Websockets API

WebSocket API include all REST API and in addition subscriptions for notifications.
WebSocket address is wss://www.deribit.com/ws/api/v1/
and test WebSocket server address is wss://test.deribit.com/ws/api/v1/
The same as the REST API, the Websocket API is available for testing via Deribit API Console (go to Account -> API tab -> API Console tab).
Deribit provides heartbeat verification process. Client sends:  {‘action’: ‘/api/v1/public/ping’}, the server returns heartbeats {“result”:”pong”} to indicate connection between the clients and the server. If the client stops receiving the heartbeats, then it needs to reconnect with the server.
Each WebSocket request has the following structure (private WS API request uses ’sig’ property as a replacement of ’x-deribit-sig’ header for the REST API):
    "id": 201,     // id, developer identifies the response by the request id (the response has the same id with the corresponding request)
    "action": URI Path, // request URI Path
    "arguments": {key: value}, // same arguments as for the REST API
    "sig": signature // request signature if it is necessary (private API), same as for the REST API

WebSocket response is a websocket message, example of handling:
// ws is the JavaScript WebSocket object
ws.onmessage = function (e) {
                if (e.data.length > 0) {
                    // get JSON object of the API response
                    var obj = JSON.parse(e.data);
					// use obj
List of WebSocket API corresponding to the REST API and they URI:
  • getinstruments – action, URI Path /api/v1/public/getinstruments
  • getcurrencies – action, URI Path /api/v1/public/getcurrencies
  • getorderbook – action, URI Path /api/v1/public/getorderbook
  • getlasttrades – action, URI Path /api/v1/public/getlasttrades
  • getsummary – action, URI Path /api/v1/public/getsummary
  • account – action, URI Path /api/v1/private/account
  • buy – action, URI Path /api/v1/private/buy
  • sell – action, URI Path /api/v1/private/sell
  • edit – action, URI Path /api/v1/private/edit
  • cancel – action, URI Path /api/v1/private/cancel
  • cancelall – action, URI Path /api/v1/private/cancelall
  • getopenorders – action, URI Path /api/v1/private/getopenorders
  • positions- action, URI Path /api/v1/private/positions
  • orderhistory – action, URI Path /api/v1/private/orderhistory