Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/src/listeners/order_book/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
listeners::order_book::{L2Snapshots, TimedSnapshots, utils::compute_l2_snapshots},
order_book::{
Coin, InnerOrder, Oid,
Coin, InnerOrder, Oid, Px,
multi_book::{OrderBooks, Snapshots},
},
prelude::*,
Expand Down Expand Up @@ -100,6 +100,10 @@ impl OrderBookState {
let time = order.time.and_utc().timestamp_millis();
let mut inner_order: InnerL4Order = order.try_into()?;
inner_order.modify_sz(sz);
// Use px from book diff (more accurate than order status px)
if let Ok(diff_px) = Px::parse_from_str(diff.px()) {
inner_order.modify_px(diff_px);
}
// must replace time with time of entering book, which is the timestamp of the order status update
#[allow(clippy::unwrap_used)]
inner_order.convert_trigger(time.try_into().unwrap());
Expand Down
11 changes: 9 additions & 2 deletions server/src/listeners/order_book/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ pub(super) fn validate_snapshot_consistency<O: Clone + PartialEq + Debug>(
return Err(format!("Missing {} book", coin.value()).into());
}
}
if !snapshot_map.is_empty() {
return Err("Extra orderbooks detected".to_string().into());
// Only error if expected has non-empty books that we don't have
// Empty books are equivalent to not existing
let non_empty_expected: Vec<_> = snapshot_map
.iter()
.filter(|(_, book)| !book.as_ref()[0].is_empty() || !book.as_ref()[1].is_empty())
.map(|(c, _)| c.value())
.collect();
if !non_empty_expected.is_empty() {
return Err(format!("Extra orderbooks detected: {:?}", non_empty_expected).into());
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions server/src/order_book/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub(crate) trait InnerOrder: Clone {
fn decrement_sz(&mut self, dec: Sz);
fn fill(&mut self, maker_order: &mut Self) -> Sz;
fn modify_sz(&mut self, sz: Sz);
fn modify_px(&mut self, px: Px);
fn convert_trigger(&mut self, ts: u64);
}

Expand Down
4 changes: 4 additions & 0 deletions server/src/types/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ impl InnerOrder for InnerL4Order {
match_sz
}

fn modify_px(&mut self, px: Px) {
self.limit_px = px;
}

fn convert_trigger(&mut self, ts: u64) {
if self.is_trigger {
self.trigger_px = "0.0".to_string();
Expand Down
4 changes: 4 additions & 0 deletions server/src/types/node_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ impl NodeDataOrderDiff {
pub(crate) fn coin(&self) -> Coin {
Coin::new(&self.coin)
}

pub(crate) fn px(&self) -> &str {
&self.px
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down