Skip to content

Commit

Permalink
Fix update order in Rust cache (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipmacek authored Jan 25, 2025
1 parent 2280d02 commit 222b092
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nautilus_core/common/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,9 @@ impl Cache {
// }
}

// update the order in the cache
self.orders.insert(client_order_id, order.clone());

Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions nautilus_core/common/src/cache/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ mod tests {
order.apply(OrderEventAny::Submitted(submitted)).unwrap();
cache.update_order(&order).unwrap();

// check the status change of the cached order
let cached_order = cache.order(&client_order_id).unwrap();
assert_eq!(cached_order.status(), OrderStatus::Submitted);

let result = cache.order(&order.client_order_id()).unwrap();

assert_eq!(order.status(), OrderStatus::Submitted);
Expand Down Expand Up @@ -183,6 +187,10 @@ mod tests {
order.apply(OrderEventAny::Rejected(rejected)).unwrap();
cache.update_order(&order).unwrap();

// check the status change of the cached order
let cached_order = cache.order(&order.client_order_id()).unwrap();
assert_eq!(cached_order.status(), OrderStatus::Rejected);

let result = cache.order(&order.client_order_id()).unwrap();

assert!(order.is_closed());
Expand Down

0 comments on commit 222b092

Please sign in to comment.