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 terminal_cloids: Mutex<BoundedDedup<Ustr>>,
pub cached_venue_order_ids: DashMap<ClientOrderId, VenueOrderId>,
pub buffered_fills: DashMap<ClientOrderId, Vec<FillReport>>,
pub order_filled_qty: DashMap<ClientOrderId, Quantity>,
pub pending_corrective: DashMap<ClientOrderId, (u64, HyperliquidExecPlaceOrderRequest)>,
/* 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.
terminal_cloids: Mutex<BoundedDedup<Ustr>>Raw Hyperliquid CLOIDs that reached a terminal state through the post
response path before the matching orderUpdates event arrived.
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.
buffered_fills: DashMap<ClientOrderId, Vec<FillReport>>FillReports buffered only when a cancel-replace fill cannot be promoted
(the identity carries no price); drained by the cancel-replace branch of
handle_accepted. The common path promotes on the fill instead. See
GH-3972.
order_filled_qty: DashMap<ClientOrderId, Quantity>Cumulative filled quantity per tracked order. Compared against
OrderIdentity::quantity to decide when to clean up tracked state.
pending_corrective: DashMap<ClientOrderId, (u64, HyperliquidExecPlaceOrderRequest)>Corrective reduce queued by the cancel-replace promotion: client order id to (new venue order id, reduced request). Drained by the WS loop.
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 mark_submission_pending(&self, client_order_id: ClientOrderId)
pub fn mark_submission_pending(&self, client_order_id: ClientOrderId)
Marks a tracked order as awaiting its submission POST response.
Sourcepub fn submission_pending(&self, client_order_id: &ClientOrderId) -> bool
pub fn submission_pending(&self, client_order_id: &ClientOrderId) -> bool
Returns whether the order still awaits its submission POST response.
Sourcepub fn buffer_submission_rejection(
&self,
client_order_id: ClientOrderId,
report: OrderStatusReport,
)
pub fn buffer_submission_rejection( &self, client_order_id: ClientOrderId, report: OrderStatusReport, )
Holds a submission-time rejection until the POST response resolves.
Sourcepub fn resolve_submission(
&self,
client_order_id: &ClientOrderId,
) -> Option<OrderStatusReport>
pub fn resolve_submission( &self, client_order_id: &ClientOrderId, ) -> Option<OrderStatusReport>
Resolves submission tracking and returns any early rejection report.
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) -> bool
pub fn insert_filled(&self, cid: ClientOrderId) -> bool
Marks an order as having reached a terminal state.
Returns true when this call claimed the terminal state, and false
when another path had already claimed it.
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 insert_terminal_cloid(&self, cloid: Ustr)
pub fn insert_terminal_cloid(&self, cloid: Ustr)
Records a terminal raw Hyperliquid CLOID.
Used when the post response rejects an order before the WebSocket
orderUpdates message. The normal CLOID mapping can be removed while a
late unresolved order update still gets suppressed instead of forwarded
as an external report.
Sourcepub fn terminal_cloid_seen(&self, cloid: &Ustr) -> bool
pub fn terminal_cloid_seen(&self, cloid: &Ustr) -> bool
Returns whether a raw Hyperliquid CLOID reached a terminal state through the post response path.
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,
target_qty: Quantity,
) -> u64
pub fn mark_pending_modify( &self, client_order_id: ClientOrderId, old_venue_order_id: VenueOrderId, target_qty: Quantity, ) -> u64
Queues an in-flight modify intent for cancel-before-accept suppression and records the target absolute total qty for the cancel-replace promotion. Returns the intent’s generation.
The generation lets the submission path clear only this modify on
failure via Self::clear_modify_generation, leaving newer queued
modifies intact. Chained modifies append rather than overwrite, so a
later modify cannot drop an earlier pending old-leg marker.
Sourcepub fn clear_pending_modify(&self, client_order_id: &ClientOrderId)
pub fn clear_pending_modify(&self, client_order_id: &ClientOrderId)
Clears the entire pending modify chain for a client order id.
Sourcepub fn clear_modify_generation(
&self,
client_order_id: &ClientOrderId,
generation: u64,
)
pub fn clear_modify_generation( &self, client_order_id: &ClientOrderId, generation: u64, )
Removes a single modify intent by generation, leaving newer queued modifies intact. Drops the chain entry when it empties.
When the removed intent is the front, the next queued modify inherits its old leg: a rejected modify does not cancel-replace, so the resting leg it targeted is still live and the next modify cancel-replaces the same one. A non-front removal needs no reparenting; the front’s promotion (or its own removal) advances the chain.
Sourcepub fn stash_modify_request(
&self,
client_order_id: ClientOrderId,
request: HyperliquidExecPlaceOrderRequest,
)
pub fn stash_modify_request( &self, client_order_id: ClientOrderId, request: HyperliquidExecPlaceOrderRequest, )
Stashes the exact venue request sent onto the most recently queued modify intent for the order.
Sourcepub fn modify_request(
&self,
client_order_id: &ClientOrderId,
) -> Option<HyperliquidExecPlaceOrderRequest>
pub fn modify_request( &self, client_order_id: &ClientOrderId, ) -> Option<HyperliquidExecPlaceOrderRequest>
Returns a clone of the front intent’s stashed modify request, if any.
Sourcepub fn claim_front_modify(
&self,
client_order_id: &ClientOrderId,
new_venue_order_id: VenueOrderId,
) -> Option<ModifyIntent>
pub fn claim_front_modify( &self, client_order_id: &ClientOrderId, new_venue_order_id: VenueOrderId, ) -> Option<ModifyIntent>
Claims the front (oldest) modify intent for promotion.
Advances the next queued intent’s old leg to new_venue_order_id: its
cancel-replace targets the replacement just promoted, not the leg it was
queued against. Returns the claimed intent, or None when no intent is
queued (an external modify with no local marker). Drops the chain entry
when it empties.
Sourcepub fn queue_corrective(
&self,
client_order_id: ClientOrderId,
oid: u64,
request: HyperliquidExecPlaceOrderRequest,
)
pub fn queue_corrective( &self, client_order_id: ClientOrderId, oid: u64, request: HyperliquidExecPlaceOrderRequest, )
Queues a corrective reduce for the WebSocket consumer loop to post.
Sourcepub fn take_corrective(
&self,
client_order_id: &ClientOrderId,
) -> Option<(u64, HyperliquidExecPlaceOrderRequest)>
pub fn take_corrective( &self, client_order_id: &ClientOrderId, ) -> Option<(u64, HyperliquidExecPlaceOrderRequest)>
Removes and returns a queued corrective reduce, if any.
Sourcepub fn has_pending_modify(&self, client_order_id: &ClientOrderId) -> bool
pub fn has_pending_modify(&self, client_order_id: &ClientOrderId) -> bool
Returns whether any modify intent is queued for the 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 front intent’s old venue order id, if any.
Sourcepub fn pending_modify_contains_old(
&self,
client_order_id: &ClientOrderId,
venue_order_id: VenueOrderId,
) -> bool
pub fn pending_modify_contains_old( &self, client_order_id: &ClientOrderId, venue_order_id: VenueOrderId, ) -> bool
Returns whether any queued intent cancel-replaces venue_order_id.
Used to suppress the CANCELED(old_voi) leg of any in-flight modify in
the chain, not only the oldest.
Sourcepub fn pending_modify_target_qty(
&self,
client_order_id: &ClientOrderId,
) -> Option<Quantity>
pub fn pending_modify_target_qty( &self, client_order_id: &ClientOrderId, ) -> Option<Quantity>
Returns the front intent’s recorded target absolute total qty, if any.
Sourcepub fn buffer_fill(&self, client_order_id: ClientOrderId, fill: FillReport)
pub fn buffer_fill(&self, client_order_id: ClientOrderId, fill: FillReport)
Buffers a FillReport arrived during an in-flight cancel-replace.
Sourcepub fn drain_buffered_fills(
&self,
client_order_id: &ClientOrderId,
) -> Vec<FillReport>
pub fn drain_buffered_fills( &self, client_order_id: &ClientOrderId, ) -> Vec<FillReport>
Removes and returns buffered fills for the cid, in arrival order.
Sourcepub fn buffered_fill_count(&self, client_order_id: &ClientOrderId) -> usize
pub fn buffered_fill_count(&self, client_order_id: &ClientOrderId) -> usize
Number of buffered fills for the cid.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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