pub struct OrderRegistry { /* private fields */ }Expand description
Many OrderFsms keyed by client order id.
§Examples
use std::time::{Duration, Instant};
use brokapi_core::{ClientOrderId, OrderState};
use brokapi_sansio::OrderRegistry;
let mut registry = OrderRegistry::new();
let t0 = Instant::now();
let (a, b) = (ClientOrderId::new_v4(), ClientOrderId::new_v4());
registry.register_place(a, t0);
registry.register_place(b, t0 + Duration::from_secs(20));
// 31 s after `a` was sent, with a 30 s limit: only `a` has gone silent.
let changed = registry.on_global_timeout(t0 + Duration::from_secs(31), Duration::from_secs(30));
assert_eq!(changed.len(), 1);
assert_eq!(changed[0].0, a);
assert!(matches!(changed[0].1, OrderState::Unknown { .. }));
assert_eq!(registry.in_flight_cids(), vec![b]);Implementations§
Source§impl OrderRegistry
impl OrderRegistry
Sourcepub fn register_place(&mut self, cid: ClientOrderId, now: Instant)
pub fn register_place(&mut self, cid: ClientOrderId, now: Instant)
Starts tracking cid as InFlight, sent at now. An order already tracked under this cid
is replaced.
Sourcepub fn apply(
&mut self,
cid: ClientOrderId,
signal: OrderSignal,
now: Instant,
) -> Result<Option<OrderState>, FsmError>
pub fn apply( &mut self, cid: ClientOrderId, signal: OrderSignal, now: Instant, ) -> Result<Option<OrderState>, FsmError>
Applies a signal to the order cid, see OrderFsm::apply for the result.
§Errors
FsmError::UnknownOrder when cid is not tracked, and every error of OrderFsm::apply.
Sourcepub fn get(&self, cid: ClientOrderId) -> Option<&OrderFsm>
pub fn get(&self, cid: ClientOrderId) -> Option<&OrderFsm>
The state machine of cid, if tracked.
Sourcepub fn forget_finished(&mut self, cid: ClientOrderId) -> bool
pub fn forget_finished(&mut self, cid: ClientOrderId) -> bool
Stops tracking cid, but only if its order is finished (Filled, Cancelled or Rejected).
Returns true when it was removed. A live order, or an unknown cid, is left alone.
Sourcepub fn in_flight_cids(&self) -> Vec<ClientOrderId> ⓘ
pub fn in_flight_cids(&self) -> Vec<ClientOrderId> ⓘ
The cids of all orders now in state InFlight, in no particular order.
Sourcepub fn abandon_inflight(
&mut self,
now: Instant,
) -> Vec<(ClientOrderId, OrderState)>
pub fn abandon_inflight( &mut self, now: Instant, ) -> Vec<(ClientOrderId, OrderState)>
Moves every InFlight order to Unknown now, whatever its age (shutdown).
Returns each changed cid with its new state. Nothing is sent to the broker.
Sourcepub fn on_global_timeout(
&mut self,
now: Instant,
timeout: Duration,
) -> Vec<(ClientOrderId, OrderState)>
pub fn on_global_timeout( &mut self, now: Instant, timeout: Duration, ) -> Vec<(ClientOrderId, OrderState)>
Moves every InFlight order that has waited timeout or longer (since it was registered) to
Unknown, and returns the changed ones with their new state.
Nothing is sent to the broker. Orders in other states are not touched.