From 535e238d52bbed59fc2b02d91033e9a40d78c3b8 Mon Sep 17 00:00:00 2001 From: Philipp Hoenisch Date: Thu, 14 Oct 2021 13:20:12 +1100 Subject: [PATCH] Add hard boundaries to take order request If an order request is not in between min and max it will automatically be rejected. --- daemon/src/maker_cfd.rs | 15 +++++++++++++-- daemon/src/model.rs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 15f9860..54ef783 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -525,7 +525,18 @@ impl Actor { } }; - // 2. Insert CFD in DB + // 2. check if order has acceptable amounts + if quantity < current_order.min_quantity || quantity > current_order.max_quantity { + self.takers + .do_send_async(maker_inc_connections::TakerMessage { + taker_id, + command: TakerCommand::NotifyOrderRejected { id: order_id }, + }) + .await?; + return Ok(()); + } + + // 3. Insert CFD in DB let cfd = Cfd::new( current_order.clone(), quantity, @@ -541,7 +552,7 @@ impl Actor { self.cfd_feed_actor_inbox .send(load_all_cfds(&mut conn).await?)?; - // 3. Remove current order + // 4. Remove current order self.current_order_id = None; self.takers .do_send_async(maker_inc_connections::BroadcastOrder(None)) diff --git a/daemon/src/model.rs b/daemon/src/model.rs index 2d62e2a..24d0f4d 100644 --- a/daemon/src/model.rs +++ b/daemon/src/model.rs @@ -13,7 +13,7 @@ use uuid::Uuid; pub mod cfd; -#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, PartialOrd)] pub struct Usd(pub Decimal); impl Usd {