fintech-algorithms

Cancel-on-Disconnect

Install and import

bash
npm install fintech-algorithms
ts
import { 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

NameTypeNotes
disconnected_session_idstringThe session that dropped.
disconnect_typestringHow it dropped — graceful, timeout or transport failure.
trigger_disconnect_typesstring[]Which disconnect types actually trigger cancellation.
policystringCancellation scope: session, participant or firm.
ordersOrder[]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

disconnected_session_id
"S-1"
disconnect_type
"hard"
trigger_disconnect_types
["hard", "graceful", "server"]
policy
"cancel_continuous"
orders
[
  {
    "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

Cancel-on-Disconnect — system map

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.

Read the article →

References