WebSocket Trading API

Below document describes requests and responses for trading related data using websocket API. The three major categories of data including balance, order and position data
All requests must be sent after autorization.

Balances

Subscribe Balance Request

Request to subscribe balance information
     {
        "operation":"SUBSCRIBE_BALANCES"
     }

Unsubscribe Balance Request

Request to unsubscribe balance information
     {
        "operation":"UNSUBSCRIBE_BALANCES"
     }

Balance Message

Sample message for balance information
     {
        "e":"balance",                  // Event type
        "data":[                        // balances by asset
           {
              "asset":"USDC",           // Asset name
              "total":10000,            // total balance
              "free":9244,              // free balance
              "pnl":0,                  // pnl
              "marginRequirements":756  // margin requirements
           }
        ]
     }

Orders

Subscribe Orders Request

Request to subscribe orders status and updates
     {
         "operation":"SUBSCRIBE_ORDERS"
     }

Unsubscribe Orders Request

Request to unsubscribe orders status and updates
     {
         "operation":"UNSUBSCRIBE_ORDERS"
     }

Orders Snapshot Message

Sample messages for order information
      {
        "e":"orderSnapshot",           // Event type
        "data":[
           {
              "id":3408060931,         // Id
              "clOrdId":"3353000190",  // client order id
              "origClOrdId":null,      // original client order id
              "symbol":"BTCUSD.P",     // symbol
              "side":"BUY",            // side
              "transactTime":"2019-11-07T14:44:27.088", // order creation time
              "orderQty":1,            // order quantity
              "ordType":"LIMIT",       // order type: LIMIT, MARKET
              "transactionType":"NEW", // order type: NEW, REPLACE, CANCEL
              "price":9183.46,         // order price
              "timeInForce":"GTC",     // always GTC
              "ordStatus":"ACTIVE",    // order status: ACTIVE, CANCEL, CANCELED, EXPIRED, FILLED, PARTIALLY_FILLED, REPLACED, REJECTED, UNKNOWN
              "leavesQty":1,           // leaves quantity
              "cumQty":0,              // cumulative quantity
              "avgPx":0,               // average execution price
              "text":null              // text
           },
           {
              "id":3407889588,
              "clOrdId":"3353000177",
              "origClOrdId":null,
              "symbol":"BTCUSD.P",
              "side":"BUY",
              "transactTime":"2019-11-07T14:44:03.636",
              "orderQty":1,
              "ordType":"LIMIT",
              "transactionType":"NEW",
              "price":9182.19,
              "timeInForce":"GTC",
              "ordStatus":"REPLACED",
              "leavesQty":0,
              "cumQty":0,
              "avgPx":0,
              "text":null
           },
           {
              "id":3405273093,
              "clOrdId":"3353000166",
              "origClOrdId":null,
              "symbol":"BTCUSD.P",
              "side":"BUY",
              "transactTime":"2019-11-07T14:31:02.353",
              "orderQty":7,
              "ordType":"LIMIT",
              "transactionType":"NEW",
              "price":9000,
              "timeInForce":"GTC",
              "ordStatus":"CANCELED",
              "leavesQty":0,
              "cumQty":0,
              "avgPx":0,
              "text":null
           },
           {
              "id":3408025085,
              "clOrdId":"3353000183",
              "origClOrdId":"3353000177",
              "symbol":"BTCUSD.P",
              "side":"BUY",
              "transactTime":"2019-11-07T14:44:15.504",
              "orderQty":12,
              "ordType":"LIMIT",
              "transactionType":"REPLACE",
              "price":9182.1,
              "timeInForce":"GTC",
              "ordStatus":"CANCELED",
              "leavesQty":0,
              "cumQty":0,
              "avgPx":0,
              "text":null
           },
           {
              "id":3407851966,
              "clOrdId":"3353000171",
              "origClOrdId":null,
              "symbol":"BTCUSD.P",
              "side":"BUY",
              "transactTime":"2019-11-07T14:43:51.472",
              "orderQty":1,
              "ordType":"LIMIT",
              "transactionType":"NEW",
              "price":9220,
              "timeInForce":"GTC",
              "ordStatus":"FILLED",
              "leavesQty":0,
              "cumQty":1,
              "avgPx":9214.7,
              "text":null
           }
        ]
     }

Orders Update Message

Sample messages for order updates
     {
        "e":"order",
        "id":3408209003,         // Id
        "clOrdId":"3353000194",  // client order id
        "origClOrdId":null,      // original client order id
        "symbol":"BTCUSD.P",     // symbol
        "side":"BUY",            // side
        "transactTime":"2019-11-07T14:45:14.895", // order creation time
        "orderQty":2,            // order quantity
        "ordType":"LIMIT",       // order type: LIMIT, MARKET
        "transactionType":"NEW", // order type: NEW, REPLACE, CANCEL
        "price":9182.02,         // order price
        "timeInForce":"GTC",     // always GTC
        "ordStatus":"ACTIVE",    // order status: ACTIVE, CANCEL, CANCELED, EXPIRED, FILLED, PARTIALLY_FILLED, REPLACED, REJECTED, UNKNOWN
        "leavesQty":2,           // leaves quantity
        "cumQty":0,              // cumulative quantity
        "avgPx":0,               // average execution price
        "text":null              // text
     }

Positions

Subscribe Position Request

Request to subscribe position related information
     {
        "operation":"SUBSCRIBE_POSITIONS"
     }

Unsubscribe Position Request

Request to unsubscribe position related information
     {
        "operation":"UNSUBSCRIBE_POSITIONS"
     }

Position Snapshot Message

Sample message for position information.
    {
        "e":"positionSnapshot",       // event type
        "data":[                      // list of positions
           {
              "symbol":"BTCUSD.P",    // symbol
              "quantity":4,           // quantity
              "costBasis":3676.22,    // cost basis
              "marketCost":3679.32,   // market cost
              "openPnl":3.11,         // open pnl
              "realizedPnl":0,        // realized pnl
              "dailyPnl":0,           // daily pnl
              "totalPnl":3.11,        // total pnl
              "openDateTime":"2019-11-07T14:43:51.472", // open position time
              "closeDateTime":null    // close position time
           }
        ]
     }

Position Message

Sample message for position update
    {
        "e":"position",         // Event type
        "symbol":"BTCUSD.P",    // symbol
        "quantity":4,           // quantity
        "costBasis":3676.22,    // cost basis
        "marketCost":3679.108,  // market cost
        "openPnl":2.898,        // open pnl
        "realizedPnl":0,        // realized pnl
        "dailyPnl":0,           // daily pnl
        "totalPnl":2.898,       // total pnl
        "openDateTime":"2019-11-07T14:43:51.472", // open position time
        "closeDateTime":null    // close position time
     }