View Live Order and Market Data Updates

Overview

You can use the Trade WebSocket API to get real-time status updates for market data and trigger messages for:

  • Order books - Subscribe to a live feed of all outstanding buy and sell orders on the market for specific coins and tokens. Send messages when specific market conditions occur.
  • Trade orders - Subscribe to live status updates for your trade orders, including individual fills for an order. Send messages when statuses update.

Prerequisites

Steps

1. Subscribe to Order Books

Endpoint: Get WebSocket Connection

GET /api/prime/trading/v1/ws

{
  "type": "subscribe",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
  "channel": "level2",
  "productId": "TBTC-TUSD*"
}

Step Result

{
  "channel": "level2",
  "type": "snapshot",
  "product": "TBTC-TUSD*",
  "time": "2020-01-01T09:35:26.465Z",
  "bids": [["7001.10", "1.5084"]],
  "asks": [["7002.55", "2.7524"]],
}

2. Subscribe to Trade Orders

Endpoint: Get WebSocket Connection

GET /api/prime/trading/v1/ws

{
  "type": "subscribe",
  "channel": "orders",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
}

Step Result

{
  "channel": "order",
  "time": "2019-04-25T01:02:03.045678Z",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
  "orderId": "14db12f5-4d3d-4fd8-8ced-062aa81bb4bc",
  "clientOrderId": "my-order-1",
  "product": "TBTC-TUSD*",
  "status": "opened",
  "type": "market",
  "side": "buy",
  "quantity": "1.01",
}
{
  "channel": "order",
  "time": "2019-04-25T01:02:04.045678Z",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
  "orderId": "14db12f5-4d3d-4fd8-8ced-062aa81bb4bc",
  "clientOrderId": "my-order-1",
  "product": "TBTC-TUSD*",
  "status": "opened",
  "type": "market",
  "side": "buy",
  "quantity": "1.01",
  "cumulativeQuantity": "0.50",
  "averagePrice": "7090.1",
  "tradeId": "a6a9ab1b-2947-41b7-b44d-4ce61fca8b92",
  "fillQuantity": "0.50",
  "fillPrice": "7090.1",
}
{
  "channel": "order",
  "time": "2019-04-25T01:02:03.045678Z",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
  "orderId": "14db12f5-4d3d-4fd8-8ced-062aa81bb4bc",
  "clientOrderId": "my-order-1",
  "product": "TBTC-TUSD*",
  "status": "completed",
  "type": "market",
  "side": "buy",
  "quantity": "1.01",
  "cumulativeQuantity": "1.01",
  "averagePrice": "7090.1",
}
{
  "channel": "order",
  "time": "2019-04-25T01:02:03.045678Z",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
  "orderId": "14db12f5-4d3d-4fd8-8ced-062aa81bb4bc",
  "clientOrderId": "my-order-1",
  "product": "TBTC-TUSD*",
  "status": "canceled",
  "type": "market",
  "side": "buy",
  "quantity": "1.01",
  "cumulativeQuantity": "0.50",
  "averagePrice": "7090.1",
}
{
  "channel": "order",
  "time": "2019-04-25T01:02:03.045678Z",
  "accountId": "f230fdebfa084ffebc7e00515f54603f",
  "orderId": "14db12f5-4d3d-4fd8-8ced-062aa81bb4bc",
  "clientOrderId": "my-order-1",
  "product": "TBTC-TUSD*",
  "status": "error",
  "message": "insufficient fund",
  "type": "market",
  "side": "buy",
  "quantity": "1.01",
  "cumulativeQuantity": "0.50",
  "averagePrice": "7090.1",
}

See Also

API Reference: Get WebSocket Connection