Expand description
WebSocket message dispatch for the Polymarket execution client.
Routes user-channel WS messages (order updates and trades) for orders submitted through this
client into Nautilus order events (OrderAccepted / OrderFilled / OrderFillVoided /
OrderCanceled / OrderRejected / OrderExpired), building them from the context captured at
submit (OrderContextRegistry). Order-channel messages drive lifecycle events; trade-channel
messages drive fills, and acceptance is synthesized before a fill or cancel that races ahead.
Messages are emitted once the order is known (accepted, or with a submit in flight), otherwise
buffered until acceptance. Reports are reserved for the generate_* query and reconciliation
methods.
Trade evidence is admitted through the shared settlement boundary and governed by the
settlement registry: provisional and confirmed stream statuses apply legs once per
uninterrupted session, failed or conflicting stream evidence quarantines the trade for
targeted terminal REST resolution, and only a REST-established FAILED outcome voids
applied fills or tombstones absent legs.
Execution-client and dispatch replacement confirmations share one promotion under the dispatch
lock. Execution-client confirmation uses logical-order context and local event time. Dispatch
confirmation uses old-leg context and stream or REST evidence time, with local time as fallback
for invalid order-update timestamps. Promotion publishes OrderUpdated before registering and
releasing fills.
Execution-client confirmation drains the returned activity immediately; dispatch handlers retain
their own emission order. Execution-client confirmation sets drained fill ts_init at emission;
dispatch preserves buffered ts_init.