Websocket API

The Deribit Websocket API can be used for all of the HTTP RPC endpoints. On top of this, the Websocket adds support for CoD (Cancel on Disconnect) and notification.

WebSocket address is wss://www.deribit.com/ws/api/v1/ and test WebSocket server address is wss://test.deribit.com/ws/api/v1/. Before using the Websocket API, you'll need to enable it via the Deribit API Console (go to Account > API tab > API Console tab).

All websocket messages, are JSON encoded objects. This is true for user-generated messages and server-generated messages.

RPC Message structure

Messages sent by the user consist of the following fields:

name type example description
action string '/api/v1/private/account' The endpoint to call
id integer 42 A user assigned message number, to match requests and their responses
arguments object {"ext": true} The arguments for the endpoint. If the endpoint does not take any arguments, this field can be left out
sig string The signature for the request. For public endpoints, this field can be left out. Check RPC authentication for details on how to compute this signature.

The server will respond with:

name type example description
id integer 42 The message id specified in the call
success bool true Whether the call was successful
error int Only present when there is an error to report. If so, the message field will contain more information. Check Error codes to determine what the error is.
testnet boolean false Indicates whether the API in use is actually the test API. false for production server, true for test server
message string Additional information about the request. Typically used to provide error details
usIn integer 1528920124554066 The time in microseconds (since Jan 1^st 2017) that the requests was received
usOut integer 1528920124554067 The time in microseconds (since Jan 1^st 2017) that the response was sent
usDiff integer The number microseconds that was spent handling the request
result * If successful, the response for the API call

Consult RPC Endpoints to see which endpoints are available.

example

RPC Request:

{
    "id": 42,
    "action": "`/api/v1/private/account`",
    "arguments": {"ext": true},
    "sig": "19EPj2jMRW46e.1328811339209.i5g0KXArbtnYDRuHkn9PYRAQ2xGzP4qM5KXcMSG3Wcw="
}

RPC Response:

{
    "id": 42,
    "success": true,
    "testnet": false,
    "message": "",
    "result": {...},
    "usIn": 1328811339209183,
    "usOut": 1328811339209783
}

Notification Message structure

To receive event notifications, send a subscribe RPC call.

The following event channels can be subscribed to:

  • order_book, notifies of order book changes
  • trade, trade notifications
  • my_trade, trade notifications, filtered for user trades.
  • user_order, notifies of opened, changed or filled user orders.
  • index, notifies of index value at frequent intervals.
  • portfolio, notifies of portfolio changes.
  • announcement, notifies of index value at frequent intervals.

Keep-alive

The Deribit Websocket provides two mechanisms for keep-alive and to prevent stale connections, one initiated by the client, and one initiated by the server.

To use the client-initiated mechanism, send {"action": "/api/v1/public/ping"} over the websocket connection. Within a millisecond (plus network delay),the server will respond with {"result":"pong"}. If you do not receive a response, you should treat the connection as dead, and reconnect.

To use the server-initiated mechanism, send {"action": "/api/v1/public/setheartbeat", "arguments": {"interval": 60}} over the websocket connection. After 60 seconds, the server will send two messages: {"message":"heartbeat"} and {"message":"test_request"}. If you do not receive a heartbeat message within 60 seconds, you should treat the connection as dead. When you receive a test_request message, you should respond by any websocket message, ping was specifically designed for this purpose. If you do not respond within 60 seconds (the heartbeat interval), the server will treat your connection as stale, and close it. While these examples used a heartbeat of 60 seconds, heartbeats as fast as 10 seconds are permitted.

Rate Limits

Current rate limit is 200 (order) client messages per second with bursts to 300. If you need higher rate limits please contact support.

Endpoints

The following endpoints are available. To use an endpoint, specify it in the action field. Endpoint starting with /api/v1/private/ require a signature in the sig field. Check RPC authentication for details on how to compute this signature.

Path Description
/api/v1/public/time Check server time
/api/v1/public/test Check connectivity
/api/v1/public/ping Keep alive websocket connection
/api/v1/public/setheartbeat Switches heartbeat keep-alive on
/api/v1/public/cancelheartbeat Switches heartbeat keep-alive off
/api/v1/public/getinstruments Retrieve available instruments
/api/v1/public/getcurrencies Retrieve available cryptocurrencies
/api/v1/public/index Retrieve the value of the Deribit Index
/api/v1/public/getorderbook Retrieve the order book
/api/v1/public/getlasttrades Retrieve the latest trades
/api/v1/public/getsummary Retrieves the summary information such as Open Interest, 24H Volume, etc.
/api/v1/public/stats Retrieve aggregated 24h trade volumes for different instrument types
/api/v1/public/getannouncements Retrieve announcements
/api/v1/public/getlastsettlements Retrieve settlements, deliveries and bankruptcies
/api/v1/private/account Retrieve account information, including balances
/api/v1/private/buy Place a buy order
/api/v1/private/sell Place a sell order
/api/v1/private/edit Edit an existing order
/api/v1/private/cancel Cancel an order
/api/v1/private/cancelall Bulk cancel orders
/api/v1/private/getopenorders Retrieve list of orders
/api/v1/private/positions Retrieve current positions
/api/v1/private/orderhistory Retrieve historic orders for account
/api/v1/private/orderstate Retrieve details of one order
/api/v1/private/tradehistory Retrieve historic trades for account
/api/v1/private/newannouncements Retrieve unread announcements
/api/v1/private/getemaillang Check email language
/api/v1/private/setemaillang Change email language
/api/v1/private/setannouncementasread Mark announcements as read
/api/v1/private/settlementhistory Retrieve settlements affecting account
/api/v1/private/cancelondisconnect Toggles CoD (cancel on disconnect)
/api/v1/private/subscribe Subscribe to notification channels
/api/v1/private/unsubscribe Unsubscribe from notification channels
/api/v1/private/logout Cleanly closes the connection

results matching ""

    No results matching ""