Skip to main content

WsDispatchState

Struct WsDispatchState 

Source
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

Source

pub fn new() -> Self

Creates a new empty dispatch state.

Source

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.

Source

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.

Source

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.

Source

pub fn update_identity_quantity( &self, client_order_id: &ClientOrderId, quantity: Quantity, )

Refreshes the tracked quantity for a modify ack.

Source

pub fn insert_accepted(&self, cid: ClientOrderId)

Marks an OrderAccepted event as emitted for this order.

Source

pub fn insert_filled(&self, cid: ClientOrderId)

Marks an order as having reached the filled terminal state.

Source

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.

Source

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.

Source

pub fn cached_venue_order_id( &self, client_order_id: &ClientOrderId, ) -> Option<VenueOrderId>

Returns the previously cached venue order id, if any.

Source

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.

Source

pub fn clear_pending_modify(&self, client_order_id: &ClientOrderId)

Clears the pending modify marker for a client order id.

Source

pub fn pending_modify( &self, client_order_id: &ClientOrderId, ) -> Option<VenueOrderId>

Returns the pending modify marker for a client order id, if any.

Source

pub fn record_filled_qty(&self, client_order_id: ClientOrderId, qty: Quantity)

Records cumulative filled quantity for a tracked order.

Source

pub fn previous_filled_qty( &self, client_order_id: &ClientOrderId, ) -> Option<Quantity>

Returns the previously recorded cumulative filled quantity, if any.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WsDispatchState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,