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

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 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. When the dedup set is at capacity the oldest entry is evicted to make room, preserving the DEDUP_CAPACITY most recently seen trade IDs.

Source

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

Removes all dispatch state for an order that has reached a terminal state.

Source

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.

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 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.

Source

pub fn previous_delta_snapshot( &self, client_order_id: &ClientOrderId, ) -> Option<DeltaSnapshot>

Returns the previously recorded delta snapshot, if any.

Source

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

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,