-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Side enum we use for capturing which side an order or position is on has exactly two values with "opposing" meaning. Client code may reasonably want to negate a side and expect the result to be the other one. This change enables such use cases by implementing the Not trait for both types.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright (C) 2019-2020 Daniel Mueller <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
use std::ops::Not; | ||
|
||
use hyper::Method; | ||
|
||
use num_decimal::Num; | ||
|
@@ -24,6 +26,17 @@ pub enum Side { | |
Short, | ||
} | ||
|
||
impl Not for Side { | ||
type Output = Self; | ||
|
||
fn not(self) -> Self::Output { | ||
match self { | ||
Self::Long => Self::Short, | ||
Self::Short => Self::Long, | ||
} | ||
} | ||
} | ||
|
||
|
||
/// A single position as returned by the /v2/positions endpoint on a GET | ||
/// request. | ||
|
@@ -134,6 +147,12 @@ mod tests { | |
use crate::Client; | ||
|
||
|
||
#[test] | ||
fn negate_side() { | ||
assert_eq!(!Side::Long, Side::Short); | ||
assert_eq!(!Side::Short, Side::Long); | ||
} | ||
|
||
#[test] | ||
fn parse_reference_position() { | ||
let response = r#"{ | ||
|