Skip to main content

Streaming

note

This section is related to trading intgeration. For more information about the streaming endpoint for data integration, see Stream of prices

Streaming endpoints are an alternative to regular endpoints. Regular endpoints are usual REST API requests — the client makes a request to the server initiating an HTTP connection. The server closes the connection after providing a response.

Streaming endpoints work differently. The client initiates the connection and the server continuously sends messages without closing it. Generally, one streaming connection per endpoint is opened until the user session ends.

There are no response header requirements for the streaming endpoints.

Messages sent in the response body are in the JSON format without the newline characters. A newline character should separate different messages.

Data flow of streaming endpoint

  1. Client opens a connection
  2. Server initially responds with snapshot of data
  3. While connection is open, server continues to send update and ping messages
  4. Client or server closes a connection

Examples of the expected response for the case of /stream/orders endpoint are provided in the following sections.

Snapshot of data

The client initiates the connection. Server responds with a JSON message containing all orders for this account from the current trading session as well as open orders from the previous sessions. The formatted response is shown below:

[
{
"id": "1",
"instrument": "EURUSD",
"qty": 101,
"side": "buy",
"type": "limit",
"avgPrice": 0,
"limitPrice": 1.2093,
"duration": {
"type": "gtt",
"datetime": 1548406235
},
"status": "working"
},
{
"id": "2",
"instrument": "AAPL",
"qty": 2,
"side": "sell",
"type": "market",
"avgPrice": 170.29,
"duration": {
"type": "gtc"
},
"status": "filled"
}
]

Update and ping messages

It is only required to send an update if a new order is placed or if there is an update for a particular order. The message should contain full information for that particular order, and not only for the updated fields:

[
{
"id": "1",
"instrument": "EURUSD",
"qty": 101,
"side": "buy",
"type": "limit",
"avgPrice": 1.2087,
"limitPrice": 1.2093,
"duration": {
"type": "gtt",
"datetime": 1548406235
},
"status": "filled"
}
]

It is expected to receive a ping message that indicates an active connection in the case of no updates for five seconds:

{"s": "ok"}

Closing a connection

If the connection is closed by the server, the client will attempt to reconnect several times. If the reconnect attempt is unsuccessful, the user will be logged out from the integration.