Skip to content

Commit

Permalink
Merge pull request #5 from Overmuse/SR/trading_message
Browse files Browse the repository at this point in the history
SR/trading message
  • Loading branch information
SebRollen authored Oct 27, 2021
2 parents 222b178 + 42d19c1 commit d397017
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "trading-base"
version = "0.4.0"
version = "0.5.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
rust_decimal = "1.14"
rust_decimal = "1.17"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"
uuid = { version = "0.8", features = ["v4", "serde"] }
Expand Down
20 changes: 17 additions & 3 deletions src/trade_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ impl TradeIntent {
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(tag = "action", rename_all = "snake_case")]
pub enum TradeMessage {
New { intent: TradeIntent },
Cancel { id: Uuid },
}

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -84,8 +91,15 @@ mod test {
limit_price: Decimal::new(101, 0),
})
.time_in_force(TimeInForce::ImmediateOrCancel);
let serialized = serde_json::to_string(&intent).unwrap();
let deserialized = serde_json::from_str(&serialized).unwrap();
assert_eq!(intent, deserialized);
let new_message = TradeMessage::New {
intent: intent.clone(),
};
let cancel_message = TradeMessage::Cancel { id: intent.id };
let new_serialized = serde_json::to_string(&new_message).unwrap();
let new_deserialized = serde_json::from_str(&new_serialized).unwrap();
let cancel_serialized = serde_json::to_string(&cancel_message).unwrap();
let cancel_deserialized = serde_json::from_str(&cancel_serialized).unwrap();
assert_eq!(new_message, new_deserialized);
assert_eq!(cancel_message, cancel_deserialized);
}
}

0 comments on commit d397017

Please sign in to comment.