Auto Cancel#

There are different levels of protection gateway implement to manage the risks associated with disconnected services.

Some exchanges allow auto-cancelation based on a heartbeat sent by the gateway. If the heartbeat is not received (with some tolerance), the exchange will then automatically delete any open orderes.

This can typically only be done at an account level.

Note

There will always be the risk that orders can be partially or fully filled in the time between disconnect happens and the exchange detects the timeout.

The gateway can also be instructed by a connected client to cancel open orders on disconnect. This request is automatically made at connection time and typically controlled by the client’s config dispatcher:

void Config::dispatch(Handler &handler) const {
  handler(client::Settings{
      .order_cancel_policy = OrderCancelPolicy::BY_ACCOUNT,
      // ...
  });
  // ...
}

Note

This example will instruct the gateway to automatically cancel all open orders for the account if the client disconnects. This includes orders placed manually or by other clients!

There are different policies

Policy

Comments

UNDEFINED

Nothing is canceled by the gateway.

MANAGED_ORDERS

Only orders known by the gateway to originate from the disconnected client. This can sometimes be a very expensive operation as a request typically will have to be sent for each open order. The risks include adverse impact on other clients, the account can potentially be rate-limited by the exchange, etc.

BY_ACCOUNT

This is the prefered option as it is typically implemented a single atomic request. The downside is that strategies sharing the same account will need to deal with cancelations caused by other clients disconnecting.