Cancel-on-Disconnect
Install and import
npm install fintech-algorithmsimport { cancelOnDisconnect } from "fintech-algorithms/matching-engines-and-venue-logic/order-controls/cancel-on-disconnect";Signature
cancelOnDisconnect(disconnected_session_id, disconnect_type, trigger_disconnect_types, policy, orders)Decides which orders to pull when a session drops. Not every disconnect should cancel — a deliberate logout and a network failure are different events, and cancelling a hedge because of a brief blip is its own risk.
Parameters
| Name | Type | Notes |
|---|---|---|
disconnected_session_id | string | The session that dropped. |
disconnect_type | string | How it dropped — graceful, timeout or transport failure. |
trigger_disconnect_types | string[] | Which disconnect types actually trigger cancellation. |
policy | string | Cancellation scope: session, participant or firm. |
orders | Order[] | Live orders to evaluate. |
Returns
{ cancelled, retained, triggered, policy, … }
Orders cancelled and retained, with whether the disconnect type triggered at all.
Errors
- When the policy is unrecognised — throws
Complexity: time O(orders),
space O(cancelled).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
"S-1""hard"["hard", "graceful", "server"]"cancel_continuous"[
{
"order_id": "O-1",
"session_id": "S-1",
"book": "continuous",
"time_in_force": "DAY",
"quantity": 100
},
{
"order_id": "O-2",
"session_id": "S-1",
"book": "continuous",
"time_in_force": "GTC",
"quantity": 200
},
{
"order_id": "O-3",
"session_id": "S-1",
"book": "auction",
"time_in_force": "DAY",
"quantity": 300
}
]Showing 3 of 4 elements.
Call
cancelOnDisconnect(disconnected_session_id, disconnect_type, trigger_disconnect_types, policy, orders)Returns
object with 9 fields: disconnected_session_id, disconnect_type, triggered, policy, canceled_order_ids, retained_orders, canceled_count, retained_count, …
{
"disconnected_session_id": "S-1",
"disconnect_type": "hard",
"triggered": true,
"policy": "cancel_continuous",
"canceled_order_ids": ["O-1", "O-2"],
"retained_orders": [
{
"order_id": "O-3",
"reason": "auction-order-retained"
},
{
"order_id": "O-4",
"reason": "different-session"
}
],
"canceled_count": 2,
"retained_count": 2,
"state": "purge-applied"
}Other exports
This module also exports
tickSizeValidation, priceBandValidation, selfTradePrevention, fatFingerLimit, circuitBreakerTrigger, calculate. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Nasdaq Introduces Changes to Cancel on Disconnect Functionality — Nasdaq
- Cboe Titanium U.S. Equities FIX Specification — Cboe Global Markets
- Evidence boundary