Live trading fails at the edges — retries, missed cancels, duplicate acks. The OMS keeps local state aligned with the exchange.
Challenge we are solving
Networks lose packets. Heartbeats expire. Orders get partially filled while a cancel is in flight. If internal state and exchange state diverge, you place a duplicate or leak an orphan order.
What this stage does
Signs the order (EIP-712 v2), submits it via the CLOB V2 client, listens for accept/partial/fill/cancel/reject events, renews heartbeats, reconciles when internal ≠ exchange, and exposes the full lifecycle for audit.
Why this stage exists
This is where operational discipline matters most. Bugs here cost real capital silently.
Every formula below is implemented in packages/polytraders-bots/ or packages/polytraders-runner/. Treat the worked example as the unit-test sanity check you should be able to reproduce locally.
Order struct (taker, maker, side, price, size, nonce, builder)
typed
worked example\[\text{wrong domain} \Rightarrow \text{venue returns SEC\_DOMAIN\_MISMATCH;\; no funds at risk because the venue refuses to sign}\]
We use the V2 domain only. Mixing V1 and V2 domains is the single most expensive class of bug at this layer.
4
Reconciliation invariant
\[internal\_state \equiv exchange\_state \;\;\text{at every confirmed tick}\]
Symbol
Meaning
Units / range
\(internal_state\)
Local view of (open orders, fills, cancels) per market
struct
\(exchange_state\)
Server view fetched via REST snapshot
struct
worked example\[diff(\{open: 800\},\{open: 0\}) \neq \emptyset \;\Rightarrow\; \text{flag DIVERGED}\;\Rightarrow\; reconcile()\]
Stage 11 pauses the affected scope automatically if reconciliation cannot close the gap within the SLO.
How a developer codes this stage
Reference TypeScript implementation lives in packages/polytraders-* at the repository root. Stage owners maintain these files — read them before writing new code.