Blog
Order stateNode.js

Handling Order Acknowledgements, Fills, and Timeouts

Track acknowledgements, partial fills, cancellation races, and unknown submissions without resetting newer order facts or automatically resending commands.

Siebly.io3 min readMarkdown

Save Identity Before Dispatch

A private event reports an order as filled while its REST placement call is still waiting. When the REST response finally arrives, code that sets the order to open on every successful response can move a completed order backwards.

Order state should retain the facts each message establishes. An acknowledgement establishes request acceptance. A cumulative quantity describes execution progress. A cancellation request describes an attempt to stop the remaining quantity. Those facts can arrive in a different order from the operations that produced them.

Save the Order Intent, the supported client order ID, product, account, and request parameters before submission. Attach the native exchange order ID when either the reply or a private event supplies it.

A client order ID is a correlation tool whose uniqueness and reuse rules come from the exchange. It is not a universal guarantee that repeating a request is harmless.

Apply Facts Without Double Counting

Incoming factRetained result
Acceptance after a filled eventAttach acceptance metadata; keep the known fill.
Repeated cumulative filled quantityPreserve the quantity rather than adding it again.
New execution recordStore it once using its execution ID and scope.
Cancellation acknowledgementContinue tracking the final order status and any fills racing cancellation.
Old snapshot after a newer eventApply the endpoint's version rules; do not overwrite solely because the snapshot arrived later.

For example, an order for two units can fill one unit and cancel its remainder. It has both an executed quantity of one and a cancelled remainder. Treating cancellation as zero execution would lose the position change.

An Account State consumer may also receive position and balance events separately. A terminal order event does not require every unrelated account field to have changed in the same message.

Retain Unknown Submissions

A connection loss after dispatch can leave the outcome unknown. Query current and historical order state using the recorded identifiers. Open orders alone are insufficient because a quickly filled order may already be absent.

An inconclusive lookup keeps the submission unresolved. It does not authorize another placement. Persist that condition across a process restart so a new worker cannot replay the command as fresh work.

Recheck Delayed Work

A known rate-limit rejection may allow a later attempt, but a queued intent can expire while waiting. Its price assumptions, available capacity, and operator permission may also change. Recheck those conditions at dispatch, after the request budget permits a call.

The pre-trade and kill-switch article explains how queued commands interact with a halt. Recovery repairs the order facts first; the application then decides whether any remaining action is still required.

Related articles

Continue from here

Related Siebly resources

All articles

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.