subscribe

WebSocket API to subscribe to notifications.

action, URI Path: /api/v1/private/subscribe
Parameters:
{
    "id": 5533, // id, developer identifies the response by the sent id
    "action": "/api/v1/private/subscribe",  
    "arguments": {
        "instrument": ["BTC-19DEC14"], // instrument filter if applicable, i.e., list of instrument names,
                                       // see getinstruments REST API
	                                   // also filters ["all"], ["futures"], ["options"] are allowed
                                       // ["all"] = no filter, all uinstruments
									   // ["futures"] = notification for futures	
                                       // ["options"] = notification for options
       "event": ["order_book", "trade", "user_order"] // events to be reported, possible events:
                                                      // "order_book" -- order book change 
                                                      // "trade" — trade notification, trade notification is not filtered 
                                                      // "user_order" -- change of user orders (openning, cancelling, filling)
    },     
   "sig": "...." // required !
}
Response message is JSON object:
{
    "id": 5533,       // equal to the request id
    "success": true,  // true or false 
    "message": "subscribed", // subscribed or not
    "result": null
}
WebSocket notification message:
{
 "notifications": [ 
			// list of notifications (notification objects)
		.....
 	  ]
}
Following notification objects are possible:
trade_event
with list of the trades. JSON object:
{
     "success": true,  // false of true
      "message": "trade_event", // event type
      "result": [ // list of trades (for trade event)
            {
             "tradeId": 3,                    // trade id
             "timeStamp": 1418152290669, // Unix timestamp 
			 "instrument": "BTC-22JAN16", // name of instrument
             "quantity": 61,          // quantity, in contracts ($10 per contract for futures, ฿1 — for options)   
             "price": 415,       // float, USD for futures, BTC for options
             "state": "closed",     // order state
             "direction": "buy",   
             "orderId": 10,         // order id
             "matchingId": 6,       // id of matching order
             "makerComm": 0.0001,   
             "takerComm": 0.0005,
             "indexPrice": 420.69   // index price
           }
        ]
     }
order_book_event
It notifies about a change of order book for certain instrument. JSON object:
{
            "success": true,
            "message": "order_book_event",
            "result": {
                "instrument": "BTC-9OCT15",
                "bids": [
                    {
                        "quantity": 10, // quantity, in contracts ($10 per contract for futures, ฿1 — for options)
                        "price": 418.19, // float, USD for futures, BTC for options
                        "cm": 10  // cumulative quantity, in contracts ($10 per contract for futures, ฿1 — for options)
                    }
                    ...// next best bids
                ],
                "asks": [
                    {
                        "quantity": 10,
                        "price": 422.21,
                        "cm": 20
                    }
                    ...// next best asks  
                ],
                "last": 418.19,
                "low": 415.18,
                "high": 420.26
            }
        }
user_order_event
It notifies about a change of user’s orders. This event is triggered for all changes of the user orders, it doesn’t depend on “instrument” parameter at subscription. JSON object:
{   "success": true,
    "message": "user_orders_event",
    "result": [
                {
                    "id": 1031,                   // order identifier
                    "instrument": "BTC-22JAN16",  // instrument name
                    "direction": "sell",          // direction of the order "buy" or "sell"
                    "price": 426,                 // price
                    "quantity": 10,               // quantity, in contracts ($10 per contract for futures, ฿1 — for options)
                    "filledQuantity": 0,          // filled quantity, in contracts ($10 per contract for futures, ฿1 — for options)
                    "state": "open",              // order state "open", "cancelled", "filled"
                    "created": 1453454229858,     // creation Unix timestamp
                    "modified": 1453454229858     // Unix timestamp of the last change
                }
              ]
}
              

unsubscribe

Unsubscribe from all notifications without closing the websocket connection. Currently there is no selectors.
action, URI Path: /api/v1/private/unsubscribe
Paramerts: none
{
    "id": 1798, // id, developer identifies the response by the sent id
    "action": "/api/v1/private/unsubscribe",
    "sig": "...."  // required
}
Response message is JSON object:
{
    "id": 1798,      // equal to the request id
    "success": true,
    "message": "unsubscribed",
    "result": null
}
Websockets API
Private API