Skip to content

cancel_on_disconnect

If your bot dies, your laptop sleeps, or the network drops, orders you left on the book keep trading without you. cancel_on_disconnect makes the exchange pull them for you when it stops hearing from your client.

Drop the connection below and watch it happen. Reconnect before the grace period ends and nothing is lost.

cancel_on_disconnect

Two resting orders. Kill the socket and watch which one leaves the book.

heartbeat

Order book · NYY vs BOS · Yankees win
PriceSizeDepth
spread
your resting orders
Channel frames [join_ref, ref, topic, event, payload]

The feature is enabled when you join the channel, not per request:

["1", "1", "active_orders:{user_id}", "phx_join",
{ "cancel_on_disconnect": true, "ping_timeout": 5000 }]
Parameter Notes
cancel_on_disconnect Boolean. Defaults to false.
ping_timeout Milliseconds. Must be an integer — a non-integer fails the join with {"ping_timeout": "Must be an integer"}. Clamped to 5000–20000; values outside the range are silently pulled to the nearest bound.

Once joined, send a ping on the channel before each ping_timeout elapses. The server replies {"ping": "pong", "ttl": <ping_timeout>} and resets the clock. Ping at roughly 60% of the window so a single slow round trip doesn’t cost you the connection.

  1. The deadline passes and the server stops the channel with {:error, :ping_timeout}.
  2. A 20-second grace period starts (delay_to_start_canceling). Reconnect inside it and your orders are untouched — this is what makes a brief network blip safe.
  3. If the grace expires, every order whose own cancel_on_disconnect field is true is cancelled. Orders without the flag stay on the book.
POST /api/v1/orders
{
"user_order": {
"market_id": "855faa81-7115-4f4f-b492-389fbd8c1ed8",
"order_type": "limit",
"action": "buy",
"price": 46,
"quantity": 25,
"cancel_on_disconnect": true
}
}