Rules
- Persist every
clientOrderIdbefore you send it. Store the ID with the order terms first. A placement you cannot match back to its ID after a crash is a placement you cannot recover. - Retry placements with the same
clientOrderIdand the same terms. It is always safe. D1 creates at most one order per ID and returns the existing order on a retry. See clientOrderId and idempotency. - Never create a second intent while the first is unknown. After a timeout or
5xx, do not re-send the same order under a new ID. Mark the old ID as “possibly live” until you have seen its result. - A timeout is not a failure. The order may already exist, or may still be created after you stopped waiting. Not finding it straight away does not prove it will never exist.
- Persist your execution checkpoint. Store
nextAfteronly after you have applied the whole page, ideally in the same transaction as the fills. Make fill handling idempotent onfillId. See Checkpointing. - Reconcile after every reconnect. Catch up on
/executionsuntilhasMoreisfalse, then compareGET /mm/v1/orders?state=restingwith what you think is resting. - Respect
429andRetry-After. Wait at leastRetry-Afterseconds, add jitter, and retry the same request. See Rate Limits. - Back off with jitter on errors. On
5xxand network errors, use bounded exponential backoff with random jitter, so that many workers do not retry in lockstep. - Cancel risk when placement becomes unavailable. On
TRADING_DISABLED,DEALER_SUSPENDED, a stale price feed or an unexpected state, stop placing and callPOST /mm/v1/orders/cancel-all. Cancellation keeps working when placement does not. - Handle partial fills. An order can fill in several pieces, both when placed and later while resting. Book each execution as it arrives; do not wait for
FILLED. - Reconcile on a schedule. Every few minutes, check open orders, positions and balances against your own state. If they disagree, trust D1, find the missing executions, and alert.
- Stop on credential errors.
401and403(other thanTRADING_DISABLED) will not fix themselves. Stop, alert a person, and do not retry in a loop.
Startup and reconnect
POST /mm/v1/orders/cancel-all after catching up on executions and before you start quoting.