Skip to content

Active orders

The Active Orders Channel delivers information to the subscriber on order that are filled against an active market in the system.

The ActiveOrder object describes an order placed by a user in a market. Specifically an “active” order is an order on an active market (a market not scheduled, pre_open or closed.)

The following properties are set when the market is created and never change:

  • id : The unique id of the order.
  • market_id : The id of the market.
  • action : The Action of the order which will be either buy or sell.
  • type : The type of the order which will either be limit or market. Limit orders set a ceiling for the buy price or a floor for the sell price. If the order is not filled completely it will remain in the order book. Market orders have no floor or ceiling on price and will either completely execute or the remainder of the order will be cancelled after the system attempts to fill the order.
  • price : The price of the order, which will be null if the order_type == "market".
  • quantity : The amount of the order to buy or sell.
  • time : The timestamp when the order was created in ISO 8601 Format.
  • inserted_at : The timestamp when the order was created as an integer in microseconds.
  • filled : How much of the original order amount was filled.
  • filled_percentage : What percentage of the original order amount was filled.
  • avg_price : The average price that was used to fill the order.
  • status : The status of the order which will either be open, cancelled or filled.

Orders cancellation on channel disconnection

Section titled “Orders cancellation on channel disconnection”

This is an optional feature enabled when joining the channel by sending a payload with keys:

  • cancel_on_disconnect set to true
  • ping_timeout set to milliseconds telling the server when to consider the channel dead

Enabling this feature has to go hand in hand with the cancelOnDisconnect flag when placing orders via GraphQL confirmOrder mutation.

When the feature is enabled, the server will expect the client to send ping messages to the active_orders channel. If ping is not received within the set timeout, the server will consider the channel dead and will start cancelling orders flagged for cancellations that are older than the set ping_timeout.

Every ping message sent to the channel prolongs the decision.

It may happen that an order with the flag cancelOnDisconnect is created after the last ping message was sent. In this case, the order will be cancelled when the last set ping_timeout expires.

This also means that if flagged orders are placed after the channel is considered dead, such orders will be cancelled after the last ping_timeout set.

In this case, the server will assume that the timeout is at the top of the allowed range (20s, depending on the server’s configuration).

A user can join the channel from multiple sockets and enable the feature on more than one channel. In this case, the order cancellation kicks in only after all the channels are considered dead.

What if I closed the socket or left channel intentionally?

Section titled “What if I closed the socket or left channel intentionally?”

Then, the flagged orders will be cancelled after the server detects the last ping expired. This gives you some time to reconnect if you don’t want to automatically cancel the flagged orders.

["3","3","active_orders:{{UID}}","phx_join", ""]

Join and enable order cancellation on disconnection

Section titled “Join and enable order cancellation on disconnection”
["3","3","active_orders:{{UUID}}","phx_join", {"cancel_on_disconnect": true, "ping_timeout": 10000}]

If the feature is enabled the server will return payload like the following:

{"cancel_on_disconnect": true, "ping_timeout": 15000}

NOTE: ping_timeout unit is milliseconds

NOTE: The server may set different ping_timeout when requested when enabling the feature. This happens when provided value is out of allowed range.

["1", "1", "active_orders:{{UUID}}", "ping", ""]
[null, null, "active_orders:fbNZHhLfj8Ts2jxDczSQrOEBSdg1", "all_orders", { "orders": [ActiveOrder]}]

The orders list could be empty but if not, it will be a list of ActiveOrder objects described below.

Example 1:

[
null,
null,
"active_orders:fbNZHhLfj8Ts2jxDczSQrOEBSdg1",
"all_orders",
{
"orders": []
}
]

Example 2:

[
null,
null,
"active_orders:fbNZHhLfj8Ts2jxDczSQrOEBSdg1",
"all_orders",
{
"orders": [
{
"action": "sell",
"avg_price": null,
"filled": 0,
"filled_percentage": 0,
"id": "7dc6671e-2852-44f4-803d-4405d8a85407",
"market_id": "002b030c-5ac2-41f4-92de-175e666b0a70",
"order_type": "limit",
"price": 10,
"quantity": 20,
"status": "open",
"time": "2020-11-06T21:34:30.376858Z"
}
]
}
]
[null, null, "active_orders:fbNZHhLfj8Ts2jxDczSQrOEBSdg1", "new_open_order", ActiveOrder]

Example:

[
null,
null,
"active_orders:fbNZHhLfj8Ts2jxDczSQrOEBSdg1",
"new_open_order",
{
"action": "sell",
"avg_price": null,
"filled": 0,
"filled_percentage": 0,
"id": "7dc6671e-2852-44f4-803d-4405d8a85407",
"market_id": "002b030c-5ac2-41f4-92de-175e666b0a70",
"order_type": "limit",
"price": 10,
"quantity": 20,
"status": "open",
"time": "2020-11-06T21:34:30.376858Z"
}
]
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://bet_stack.com/active_order_schema",
"title": "ActiveOrder",
"type": "object",
"description": "Information on an order in the active orders channel",
"properties": {
"id": {
"description": "The unique ID of the order.",
"type": "string",
"format": "uuid"
},
"market_id": {
"description": "The unique id of the market the order was placed on.",
"type": "string",
"format": "uuid"
},
"action": {
"description": "Whether to buy contracts or sell them.",
"type": "string",
"enum": [
"buy",
"sell"
]
},
"price": {
"description": "The base price for the contracts if the order has type=limit.",
"type": [
"number",
"null"
],
"format": "integer",
"minimum": 1,
"maximum": 99
},
"quantity": {
"description": "The amount of contracts to buy or sell.",
"type": "number",
"format": "integer",
"exclusiveMinimum": 0
},
"order_type": {
"description": "The type of order placed against the market.",
"type": "string",
"enum": [
"limit",
"market"
]
},
"status": {
"description": "The current status of the order.",
"type": "string",
"enum": [
"open",
"filled",
"cancelled"
]
},
"avg_price": {
"description": "The average price in cents that the order was traded on.",
"type": [
"number",
"null"
],
"format": "integer",
"minimum": 0
},
"filled_percentage": {
"description": "The integer percentage of the order that has been filled.",
"type": "number",
"format": "integer",
"minimum": 0,
"maximum": 100
},
"time": {
"description": "Time when the order was placed.",
"type": "string",
"format": "datetime"
}
}
}