pub struct WsDispatchState {
pub order_identities: DashMap<ClientOrderId, OrderIdentity>,
pub emitted_accepted: DashSet<ClientOrderId>,
pub filled_orders: DashSet<ClientOrderId>,
pub emitted_trades: Mutex<BoundedDedup<TradeId>>,
pub cached_venue_order_ids: DashMap<ClientOrderId, VenueOrderId>,
pub pending_modify_keys: DashMap<ClientOrderId, VenueOrderId>,
pub order_filled_qty: DashMap<ClientOrderId, Quantity>,
/* 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), provides cross-stream dedup
for OrderAccepted and OrderFilled emissions, and carries the
GH-3827 cancel-replace state (cached_venue_order_ids and
pending_modify_keys).
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.
Retained past cleanup_terminal so that late replay of the same
status or fill does not re-emit events.
emitted_trades: Mutex<BoundedDedup<TradeId>>Trade IDs for which an OrderFilled event has been emitted.
Bounded FIFO dedup to bound memory while keeping recent trade ids deduped across reconnects.
cached_venue_order_ids: DashMap<ClientOrderId, VenueOrderId>Last venue order id observed for a tracked client order id.
Populated on the first OrderAccepted and refreshed on every
cancel-replace promotion. A later ACCEPTED with a different venue
order id under the same client order id is treated as the
replacement leg of a Hyperliquid modify and emitted as OrderUpdated.
pending_modify_keys: DashMap<ClientOrderId, VenueOrderId>Maps client_order_id to the old venue order id of an in-flight
modify. Populated by modify_order only after a successful HTTP
round-trip and cleared on the matching ACCEPTED(new_voi). A
CANCELED(old_voi) arriving while the marker is set is treated as
the cancel leg of a cancel-before-accept race and suppressed so the
later ACCEPTED(new_voi) can flow through the OrderUpdated path.
order_filled_qty: DashMap<ClientOrderId, Quantity>Cumulative filled quantity per tracked order. Compared against
OrderIdentity::quantity to decide when to clean up tracked state.
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 update_identity_price(
&self,
client_order_id: &ClientOrderId,
price: Option<Price>,
)
pub fn update_identity_price( &self, client_order_id: &ClientOrderId, price: Option<Price>, )
Refreshes the tracked price for a modify ack when the new report carries an updated price.
Sourcepub fn update_identity_quantity(
&self,
client_order_id: &ClientOrderId,
quantity: Quantity,
)
pub fn update_identity_quantity( &self, client_order_id: &ClientOrderId, quantity: Quantity, )
Refreshes the tracked quantity for a modify ack.
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.
Sourcepub fn record_venue_order_id(
&self,
client_order_id: ClientOrderId,
venue_order_id: VenueOrderId,
)
pub fn record_venue_order_id( &self, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, )
Caches the venue order id observed for a tracked client order id.
Sourcepub fn cached_venue_order_id(
&self,
client_order_id: &ClientOrderId,
) -> Option<VenueOrderId>
pub fn cached_venue_order_id( &self, client_order_id: &ClientOrderId, ) -> Option<VenueOrderId>
Returns the previously cached venue order id, if any.
Sourcepub fn mark_pending_modify(
&self,
client_order_id: ClientOrderId,
old_venue_order_id: VenueOrderId,
)
pub fn mark_pending_modify( &self, client_order_id: ClientOrderId, old_venue_order_id: VenueOrderId, )
Marks an in-flight modify for cancel-before-accept suppression.
Sourcepub fn clear_pending_modify(&self, client_order_id: &ClientOrderId)
pub fn clear_pending_modify(&self, client_order_id: &ClientOrderId)
Clears the pending modify marker for a client order id.
Sourcepub fn pending_modify(
&self,
client_order_id: &ClientOrderId,
) -> Option<VenueOrderId>
pub fn pending_modify( &self, client_order_id: &ClientOrderId, ) -> Option<VenueOrderId>
Returns the pending modify marker for a client order id, if any.
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.
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 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.
filled_orders is intentionally not cleared here: the marker is
used to suppress stale replays and must outlive the identity cleanup.
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