pub struct WsDispatchState {
pub order_identities: DashMap<ClientOrderId, OrderIdentity>,
pub emitted_accepted: DashSet<ClientOrderId>,
pub filled_orders: DashSet<ClientOrderId>,
pub delta_snapshots: DashMap<ClientOrderId, DeltaSnapshot>,
pub order_filled_qty: DashMap<ClientOrderId, Quantity>,
pub emitted_trades: Mutex<IndexSet<TradeId>>,
/* private fields */
}Expand description
Per-client dispatch state shared between order submission and the WebSocket consumer task.
Tracks which orders were submitted through this client (so we can route
venue events to typed [OrderEventAny] emissions for tracked orders, and
fall back to reports for external orders), and provides cross-stream
dedup for OrderAccepted and OrderFilled emissions.
Fields§
§order_identities: DashMap<ClientOrderId, OrderIdentity>Tracked orders keyed by full Nautilus [ClientOrderId].
emitted_accepted: DashSet<ClientOrderId>Client order IDs for which an OrderAccepted event has been emitted.
filled_orders: DashSet<ClientOrderId>Client order IDs that have reached the filled terminal state.
delta_snapshots: DashMap<ClientOrderId, DeltaSnapshot>Last snapshot of qty / filled / price / trigger_price seen on a
tracked OpenOrdersDelta.
The futures delta path uses this map to discriminate partial-fill
notifications (the new delta carries filled greater than the
previously seen value), modify acknowledgements (a non-fill field
changed), and pure no-op deltas (nothing changed). It is updated only
by the delta path so that the fill path’s own cumulative is not
double-counted.
order_filled_qty: DashMap<ClientOrderId, Quantity>Cumulative filled quantity per tracked client order id, populated by the fill side of dispatch.
Compared against OrderIdentity::quantity to decide when to clean up
tracked state on a terminal fill.
emitted_trades: Mutex<IndexSet<TradeId>>Trade IDs for which an OrderFilled event has been emitted.
Bounded FIFO dedup: when capacity is reached, the oldest entry is
evicted on the next insert. A simple clear() at the threshold would
drop all recent trade IDs at once, opening a window where a reconnect
or replay immediately after the rollover could re-emit duplicate
OrderFilled events.
Implementations§
Source§impl WsDispatchState
impl WsDispatchState
Sourcepub fn register_identity(
&self,
client_order_id: ClientOrderId,
identity: OrderIdentity,
)
pub fn register_identity( &self, client_order_id: ClientOrderId, identity: OrderIdentity, )
Registers an order identity. Called by the execution client at order submission time, before any WebSocket events for the order can arrive.
Sourcepub fn lookup_identity(
&self,
client_order_id: &ClientOrderId,
) -> Option<OrderIdentity>
pub fn lookup_identity( &self, client_order_id: &ClientOrderId, ) -> Option<OrderIdentity>
Returns a clone of the identity for the given client order id, if any.
Sourcepub fn insert_accepted(&self, cid: ClientOrderId)
pub fn insert_accepted(&self, cid: ClientOrderId)
Marks an OrderAccepted event as emitted for this order.
Sourcepub fn insert_filled(&self, cid: ClientOrderId)
pub fn insert_filled(&self, cid: ClientOrderId)
Marks an order as having reached the filled terminal state.
Sourcepub fn check_and_insert_trade(&self, trade_id: TradeId) -> bool
pub fn check_and_insert_trade(&self, trade_id: TradeId) -> bool
Atomically inserts a trade id into the dedup set.
Returns true when the trade was already present (i.e. it is a
duplicate), false otherwise. When the dedup set is at capacity the
oldest entry is evicted to make room, preserving the DEDUP_CAPACITY
most recently seen trade IDs.
Sourcepub fn cleanup_terminal(&self, client_order_id: &ClientOrderId)
pub fn cleanup_terminal(&self, client_order_id: &ClientOrderId)
Removes all dispatch state for an order that has reached a terminal state.
Sourcepub fn record_filled_qty(&self, client_order_id: ClientOrderId, qty: Quantity)
pub fn record_filled_qty(&self, client_order_id: ClientOrderId, qty: Quantity)
Records cumulative filled quantity for a tracked order. Used by the fill side of dispatch only.
Sourcepub fn previous_filled_qty(
&self,
client_order_id: &ClientOrderId,
) -> Option<Quantity>
pub fn previous_filled_qty( &self, client_order_id: &ClientOrderId, ) -> Option<Quantity>
Returns the previously recorded cumulative filled quantity, if any.
Sourcepub fn record_delta_snapshot(
&self,
client_order_id: ClientOrderId,
snapshot: DeltaSnapshot,
)
pub fn record_delta_snapshot( &self, client_order_id: ClientOrderId, snapshot: DeltaSnapshot, )
Records the latest delta snapshot for a tracked order. Used by the delta side of dispatch only.
Sourcepub fn previous_delta_snapshot(
&self,
client_order_id: &ClientOrderId,
) -> Option<DeltaSnapshot>
pub fn previous_delta_snapshot( &self, client_order_id: &ClientOrderId, ) -> Option<DeltaSnapshot>
Returns the previously recorded delta snapshot, if any.
Sourcepub fn update_identity_quantity(
&self,
client_order_id: &ClientOrderId,
quantity: Quantity,
)
pub fn update_identity_quantity( &self, client_order_id: &ClientOrderId, quantity: Quantity, )
Updates the tracked quantity for an order following a successful
modify acknowledgement, leaving all other identity fields untouched.
Trait Implementations§
Source§impl Debug for WsDispatchState
impl Debug for WsDispatchState
Auto Trait Implementations§
impl !Freeze for WsDispatchState
impl !RefUnwindSafe for WsDispatchState
impl Send for WsDispatchState
impl Sync for WsDispatchState
impl Unpin for WsDispatchState
impl UnsafeUnpin for WsDispatchState
impl UnwindSafe for WsDispatchState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more