Deribit API v2.0.1
Overview
Deribit provides three different interfaces to access the API:
- JSON-RPC over Websocket
- JSON-RPC over HTTP
- FIX (Financial Information eXchange)
Deribit features testing environment, test.deribit.com
, which can be used to test the API. For this reason all examples in this documentation refer to that environment. To reach production environment it should be changed to www.deribit.com
. Note that both environments are separate, which means that they require separate accounts and credentials (API keys) to authenticate using private methods - test credentials do not work in production enviromnent and vice versa.
To see the list of your API keys check Account > API tab, where you'll also find a link to API Console (>_ Api Console
) which allows you to test JSON-RPC API, both via HTTP and Websocket.
- Error Codes (HTTP and Websocket RPC Error codes)
Naming
Deribit tradeable assets or instruments use the following system of naming:
Kind | Examples | Template | Comments |
---|---|---|---|
Future | BTC-25MAR16 , BTC-5AUG16 |
BTC-DMMMYY |
BTC is currency, DMMMYY is expiration date, D stands for day of month (1 or 2 digits), MMM - month (3 first letters in English), YY stands for year. |
Perpetual | BTC-PERPETUAL |
Perpetual contract for currency BTC . |
|
Option | BTC-25MAR16-420-C , BTC-5AUG16-580-P |
BTC-DMMMYY-STRIKE-K |
STRIKE is option strike price in USD. Template K is option kind: C for call options or P for put options. |
Rate Limits
Rate limits are described on separate document.
JSON-RPC
JSON-RPC is a light-weight remote procedure call (RPC) protocol. The JSON-RPC specification defines the data structures that are used for the messages that are exchanged between client and server, as well as the rules around their processing. JSON-RPC uses JSON (RFC 4627) as data format.
JSON-RPC is transport agnostic: it does not specify which transport mechanism must be used. The Deribit API supports both Websocket (preferred) and HTTP (with limitations: subscriptions are not supported over HTTP).
Request messages
An example of a request message:
{
"jsonrpc": "2.0",
"id": 8066,
"method": "public/ticker",
"params": {
"instrument": "BTC-24AUG18-6500-P"
}
}
According to the JSON-RPC sepcification the requests must be JSON objects with the following fields.
Name | Type | Description |
---|---|---|
jsonrpc | string | The version of the JSON-RPC spec: "2.0" |
id | integer or string | An identifier of the request. If it is included, then the response will contain the same identifier |
method | string | The method to be invoked |
params | object | The parameters values for the method. The field names must match with the expected parameter names. The parameters that are expected are described in the documentation for the methods, below. |
Response messages
An example of a response message:
{
"jsonrpc": "2.0",
"id": 5239,
"testnet": false,
"result": [
{
"coin_type": "BITCOIN",
"currency": "BTC",
"currency_long": "Bitcoin",
"fee_precision": 4,
"min_confirmations": 1,
"min_withdrawal_fee": 0.0001,
"withdrawal_fee": 0.0001,
"withdrawal_priorities": [
{
"value": 0.15,
"name": "very_low"
},
{
"value": 1.5,
"name": "very_high"
}
]
}
],
"usIn": 1535043730126248,
"usOut": 1535043730126250,
"usDiff": 2
}
The JSON-RPC API always responds with a JSON object with the following fields.
Name | Type | Description |
---|---|---|
id | integer | This is the same id that was sent in the request. |
result | any | If successful, the result of the API call. The format for the result is described with each method. |
error | error object | Only present if there was an error invoking the method. The error object is described below. |
testnet | boolean | Indicates whether the API in use is actually the test API. false for production server, true for test server. |
usIn | integer | The timestamp when the requests was received (microseconds since the Unix epoch) |
usOut | integer | The timestamp when the response was sent (microseconds since the Unix epoch) |
usDiff | integer | The number of microseconds that was spent handling the request |
An example of a response with an error:
{
"jsonrpc": "2.0",
"id": 8163,
"error": {
"code": 11050,
"message": "bad_request"
},
"testnet": false,
"usIn": 1535037392434763,
"usOut": 1535037392448119,
"usDiff": 13356
}
In case of an error the response message will contain the error field, with as value an object with the following with the following fields:
Name | Type | Description |
---|---|---|
code | integer | A number that indicates the kind of error. |
message | string | A short description that indicates the kind of error. |
data | any | Additional data about the error. This field may be omitted. |
Notifications
An example of a notification:
{
"jsonrpc": "2.0",
"method": "subscription",
"params": {
"channel": "deribit_price_index.btc_usd",
"data": {
"timestamp": 1535098298227,
"price": 6521.17,
"index_name": "btc_usd"
}
}
}
API users can subscribe to certain types of notifications. This means that they will receive JSON-RPC notification-messages from the server when certain events occur, such as changes to the index price or changes to the order book for a certain instrument.
The API methods public/subscribe and private/subscribe are used to set up a subscription. Since HTTP does not support the sending of messages from server to client, these methods are only availble when using the Websocket transport mechanism.
At the moment of subscription a "channel" must be specified. The channel determines the type of events that will be received. See Subscriptions for more details about the channels.
In accordance with the JSON-RPC specification, the format of a notification
is that of a request message without an id
field. The value of the
method
field will always be "subscription"
. The
params
field will always be an object with 2 members:
channel
and data
. The value of the
channel
member is the name of the channel (a string). The
value of the data
member is an object that contains data
that is specific for the channel.
Authentication
An example of a JSON request with token:
{
"id": 5647,
"method": "private/get_subaccounts",
"params": {
"access_token": "1582628593469.1MbQ-J_4.CBP-OqOwm_FBdMYj4cRK2dMXyHPfBtXGpzLxhWg31nHu3H_Q60FpE5_vqUBEQGSiMrIGzw3nC37NMb9d1tpBNqBOM_Ql9pXOmgtV9Yj3Pq1c6BqC6dU6eTxHMFO67x8GpJxqw_QcKP5IepwGBD-gfKSHfAv9AEnLJkNu3JkMJBdLToY1lrBnuedF3dU_uARm"
}
}
The API consists of public
and private
methods. The public methods do not
require authentication. The private methods use OAuth 2.0 authentication.
This means that a valid OAuth access token must be included in the request, which
can be achived by calling method public/auth.
When the token was assigned to the user, it should be passed along, with other request parameters, back to the server:
Connection type | Access token placement |
---|---|
Websocket | Inside request JSON parameters, as an access_token field |
HTTP (REST) | Header Authorization: bearer Token value |
Additional authorization method - basic user credentials
Every private
method could be accessed by providing, inside HTTP Authorization: Basic XXX
header, values with
user ClientId
and assigned ClientSecret
(both values can be found on the API page on the Deribit website) encoded with Base64
:
Authorization: Basic BASE64(
ClientId
+ :
+ ClientSecret
)
Additional authorization method - Deribit signature credentials
The Derbit service provides dedicated authorization method, which harness user generated signature to increase
security level for passing request data. Generated value is passed inside Authorization
header, coded as:
Authorization: deri-hmac-sha256 id=
ClientId
,ts=Timestamp
,sig=Signature
,nonce=Nonce
where:
Deribit credential | Description |
---|---|
ClientId | Can be found on the API page on the Deribit website (the user can configure up to 8 different IDs - with different privileges) |
Timestamp | Time when the request was generated - given as miliseconds. It's valid for 60 seconds since generation, after that time any request with an old timestamp will be rejected. |
Signature | Value for signature calculated as described below |
Nonce | Single usage, user generated initialization vector for the server token |
The signature is generated by the following formula:
RequestData = UPPERCASE(HTTP_METHOD()) + "\n" + URI() + "\n" + RequestBody + "\n";
StringToSign = Timestamp + "\n" + Nonce + "\n" + RequestData;
Signature = HEX_STRING( HMAC-SHA256( ClientSecret, StringToSign ) );
Note the newline characters in RequestData
and StringToSign
variables. If RequestBody
is ommitted in RequestData
, it's treated as an empty string, so these three newline characters must always be present.
Example using shell with openssl
tool:
ClientId=AMANDA
ClientSecret=AMANDASECRECT
Timestamp=$( date +%s000 )
Nonce=$( cat /dev/urandom | tr -dc 'a-z0-9' | head -c8 )
URI="/api/v2/private/get_account_summary?currency=BTC"
HttpMethod=GET
Body=""
Signature=$( echo -ne "${Timestamp}\n${Nonce}\n${HttpMethod}\n${URI}\n${Body}\n" | openssl sha256 -r -hmac "$ClientSecret" | cut -f1 -d' ' )
echo $Signature
shell output> 9bfbc51a2bc372d72cc396cf1a213dc78d42eb74cb7dc272351833ad0de276ab (WARNING: Exact value depends on current timestamp and client credentials)
curl -s -X ${HttpMethod} -H "Authorization: deri-hmac-sha256 id=${ClientId},ts=${Timestamp},nonce=${Nonce},sig=${Signature}" "https://www.deribit.com${URI}"
Additional authorization method - signature credentials (WebSocket API)
Example of authorization using
client_signature
:
# see javascript or python example
// using CryptoJS library
var clientId = "AMANDA";
var clientSecret = "AMANDASECRECT";
var timestamp = Date.now();
var nonce = "abcd";
var data = "";
var signature = CryptoJS.HmacSHA256(`${timestamp}\n${nonce}\n${data}`, accessSecret).toString();
var msg = {
"jsonrpc" : "2.0",
"id" : 4316,
"method" : "public/auth",
"params" : {
"grant_type": "client_signature",
"client_id": clientId,
"timestamp": timestamp,
"signature": signature,
"nonce": nonce,
"data": data
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
import hmac
import hashlib
from datetime import datetime
clientId = "AMANDA"
clientSecret = "AMANDASECRECT"
timestamp = round(datetime.now().timestamp() * 1000)
nonce = "abcd"
data = ""
signature = hmac.new(
bytes(clientSecret, "latin-1"),
msg=bytes('{}\n{}\n{}'.format(timestamp, nonce, data), "latin-1"),
digestmod=hashlib.sha256
).hexdigest().lower()
msg = {
"jsonrpc": "2.0",
"id": 8748,
"method": "public/auth",
"params": {
"grant_type": "client_signature",
"client_id": clientId,
"timestamp": timestamp,
"signature": signature,
"nonce": nonce,
"data": data
}
}
print(msg)
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
When connecting through Websocket, user can request for authorization using client_signature
method, which requires providing following parameters (as a part of JSON request):
JSON parameter | Description |
---|---|
grant_type | Must be client_signature |
client_id | Can be found on the API page on the Deribit website (the user can configure up to 8 different IDs - with different privileges) |
timestamp | Time when the request was generated - given as miliseconds. It's valid for 60 seconds since generation, after that time any request with an old timestamp will be rejected. |
signature | Value for signature calculated as described below |
nonce | Single usage, user generated initialization vector for the server token |
data | Optional field, which contains any user specific value |
The signature is generated by the following formula:
StringToSign = Timestamp + "\n" + Nonce + "\n" + Data;
Signature = HEX_STRING( HMAC-SHA256( ClientSecret, StringToSign ) );
Note the newline characters separating parts of the StringToSign
variable. If Data
is ommitted, it's treated as an empty string, so these two newline characters must always be present.
Example using shell with openssl
tool:
ClientId=AMANDA
ClientSecret=AMANDASECRECT
Timestamp=$( date +%s000 ) # e.g. 1576074319000
Nonce=$( cat /dev/urandom | tr -dc 'a-z0-9' | head -c8 ) # e.g. 1iqt2wls
Data=""
Signature=$( echo -ne "${Timestamp}\n${Nonce}\n${Data}" | openssl sha256 -r -hmac "$ClientSecret" | cut -f1 -d' ' )
echo $Signature
shell output> 56590594f97921b09b18f166befe0d1319b198bbcdad7ca73382de2f88fe9aa1 (WARNING: Exact value depends on current timestamp and client credentials)
You can also check the signature value using some online tools like, e.g: https://codebeautify.org/hmac-generator (remember that you should use it only with your test credentials).
Here's a sample JSON request created using the values from the example above:
{
"jsonrpc" : "2.0",
"id" : 9929,
"method" : "public/auth",
"params" :
{
"grant_type" : "client_signature",
"client_id" : "AMANDA",
"timestamp": "1576074319000",
"nonce": "1iqt2wls",
"data": "",
"signature" : "56590594f97921b09b18f166befe0d1319b198bbcdad7ca73382de2f88fe9aa1"
}
}
Access scope
When asking for access token
user can provide the required access level (called scope
) which defines
what type of functionality he/she wants to use, and whether requests are only going to check for some data or
also to update them.
Scopes are required and checked for private
methods, so if you plan to use only public
information you
can stay with values assigned by default.
Scope | Description |
---|---|
mainaccount | It is set automatically by the server when currently connecting user (his/her credentials) is the main user, otherwise it's not included in the final scope. |
connection | Access with requested parameters is granted when connection is open (or till expiration time). When the connection is closed user need to repeat the authentication request to get new tokens. It is set and used automatically by the server when neither connection nor session scope is provided within the request. |
session:name | The server creates a new session with name provided by the user, then generates tokens and binds them with the session. Access is granted during session lifetime. It allows to reconnect to the server and reuse assigned tokens (before their expiration time). Note that only 16 sessions are allowed per user - when limit is reached session with the shortest lifetime is removed. When using WebSocket it also allows (due to the fact that tokens are bound to the created session) skipping providing access_token with every subsequent request. |
account:read | Access to account methods - read only data. |
account:read_write | Access to account methods - allows to manage account settings, add subaccounts, etc. |
trade:read | Access to trade methods - read only data. |
trade:read_write | Access to trade methods - required to create and modify orders. |
wallet:read | Access to wallet methods - read only data. |
wallet:read_write | Access to wallet methods - allows to withdraw, generate new deposit address, etc. |
wallet:none, account:none, trade:none | Blocked access to specified functionality. |
expires:NUMBER | Access token will expire after NUMBER of seconds. |
ip:ADDR | Token will work with connection from ADDR IPv4 address, when * is provided as ADDR token will work from all IP addresses. |
block_trade:read | Access to block_trade methods - reading info about block trades - read only data. |
block_trade:read_write | Access to block_trade methods - required to create block trades. |
NOTICE: Depending on choosing an authentication method (grant type
) some scopes could be narrowed by the server or limited by user API key configured scope, e.g. when grant_type = client_credentials
and scope = wallet:read_write
could be modified by the server as scope = wallet:read
.
The user shouldn't assume that requested values are blindly accepted and should verify assigned scoped.
JSON-RPC over websocket
Websocket is the prefered transport mechanism for the JSON-RPC API, because it is faster and because it can support subscriptions and cancel on disconnect. The code examples that can be found next to each of the methods show how websockets can be used from Python or Javascript/node.js.
JSON-RPC over HTTP
Besides websockets it is also possible to use the API via HTTP. The code examples for 'shell' show how this can be done using curl. Note that subscriptions and cancel on disconnect are not supported via HTTP.
Methods
Authentication
/public/auth
curl -X GET "https://test.deribit.com/api/v2/public/auth?client_id=fo7WAPRm4P&client_secret=W0H6FJW4IRPZ1MOQ8FP6KMC5RZDUUKXS&grant_type=client_credentials" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9929,
"method" : "public/auth",
"params" : {
"grant_type" : "client_credentials",
"client_id" : "fo7WAPRm4P",
"client_secret" : "W0H6FJW4IRPZ1MOQ8FP6KMC5RZDUUKXS"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9929,
"method" : "public/auth",
"params" : {
"grant_type" : "client_credentials",
"client_id" : "fo7WAPRm4P",
"client_secret" : "W0H6FJW4IRPZ1MOQ8FP6KMC5RZDUUKXS"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9929,
"result": {
"access_token": "1582628593469.1MbQ-J_4.CBP-OqOwm_FBdMYj4cRK2dMXyHPfBtXGpzLxhWg31nHu3H_Q60FpE5_vqUBEQGSiMrIGzw3nC37NMb9d1tpBNqBOM_Ql9pXOmgtV9Yj3Pq1c6BqC6dU6eTxHMFO67x8GpJxqw_QcKP5IepwGBD-gfKSHfAv9AEnLJkNu3JkMJBdLToY1lrBnuedF3dU_uARm",
"expires_in": 31536000,
"refresh_token": "1582628593469.1GP4rQd0.A9Wa78o5kFRIUP49mScaD1CqHgiK50HOl2VA6kCtWa8BQZU5Dr03BhcbXPNvEh3I_MVixKZXnyoBeKJwLl8LXnfo180ckAiPj3zOclcUu4zkXuF3NNP3sTPcDf1B3C1CwMKkJ1NOcf1yPmRbsrd7hbgQ-hLa40tfx6Oa-85ymm_3Z65LZcnCeLrqlj_A9jM",
"scope": "connection mainaccount",
"token_type": "bearer"
}
}
Retrieve an Oauth access token, to be used for authentication of 'private' requests.
Three methods of authentication are supported:
client_credentials
- using the access key and access secret that can be found on the API page on the websiteclient_signature
- using the access key that can be found on the API page on the website and user generated signature. The signature is calculated using some fields provided in the request, using formula described here Deribit signature credentialsrefresh_token
- using a refresh token that was received from an earlier invocation
The response will contain an access token, expiration period (number of seconds that the token is valid) and a refresh token that can be used to get a new set of tokens.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
grant_type | true | string | client_credentials client_signature refresh_token |
Method of authentication |
client_id | true | string | Required for grant type client_credentials and client_signature |
|
client_secret | true | string | Required for grant type client_credentials |
|
refresh_token | true | string | Required for grant type refresh_token |
|
timestamp | true | integer | Required for grant type client_signature , provides time when request has been generated |
|
signature | true | string | Required for grant type client_signature ; it's a cryptographic signature calculated over provided fields using user secret key. The signature should be calculated as an HMAC (Hash-based Message Authentication Code) with SHA256 hash algorithm |
|
nonce | false | string | Optional for grant type client_signature ; delivers user generated initialization vector for the server token |
|
data | false | string | Optional for grant type client_signature ; contains any user specific value |
|
state | false | string | Will be passed back in the response | |
scope | false | string | Describes type of the access for assigned token, possible values: connection , session:name , trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , expires:NUMBER , ip:ADDR . Details are elucidated in Access scope |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› acccess_token | string | |
› expires_in | integer | Token lifetime in seconds |
› refresh_token | string | Can be used to request a new token (with a new lifetime) |
› scope | string | Type of the access for assigned token |
› state | string | Copied from the input (if applicable) |
› token_type | string | Authorization type, allowed value - bearer |
/public/exchange_token
curl -X GET "https://test.deribit.com/api/v2/public/exchange_token?refresh_token=1568800656974.1CWcuzUS.MGy49NK4hpTwvR1OYWfpqMEkH4T4oDg4tNIcrM7KdeyxXRcSFqiGzA_D4Cn7mqWocHmlS89FFmUYcmaN2H7lNKKTnhRg5EtrzsFCCiuyN0Wv9y-LbGLV3-Ojv_kbD50FoScQ8BDXS5b_w6Ir1MqEdQ3qFZ3MLcvlPiIgG2BqyJX3ybYnVpIlrVrrdYD1-lkjLcjxOBNJvvUKNUAzkQ&subject_id=10" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7619,
"method" : "public/exchange_token",
"params" : {
"refresh_token" : "1568800656974.1CWcuzUS.MGy49NK4hpTwvR1OYWfpqMEkH4T4oDg4tNIcrM7KdeyxXRcSFqiGzA_D4Cn7mqWocHmlS89FFmUYcmaN2H7lNKKTnhRg5EtrzsFCCiuyN0Wv9y-LbGLV3-Ojv_kbD50FoScQ8BDXS5b_w6Ir1MqEdQ3qFZ3MLcvlPiIgG2BqyJX3ybYnVpIlrVrrdYD1-lkjLcjxOBNJvvUKNUAzkQ",
"subject_id" : 10
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7619,
"method" : "public/exchange_token",
"params" : {
"refresh_token" : "1568800656974.1CWcuzUS.MGy49NK4hpTwvR1OYWfpqMEkH4T4oDg4tNIcrM7KdeyxXRcSFqiGzA_D4Cn7mqWocHmlS89FFmUYcmaN2H7lNKKTnhRg5EtrzsFCCiuyN0Wv9y-LbGLV3-Ojv_kbD50FoScQ8BDXS5b_w6Ir1MqEdQ3qFZ3MLcvlPiIgG2BqyJX3ybYnVpIlrVrrdYD1-lkjLcjxOBNJvvUKNUAzkQ",
"subject_id" : 10
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9929,
"result": {
"access_token": "1582628593469.1MbQ-J_4.CBP-OqOwm_FBdMYj4cRK2dMXyHPfBtXGpzLxhWg31nHu3H_Q60FpE5_vqUBEQGSiMrIGzw3nC37NMb9d1tpBNqBOM_Ql9pXOmgtV9Yj3Pq1c6BqC6dU6eTxHMFO67x8GpJxqw_QcKP5IepwGBD-gfKSHfAv9AEnLJkNu3JkMJBdLToY1lrBnuedF3dU_uARm",
"expires_in": 31536000,
"refresh_token": "1582628593469.1GP4rQd0.A9Wa78o5kFRIUP49mScaD1CqHgiK50HOl2VA6kCtWa8BQZU5Dr03BhcbXPNvEh3I_MVixKZXnyoBeKJwLl8LXnfo180ckAiPj3zOclcUu4zkXuF3NNP3sTPcDf1B3C1CwMKkJ1NOcf1yPmRbsrd7hbgQ-hLa40tfx6Oa-85ymm_3Z65LZcnCeLrqlj_A9jM",
"scope": "session:named_session mainaccount",
"token_type": "bearer"
}
}
Generates token for new subject id. This method can be used to switch between subaccounts.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
refresh_token | true | string | Refresh token | |
subject_id | true | integer | New subject id |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› acccess_token | string | |
› expires_in | integer | Token lifetime in seconds |
› refresh_token | string | Can be used to request a new token (with a new lifetime) |
› scope | string | Type of the access for assigned token |
› token_type | string | Authorization type, allowed value - bearer |
/public/fork_token
curl -X GET "https://test.deribit.com/api/v2/public/fork_token?refresh_token=1568800656974.1CWcuzUS.MGy49NK4hpTwvR1OYWfpqMEkH4T4oDg4tNIcrM7KdeyxXRcSFqiGzA_D4Cn7mqWocHmlS89FFmUYcmaN2H7lNKKTnhRg5EtrzsFCCiuyN0Wv9y-LbGLV3-Ojv_kbD50FoScQ8BDXS5b_w6Ir1MqEdQ3qFZ3MLcvlPiIgG2BqyJX3ybYnVpIlrVrrdYD1-lkjLcjxOBNJvvUKNUAzkQ&session_name=forked_session_name" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7620,
"method" : "public/fork_token",
"params" : {
"refresh_token" : "1568800656974.1CWcuzUS.MGy49NK4hpTwvR1OYWfpqMEkH4T4oDg4tNIcrM7KdeyxXRcSFqiGzA_D4Cn7mqWocHmlS89FFmUYcmaN2H7lNKKTnhRg5EtrzsFCCiuyN0Wv9y-LbGLV3-Ojv_kbD50FoScQ8BDXS5b_w6Ir1MqEdQ3qFZ3MLcvlPiIgG2BqyJX3ybYnVpIlrVrrdYD1-lkjLcjxOBNJvvUKNUAzkQ",
"session_name" : "forked_session_name"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7620,
"method" : "public/fork_token",
"params" : {
"refresh_token" : "1568800656974.1CWcuzUS.MGy49NK4hpTwvR1OYWfpqMEkH4T4oDg4tNIcrM7KdeyxXRcSFqiGzA_D4Cn7mqWocHmlS89FFmUYcmaN2H7lNKKTnhRg5EtrzsFCCiuyN0Wv9y-LbGLV3-Ojv_kbD50FoScQ8BDXS5b_w6Ir1MqEdQ3qFZ3MLcvlPiIgG2BqyJX3ybYnVpIlrVrrdYD1-lkjLcjxOBNJvvUKNUAzkQ",
"session_name" : "forked_session_name"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9929,
"result": {
"access_token": "1582628593469.1MbQ-J_4.CBP-OqOwm_FBdMYj4cRK2dMXyHPfBtXGpzLxhWg31nHu3H_Q60FpE5_vqUBEQGSiMrIGzw3nC37NMb9d1tpBNqBOM_Ql9pXOmgtV9Yj3Pq1c6BqC6dU6eTxHMFO67x8GpJxqw_QcKP5IepwGBD-gfKSHfAv9AEnLJkNu3JkMJBdLToY1lrBnuedF3dU_uARm",
"expires_in": 31536000,
"refresh_token": "1582628593469.1GP4rQd0.A9Wa78o5kFRIUP49mScaD1CqHgiK50HOl2VA6kCtWa8BQZU5Dr03BhcbXPNvEh3I_MVixKZXnyoBeKJwLl8LXnfo180ckAiPj3zOclcUu4zkXuF3NNP3sTPcDf1B3C1CwMKkJ1NOcf1yPmRbsrd7hbgQ-hLa40tfx6Oa-85ymm_3Z65LZcnCeLrqlj_A9jM",
"scope": "session:named_session mainaccount",
"token_type": "bearer"
}
}
Generates token for new named session. This method can be used only with session scoped tokens.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
refresh_token | true | string | Refresh token | |
session_name | true | string | New session name |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› acccess_token | string | |
› expires_in | integer | Token lifetime in seconds |
› refresh_token | string | Can be used to request a new token (with a new lifetime) |
› scope | string | Type of the access for assigned token |
› token_type | string | Authorization type, allowed value - bearer |
/private/logout
This method is only available via websockets.
var msg =
{"jsonrpc": "2.0",
"method": "private/logout",
"id": 42,
"params": {
"access_token": "1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP"}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{"jsonrpc": "2.0",
"method": "private/logout",
"id": 42,
"params": {
"access_token": "1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP"}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
This method has no response body
Gracefully close websocket connection, when COD (Cancel On Disconnect) is enabled orders are not cancelled
Parameters
This method takes no parameters
Response
This method has no response body
Session management
/public/set_heartbeat
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 9098,
"method" : "public/set_heartbeat",
"params" : {
"interval" : 30
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9098,
"method" : "public/set_heartbeat",
"params" : {
"interval" : 30
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9098,
"result": "ok"
}
Signals the Websocket connection to send and request heartbeats. Heartbeats can be used to detect stale connections.
When heartbeats have been set up, the API server will send heartbeat
messages and test_request
messages. Your software should respond to test_request
messages by sending a /api/v2/public/test
request. If your software fails to do so, the API server will immediately close the connection. If your account is configured to cancel on disconnect, any orders opened over the connection will be cancelled.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
interval | true | number | The heartbeat interval in seconds, but not less than 10 |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/public/disable_heartbeat
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 3562,
"method" : "public/disable_heartbeat",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3562,
"method" : "public/disable_heartbeat",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3562,
"result": "ok"
}
Stop sending heartbeat messages.
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/enable_cancel_on_disconnect
curl -X GET "https://test.deribit.com/api/v2/private/enable_cancel_on_disconnect?scope=account" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/enable_cancel_on_disconnect",
"params" : {
"scope" : "account"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/enable_cancel_on_disconnect",
"params" : {
"scope" : "account"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7859,
"result": "ok"
}
Enable Cancel On Disconnect for the connection. After enabling Cancel On Disconnect all orders created by the connection will be removed when connection is closed. NOTICE It does not affect orders created by other connections - they will remain active ! When change is applied for the account, then every newly opened connection will start with active Cancel on Disconnect.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
scope | false | string | connection account |
Specifies if Cancel On Disconnect change should be applied/checked for the current connection or the account (default - connection )NOTICE: Scope connection can be used only when working via Websocket. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/disable_cancel_on_disconnect
curl -X GET "https://test.deribit.com/api/v2/private/disable_cancel_on_disconnect?scope=account" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 1569,
"method" : "private/disable_cancel_on_disconnect",
"params" : {
"scope" : "account"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 1569,
"method" : "private/disable_cancel_on_disconnect",
"params" : {
"scope" : "account"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 1569,
"result": "ok"
}
Disable Cancel On Disconnect for the connection. When change is applied for the account, then every newly opened connection will start with inactive Cancel on Disconnect.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
scope | false | string | connection account |
Specifies if Cancel On Disconnect change should be applied/checked for the current connection or the account (default - connection )NOTICE: Scope connection can be used only when working via Websocket. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/get_cancel_on_disconnect
curl -X GET "https://test.deribit.com/api/v2/private/get_cancel_on_disconnect?scope=account" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 220,
"method" : "private/get_cancel_on_disconnect",
"params" : {
"scope" : "account"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 220,
"method" : "private/get_cancel_on_disconnect",
"params" : {
"scope" : "account"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 220,
"result": {
"scope" : "account",
"enabled": false
}
}
Read current Cancel On Disconnect configuration for the account.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
scope | false | string | connection account |
Specifies if Cancel On Disconnect change should be applied/checked for the current connection or the account (default - connection )NOTICE: Scope connection can be used only when working via Websocket. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› enabled | boolean | Current configuration status |
› scope | string | Informs if Cancel on Disconnect was checked for the current connection or the account |
Supporting
/public/get_time
curl -X GET "https://test.deribit.com/api/v2/public/get_time?" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7365,
"method" : "public/get_time",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7365,
"method" : "public/get_time",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7365,
"result": 1550147385946
}
Retrieves the current time (in milliseconds). This API endpoint can be used to check the clock skew between your software and Deribit's systems.
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | integer | Current timestamp (milliseconds) |
/public/hello
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 2841,
"method" : "public/hello",
"params" : {
"client_name" : "My Trading Software",
"client_version" : "1.0.2"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2841,
"method" : "public/hello",
"params" : {
"client_name" : "My Trading Software",
"client_version" : "1.0.2"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2841,
"result": {
"version": "1.2.26"
}
}
Method used to introduce the client software connected to Deribit platform over websocket. Provided data may have an impact on the maintained connection and will be collected for internal statistical purposes. In response, Deribit will also introduce itself.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
client_name | true | string | Client software name | |
client_version | true | string | Client software version |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› version | string | The API version |
/public/test
curl -X GET "https://test.deribit.com/api/v2/public/test?" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8212,
"method" : "public/test",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8212,
"method" : "public/test",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8212,
"result": {
"version": "1.2.26"
}
}
Tests the connection to the API server, and returns its version. You can use this to make sure the API is reachable, and matches the expected version.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
expected_result | false | string | exception |
The value "exception" will trigger an error response. This may be useful for testing wrapper libraries. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› version | string | The API version |
Subscription management
Subscription works as notifications, so users will automatically (after subscribing) receive messages from the server. Overview for each channel response format is described in subscriptions section.
/public/subscribe
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 3600,
"method" : "public/subscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3600,
"method" : "public/subscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3600,
"result": [
"deribit_price_index.btc_usd"
]
}
Subscribe to one or more channels.
This is the same method as /private/subscribe, but it can only be used for 'public' channels.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
channels | true | array | A list of channels to subscribe to. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of string | A list of subscribed channels. |
/public/unsubscribe
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 8691,
"method" : "public/unsubscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8691,
"method" : "public/unsubscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8691,
"result": [
"deribit_price_index.btc_usd"
]
}
Unsubscribe from one or more channels.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
channels | true | array | A list of channels to unsubscribe from. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of string | A list of subscribed channels. |
/private/subscribe
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 4235,
"method" : "private/subscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 4235,
"method" : "private/subscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 4235,
"result": [
"deribit_price_index.btc_usd"
]
}
Subscribe to one or more channels.
The name of the channel determines what information will be provided, and in what form.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
channels | true | array | A list of channels to subscribe to. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of string | A list of subscribed channels. |
/private/unsubscribe
This method is only available via websockets.
var msg =
{
"jsonrpc" : "2.0",
"id" : 3370,
"method" : "private/unsubscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3370,
"method" : "private/unsubscribe",
"params" : {
"channels" : [
"deribit_price_index.btc_usd"
]
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3370,
"result": [
"deribit_price_index.btc_usd"
]
}
Unsubscribe from one or more channels.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
channels | true | array | A list of channels to unsubscribe from. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of string | A list of subscribed channels. |
Account management
/public/get_announcements
curl -X GET "https://test.deribit.com/api/v2/public/get_announcements?" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7661,
"method" : "public/get_announcements",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7661,
"method" : "public/get_announcements",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7661,
"result": [
{
"title": "Example announcement",
"publication_timestamp": 1550058362418,
"important": false,
"id": 1550058362418,
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
}
]
}
Retrieves announcements. Default "start_timestamp" parameter value is current timestamp, "count" parameter value must be between 1 and 50, default is 5.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
start_timestamp | false | integer | Timestamp from which we want to retrieve announcements | |
count | false | integer | Maximum count of returned announcements |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› body | string | The HTML body of the announcement |
› confirmation | boolean | Whether the user confirmation is required for this announcement |
› id | number | A unique identifier for the announcement |
› important | boolean | Whether the announcement is marked as important |
› publication_timestamp | integer | The timestamp in ms at which the announcement was published |
› title | string | The title of the announcement |
/private/change_api_key_name
curl -X GET "https://test.deribit.com/api/v2/private/change_api_key_name?id=3&name=KeyName3" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2453,
"method" : "private/change_scope_in_api_key",
"params" : {
"name" : "KeyName3",
"id" : 3
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2453,
"method" : "private/change_scope_in_api_key",
"params" : {
"name" : "KeyName3",
"id" : 3
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2453,
"result": {
"timestamp": 1560242482758,
"max_scope": "account:read_write block_trade:read trade:read_write wallet:read_write",
"id": 3,
"enabled": true,
"default": false,
"client_secret": "B6RsF9rrLY5ezEGBQkyLlV-UC7whyPJ34BMA-kKYpes",
"client_id": "1sXMQBhM",
"name": "KeyName3"
}
}
Changes name for key with given id
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | integer | Id of key | |
name | true | string | Name of key (only letters, numbers and underscores allowed; maximum length - 16 characters) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/change_scope_in_api_key
curl -X GET "https://test.deribit.com/api/v2/private/change_scope_in_api_key?id=3&max_scope=account%3Aread_write+wallet%3Aread_write+block_trade%3Aread+trade%3Aread_write" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2453,
"method" : "private/change_scope_in_api_key",
"params" : {
"max_scope" : "account:read_write wallet:read_write block_trade:read trade:read_write",
"id" : 3
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2453,
"method" : "private/change_scope_in_api_key",
"params" : {
"max_scope" : "account:read_write wallet:read_write block_trade:read trade:read_write",
"id" : 3
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2453,
"result": {
"timestamp": 1560242482758,
"max_scope": "account:read_write block_trade:read trade:read_write wallet:read_write",
"id": 3,
"enabled": true,
"default": false,
"client_secret": "B6RsF9rrLY5ezEGBQkyLlV-UC7whyPJ34BMA-kKYpes",
"client_id": "1sXMQBhM",
"name": ""
}
}
Changes scope for key with given id
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
max_scope | true | string | ||
id | true | integer | Id of key |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/change_subaccount_name
curl -X GET "https://test.deribit.com/api/v2/private/change_subaccount_name?name=new_user_1_1&sid=7" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 3964,
"method" : "private/change_subaccount_name",
"params" : {
"sid" : 7,
"name" : "new_user_1_1"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3964,
"method" : "private/change_subaccount_name",
"params" : {
"sid" : 7,
"name" : "new_user_1_1"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3964,
"result": "ok"
}
Change the user name for a subaccount
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
sid | true | integer | The user id for the subaccount | |
name | true | string | The new user name |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/create_api_key
curl -X GET "https://test.deribit.com/api/v2/private/create_api_key?scope=account%3Aread+trade%3Aread+block_trade%3Aread_write+wallet%3Anone" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8974,
"method" : "private/create_api_key",
"params" : {
"scope" : "account:read trade:read block_trade:read_write wallet:none"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8974,
"method" : "private/create_api_key",
"params" : {
"scope" : "account:read trade:read block_trade:read_write wallet:none"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8974,
"result": {
"timestamp": 1560238048714,
"max_scope": "account:read block_trade:read_write trade:read wallet:none",
"id": 5,
"enabled": true,
"default": false,
"client_secret": "STu1eIkdOsLrDZFCRlddYLXUAx4Cubm4oUhEUoxWHKc",
"client_id": "wcVoQGam",
"name": ""
}
}
Creates new api key with given scope
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
max_scope | true | string | ||
default | false | boolean | If true , new key is marked as default |
|
name | false | string | Name of key (only letters, numbers and underscores allowed; maximum length - 16 characters) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/create_subaccount
curl -X GET "https://test.deribit.com/api/v2/private/create_subaccount?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5414,
"method" : "private/create_subaccount",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5414,
"method" : "private/create_subaccount",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5414,
"result": {
"email": "user_AAA@email.com",
"id": 13,
"is_password": false,
"login_enabled": false,
"portfolio": {
"eth": {
"available_funds": 0,
"available_withdrawal_funds": 0,
"balance": 0,
"currency": "eth",
"equity": 0,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 0
},
"btc": {
"available_funds": 0,
"available_withdrawal_funds": 0,
"balance": 0,
"currency": "btc",
"equity": 0,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 0
}
},
"receive_notifications": false,
"system_name": "user_1_4",
"tfa_enabled": false,
"type": "subaccount",
"username": "user_1_4"
}
}
Create a new subaccount
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
string | User email | |
› id | integer | Subaccount identifier |
› is_password | boolean | true when password for the subaccount has been configured |
› login_enabled | boolean | Informs whether login to the subaccount is enabled |
› portfolio | object | |
› › btc | object | |
› › › available_funds | number | |
› › › available_withdrawal_funds | number | |
› › › balance | number | |
› › › currency | string | |
› › › equity | number | |
› › › initial_margin | number | |
› › › maintenance_margin | number | |
› › › margin_balance | number | |
› › eth | object | |
› › › available_funds | number | |
› › › available_withdrawal_funds | number | |
› › › balance | number | |
› › › currency | string | |
› › › equity | number | |
› › › initial_margin | number | |
› › › maintenance_margin | number | |
› › › margin_balance | number | |
› receive_notifications | boolean | When true - receive all notification emails on the main email |
› system_name | string | System generated user nickname |
› tfa_enabled | boolean | Whether the two factor authentication is enabled |
› type | string | Account type |
› username | string | Account name (given by user) |
/private/disable_api_key
curl -X GET "https://test.deribit.com/api/v2/private/disable_api_key?id=3" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2861,
"method" : "private/disable_api_key",
"params" : {
"id" : 3
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2861,
"method" : "private/disable_api_key",
"params" : {
"id" : 3
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2861,
"result": {
"timestamp": 1560242676023,
"max_scope": "account:read_write block_trade:read trade:read_write wallet:read_write",
"id": 3,
"enabled": false,
"default": false,
"client_secret": "B6RsF9rrLY5ezEGBQkyLlV-UC7whyPJ34BMA-kKYpes",
"client_id": "1sXMQBhM",
"name": ""
}
}
Disables api key with given id
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | integer | Id of key |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/disable_tfa_for_subaccount
curl -X GET "https://test.deribit.com/api/v2/private/disable_tfa_for_subaccount?sid=7" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7640,
"method" : "private/disable_tfa_for_subaccount",
"params" : {
"sid" : 7
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7640,
"method" : "private/disable_tfa_for_subaccount",
"params" : {
"sid" : 7
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7640,
"result": "ok"
}
Disable two factor authentication for a subaccount.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
sid | true | integer | The user id for the subaccount |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/enable_affiliate_program
curl -X GET "https://test.deribit.com/api/v2/private/enable_affiliate_program?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 24,
"method" : "private/enable_affiliate_program",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 24,
"method" : "private/enable_affiliate_program",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc":"2.0",
"id":24,
"result":"ok"
}
Enables affilate program for user
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/enable_api_key
curl -X GET "https://test.deribit.com/api/v2/private/enable_api_key?id=3" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8580,
"method" : "private/enable_api_key",
"params" : {
"id" : 3
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8580,
"method" : "private/enable_api_key",
"params" : {
"id" : 3
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8580,
"result": {
"timestamp": 1560242634599,
"max_scope": "account:read_write block_trade:read trade:read_write wallet:read_write",
"id": 3,
"enabled": true,
"default": false,
"client_secret": "B6RsF9rrLY5ezEGBQkyLlV-UC7whyPJ34BMA-kKYpes",
"client_id": "1sXMQBhM",
"name": ""
}
}
Enables api key with given id
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | integer | Id of key |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/get_account_summary
curl -X GET "https://test.deribit.com/api/v2/private/get_account_summary?currency=BTC&extended=true" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2515,
"method" : "private/get_account_summary",
"params" : {
"currency" : "BTC",
"extended" : true
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2515,
"method" : "private/get_account_summary",
"params" : {
"currency" : "BTC",
"extended" : True
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2515,
"result": {
"balance": 118.72074005,
"options_session_upl": 0,
"deposit_address": "2NC9eNLq1z3MFuZGVp2JgSCATeDzLqwpcY7",
"options_gamma": 0,
"options_theta": 0,
"username": "user",
"equity": 118.77720303,
"type": "main",
"currency": "BTC",
"delta_total": -11.1895,
"futures_session_rpl": -0.00011454,
"portfolio_margining_enabled": false,
"total_pl": -3.46418369,
"margin_balance": 118.77720303,
"tfa_enabled": false,
"options_session_rpl": 0,
"options_delta": 0,
"futures_pl": -3.46418369,
"referrer_id": null,
"id": 3,
"session_upl": 0.05657752,
"available_withdrawal_funds": 118.38439069,
"creation_timestamp": 1594388820315,
"options_pl": 0,
"system_name": "user",
"limits": {
"non_matching_engine": {
"rate": 30,
"burst": 400
},
"matching_engine": {
"rate": 5,
"burst": 20
}
},
"initial_margin": 0.33634936,
"projected_initial_margin": 0.33634936,
"maintenance_margin": 0.24683366,
"projected_maintenance_margin": 0.24683366,
"session_rpl": -0.00011454,
"interuser_transfers_enabled": false,
"options_vega": 0,
"projected_delta_total": -11.1895,
"email": "user@example.com",
"futures_session_upl": 0.05657752,
"available_funds": 118.44085367,
"options_value": 0
}
}
Retrieves user account summary.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
extended | false | boolean | Include additional fields |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› options_gamma | number | Options summary gamma |
› projected_maintenance_margin | number | Projected maintenance margin |
› system_name | string | System generated user nickname (available when parameter extended = true ) |
› margin_balance | number | The account's margin balance |
› tfa_enabled | boolean | Whether two factor authentication is enabled (available when parameter extended = true ) |
› options_value | number | Options value |
› username | string | Account name (given by user) (available when parameter extended = true ) |
› limits | object | |
› › futures | object | Field not included if limits for futures are not set. |
› › › burst | integer | Maximal number of futures related matching engine requests allowed for user in burst mode |
› › › rate | integer | Number of futures related matching engine requests per second allowed for user |
› › matching_engine | object | |
› › › burst | integer | Maximal number of matching engine requests allowed for user in burst mode |
› › › rate | integer | Number of matching engine requests per second allowed for user |
› › non_matching_engine | object | |
› › › burst | integer | Maximal number of non matching engine requests allowed for user in burst mode |
› › › rate | integer | Number of non matching engine requests per second allowed for user |
› › options | object | Field not included if limits for options are not set. |
› › › burst | integer | Maximal number of options related matching engine requests allowed for user in burst mode |
› › › rate | integer | Number of options related matching engine requests per second allowed for user |
› › perpetuals | object | Field not included if limits for perpetuals are not set. |
› › › burst | integer | Maximal number of perpetual related matching engine requests allowed for user in burst mode |
› › › rate | integer | Number of perpetual related matching engine requests per second allowed for user |
› equity | number | The account's current equity |
› futures_pl | number | Futures profit and Loss |
› fees | array of object | User fees in case of any discounts (available when parameter extended = true and user has any discounts) |
› › currency | string | The currency the fee applies to |
› › fee_type | string | Fee type - relative if fee is calculated as a fraction of base instrument fee, fixed if fee is calculated solely using user fee |
› › instrument_type | string | Type of the instruments the fee applies to - future for future instruments (excluding perpetual), perpetual for future perpetual instruments, option for options |
› › maker_fee | number | User fee as a maker |
› › taker_fee | number | User fee as a taker |
› options_session_upl | number | Options session unrealized profit and Loss |
› id | integer | Account id (available when parameter extended = true ) |
› options_vega | number | Options summary vega |
› referrer_id | string | Optional identifier of the referrer (of the affiliation program, and available when parameter extended = true ), which link was used by this account at registration. It coincides with suffix of the affiliation link path after /reg- |
› currency | string | The selected currency |
› login_enabled | boolean | Whether account is loginable using email and password (available when parameter extended = true and account is a subaccount) |
› type | string | Account type (available when parameter extended = true ) |
› futures_session_rpl | number | Futures session realized profit and Loss |
› options_theta | number | Options summary theta |
› portfolio_margining_enabled | boolean | true when portfolio margining is enabled for user |
› projected_delta_total | number | The sum of position deltas without positions that will expire during closest expiration |
› session_rpl | number | Session realized profit and loss |
› delta_total | number | The sum of position deltas |
› options_pl | number | Options profit and Loss |
› available_withdrawal_funds | number | The account's available to withdrawal funds |
› maintenance_margin | number | The maintenance margin. |
› initial_margin | number | The account's initial margin |
› interuser_transfers_enabled | boolean | true when the inter-user transfers are enabled for user (available when parameter extended = true ) |
› futures_session_upl | number | Futures session unrealized profit and Loss |
› options_session_rpl | number | Options session realized profit and Loss |
› available_funds | number | The account's available funds |
string | User email (available when parameter extended = true ) |
|
› creation_timestamp | integer | Time at which the account was created (milliseconds since the Unix epoch; available when parameter extended = true ) |
› session_upl | number | Session unrealized profit and loss |
› total_pl | number | Profit and loss |
› options_delta | number | Options summary delta |
› balance | number | The account's balance |
› projected_initial_margin | number | Projected initial margin |
› deposit_address | string | The deposit address for the account (if available) |
/private/get_affiliate_program_info
curl -X GET "https://test.deribit.com/api/v2/private/get_affiliate_program_info?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"method" : "private/get_affiliate_program_info",
"params" : {
},
"jsonrpc" : "2.0",
"id" : 2
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"method" : "private/get_affiliate_program_info",
"params" : {
},
"jsonrpc" : "2.0",
"id" : 2
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"received": {
"eth": 0.00004,
"btc": 0.000001
},
"number_of_affiliates": 1,
"link": "https://www.deribit.com/reg-xxx.zxyq",
"is_enabled": true
}
}
Retrieves user`s affiliates count, payouts and link.
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› is_enabled | boolean | Status of affiliate program |
› link | string | Affliate link |
› number_of_affiliates | number | Number of affiliates |
› received | object | |
› › btc | number | Total payout received in BTC |
› › eth | number | Total payout received in ETH |
/private/get_email_language
curl -X GET "https://test.deribit.com/api/v2/private/get_email_language?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9265,
"method" : "private/get_email_language",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9265,
"method" : "private/get_email_language",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9265,
"result": "en"
}
Retrieves the language to be used for emails.
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | The abbreviation of the language |
/private/get_new_announcements
curl -X GET "https://test.deribit.com/api/v2/private/get_new_announcements?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 3022,
"method" : "private/get_new_announcements",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3022,
"method" : "private/get_new_announcements",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3022,
"result": [
{
"title": "Example announcement",
"publication_timestamp": 1550058362418,
"important": false,
"id": 1550058362418,
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
}
]
}
Retrieves announcements that have not been marked read by the user.
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› body | string | The HTML body of the announcement |
› confirmation | boolean | Whether the user confirmation is required for this announcement |
› id | number | A unique identifier for the announcement |
› important | boolean | Whether the announcement is marked as important |
› publication_timestamp | integer | The timestamp in ms at which the announcement was published |
› title | string | The title of the announcement |
/private/get_position
curl -X GET "https://test.deribit.com/api/v2/private/get_position?instrument_name=BTC-PERPETUAL" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 404,
"method" : "private/get_position",
"params" : {
"instrument_name" : "BTC-PERPETUAL"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 404,
"method" : "private/get_position",
"params" : {
"instrument_name" : "BTC-PERPETUAL"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 404,
"result": {
"average_price": 0,
"delta": 0,
"direction": "buy",
"estimated_liquidation_price": 0,
"floating_profit_loss": 0,
"index_price": 3555.86,
"initial_margin": 0,
"instrument_name": "BTC-PERPETUAL",
"leverage": 100,
"kind": "future",
"maintenance_margin": 0,
"mark_price": 3556.62,
"open_orders_margin": 0.000165889,
"realized_profit_loss": 0,
"settlement_price": 3555.44,
"size": 0,
"size_currency": 0,
"total_profit_loss": 0
}
}
Retrieve user position.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› average_price | number | Average price of trades that built this position |
› average_price_usd | number | Only for options, average price in USD |
› delta | number | Delta parameter |
› direction | string | Direction: buy , sell or zero |
› estimated_liquidation_price | number | Only for futures, estimated liquidation price |
› floating_profit_loss | number | Floating profit or loss |
› floating_profit_loss_usd | number | Only for options, floating profit or loss in USD |
› gamma | number | Only for options, Gamma parameter |
› index_price | number | Current index price |
› initial_margin | number | Initial margin |
› instrument_name | string | Unique instrument identifier |
› kind | string | Instrument kind, "future" or "option" |
› leverage | integer | Current available leverage for future position |
› maintenance_margin | number | Maintenance margin |
› mark_price | number | Current mark price for position's instrument |
› open_orders_margin | number | Open orders margin |
› realized_funding | number | Realized Funding in current session included in session realized profit or loss, only for positions of perpetual instruments |
› realized_profit_loss | number | Realized profit or loss |
› settlement_price | number | Last settlement price for position's instrument 0 if instrument wasn't settled yet |
› size | number | Position size for futures size in quote currency (e.g. USD), for options size is in base currency (e.g. BTC) |
› size_currency | number | Only for futures, position size in base currency |
› theta | number | Only for options, Theta parameter |
› total_profit_loss | number | Profit or loss from position |
› vega | number | Only for options, Vega parameter |
/private/get_positions
curl -X GET "https://test.deribit.com/api/v2/private/get_positions?currency=BTC&kind=future" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2236,
"method" : "private/get_positions",
"params" : {
"currency" : "BTC",
"kind" : "future"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2236,
"method" : "private/get_positions",
"params" : {
"currency" : "BTC",
"kind" : "future"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2236,
"result": [
{
"average_price": 7440.18,
"delta": 0.006687487,
"direction": "buy",
"estimated_liquidation_price": 1.74,
"floating_profit_loss": 0,
"index_price": 7466.79,
"initial_margin": 0.000197283,
"instrument_name": "BTC-PERPETUAL",
"kind": "future",
"leverage": 34,
"maintenance_margin": 0.000143783,
"mark_price": 7476.65,
"open_orders_margin": 0.000197288,
"realized_funding": -1e-8,
"realized_profit_loss": -9e-9,
"settlement_price": 7476.65,
"size": 50,
"size_currency": 0.006687487,
"total_profit_loss": 0.000032781
}
]
}
Retrieve user positions.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
|
kind | false | string | future option |
Kind filter on positions |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› average_price | number | Average price of trades that built this position |
› average_price_usd | number | Only for options, average price in USD |
› delta | number | Delta parameter |
› direction | string | Direction: buy , sell or zero |
› estimated_liquidation_price | number | Only for futures, estimated liquidation price |
› floating_profit_loss | number | Floating profit or loss |
› floating_profit_loss_usd | number | Only for options, floating profit or loss in USD |
› gamma | number | Only for options, Gamma parameter |
› index_price | number | Current index price |
› initial_margin | number | Initial margin |
› instrument_name | string | Unique instrument identifier |
› kind | string | Instrument kind, "future" or "option" |
› leverage | integer | Current available leverage for future position |
› maintenance_margin | number | Maintenance margin |
› mark_price | number | Current mark price for position's instrument |
› open_orders_margin | number | Open orders margin |
› realized_funding | number | Realized Funding in current session included in session realized profit or loss, only for positions of perpetual instruments |
› realized_profit_loss | number | Realized profit or loss |
› settlement_price | number | Last settlement price for position's instrument 0 if instrument wasn't settled yet |
› size | number | Position size for futures size in quote currency (e.g. USD), for options size is in base currency (e.g. BTC) |
› size_currency | number | Only for futures, position size in base currency |
› theta | number | Only for options, Theta parameter |
› total_profit_loss | number | Profit or loss from position |
› vega | number | Only for options, Vega parameter |
/private/get_subaccounts
curl -X GET "https://test.deribit.com/api/v2/private/get_subaccounts?with_portfolio=true" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 4947,
"method" : "private/get_subaccounts",
"params" : {
"with_portfolio" : true
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 4947,
"method" : "private/get_subaccounts",
"params" : {
"with_portfolio" : True
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 4947,
"result": [
{
"email": "user_AAA@email.com",
"id": 2,
"is_password": true,
"login_enabled": true,
"portfolio": {
"eth": {
"available_funds": 5,
"available_withdrawal_funds": 5,
"balance": 5,
"currency": "eth",
"equity": 5,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 5
},
"btc": {
"available_funds": 5.000413075,
"available_withdrawal_funds": 5.000413075,
"balance": 5.000593987,
"currency": "btc",
"equity": 5.000571846,
"initial_margin": 0.000158771,
"maintenance_margin": 0.000115715,
"margin_balance": 5.000571846
}
},
"receive_notifications": false,
"system_name": "user_1",
"tfa_enabled": false,
"type": "main",
"username": "user_1"
},
{
"email": "user_AAA@gmail.com",
"id": 7,
"is_password": true,
"login_enabled": false,
"portfolio": {
"eth": {
"available_funds": 0,
"available_withdrawal_funds": 0,
"balance": 0,
"currency": "eth",
"equity": 0,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 0
},
"btc": {
"available_funds": 0,
"available_withdrawal_funds": 0,
"balance": 0,
"currency": "btc",
"equity": 0,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 0
}
},
"receive_notifications": false,
"system_name": "user_1_1",
"tfa_enabled": false,
"type": "subaccount",
"username": "user_1_1"
},
{
"email": "user_AAA@gmail.com",
"id": 11,
"is_password": false,
"login_enabled": false,
"portfolio": {
"eth": {
"available_funds": 0,
"available_withdrawal_funds": 0,
"balance": 0,
"currency": "eth",
"equity": 0,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 0
},
"btc": {
"available_funds": 0,
"available_withdrawal_funds": 0,
"balance": 0,
"currency": "btc",
"equity": 0,
"initial_margin": 0,
"maintenance_margin": 0,
"margin_balance": 0
}
},
"receive_notifications": false,
"system_name": "user_1_2",
"tfa_enabled": false,
"type": "subaccount",
"username": "user_1_2"
}
]
}
Get information about subaccounts
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
with_portfolio | false | boolean |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
string | User email | |
› id | integer | Account/Subaccount identifier |
› is_password | boolean | true when password for the subaccount has been configured |
› login_enabled | boolean | Informs whether login to the subaccount is enabled |
› not_confirmed_email | string | New email address that has not yet been confirmed. This field is only included if with_portfolio == true . |
› portfolio | object | |
› › btc | object | |
› › › available_funds | number | |
› › › available_withdrawal_funds | number | |
› › › balance | number | |
› › › currency | string | |
› › › equity | number | |
› › › initial_margin | number | |
› › › maintenance_margin | number | |
› › › margin_balance | number | |
› › eth | object | |
› › › available_funds | number | |
› › › available_withdrawal_funds | number | |
› › › balance | number | |
› › › currency | string | |
› › › equity | number | |
› › › initial_margin | number | |
› › › maintenance_margin | number | |
› › › margin_balance | number | |
› receive_notifications | boolean | When true - receive all notification emails on the main email |
› system_name | string | System generated user nickname |
› tfa_enabled | boolean | Whether the two factor authentication is enabled |
› type | string | |
› username | string |
/private/list_api_keys
curl -X GET "https://test.deribit.com/api/v2/private/list_api_keys?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2553,
"method" : "private/list_api_keys"
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2553,
"method" : "private/list_api_keys"
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2553,
"result": [
{
"timestamp": 1560236001108,
"max_scope": "account:read block_trade:read trade:read_write wallet:read",
"id": 1,
"enabled": false,
"default": false,
"client_secret": "SjM57m1T2CfXZ4vZ76X1APjqRlJdtzHI8IwVXoQnfoM",
"client_id": "TiA4AyLPq3",
"name": ""
},
{
"timestamp": 1560236287708,
"max_scope": "account:read_write block_trade:read_write trade:read_write wallet:read_write",
"id": 2,
"enabled": true,
"default": true,
"client_secret": "mwNOvbUVyQczytQ5IVM8CbzmgqNJ81WvLKfu6MXcJPs",
"client_id": "aD-KFx-H",
"name": ""
}
]
}
Retrieves list of api keys
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
tfa | false | string | TFA code, required when TFA is enabled for current account |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/remove_api_key
curl -X GET "https://test.deribit.com/api/v2/private/remove_api_key?id=2" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8190,
"method" : "private/remove_api_key",
"params" : {
"id" : 2
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8190,
"method" : "private/remove_api_key",
"params" : {
"id" : 2
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8190,
"result": "ok"
}
Removes api key
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | integer | Id of key |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/remove_subaccount
curl -X GET "https://test.deribit.com/api/v2/private/remove_subaccount?subaccount_id=120" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"method" : "private/remove_subaccount",
"params" : {
"subaccount_id" : 120
},
"jsonrpc" : "2.0",
"id" : 6
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"method" : "private/remove_subaccount",
"params" : {
"subaccount_id" : 120
},
"jsonrpc" : "2.0",
"id" : 6
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 6,
"result": "ok"
}
Remove empty subaccount.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
subaccount_id | true | integer | The user id for the subaccount |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/reset_api_key
curl -X GET "https://test.deribit.com/api/v2/private/reset_api_key?id=3" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 6524,
"method" : "private/reset_api_key",
"params" : {
"id" : 3
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 6524,
"method" : "private/reset_api_key",
"params" : {
"id" : 3
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 6524,
"result": {
"timestamp": 1560238942222,
"max_scope": "account:read block_trade:read trade:read wallet:read",
"id": 3,
"enabled": true,
"default": false,
"client_secret": "P9Z_c73KaBPwpoTVfsXzehAhjhdJn5kM7Zlz_hhDhE8",
"client_id": "IY2D68DS",
"name": ""
}
}
Resets secret in api key
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | integer | Id of key |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/set_announcement_as_read
curl -X GET "https://test.deribit.com/api/v2/private/set_announcement_as_read?announcement_id=1550058362418" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5147,
"method" : "private/set_announcement_as_read",
"params" : {
"announcement_id" : 1550058362418
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5147,
"method" : "private/set_announcement_as_read",
"params" : {
"announcement_id" : 1550058362418
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5147,
"result": "ok"
}
Marks an announcement as read, so it will not be shown in get_new_announcements
.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
announcement_id | true | number | the ID of the announcement |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/set_api_key_as_default
curl -X GET "https://test.deribit.com/api/v2/private/set_api_key_as_default?id=3" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 402,
"method" : "private/set_api_key_as_default",
"params" : {
"id" : 3
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 402,
"method" : "private/set_api_key_as_default",
"params" : {
"id" : 3
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 402,
"result": {
"timestamp": 1560242795712,
"max_scope": "account:read_write block_trade:read trade:read_write wallet:read_write",
"id": 3,
"enabled": false,
"default": true,
"client_secret": "B6RsF9rrLY5ezEGBQkyLlV-UC7whyPJ34BMA-kKYpes",
"client_id": "1sXMQBhM",
"name": ""
}
}
Sets key with given id as default one for API Console
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | integer | Id of key |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› client_id | string | Client identifier used for authentication |
› client_secret | string | Client secret used for authentication |
› default | boolean | Informs whether this api key is default (field is deprecated and will be removed in the future) |
› enabled | boolean | Informs whether api key is enabled and can be used for authentication |
› id | integer | key identifier |
› max_scope | string | Describes maximal access for tokens generated with given key, possible values: trade:[read, read_write, none] , wallet:[read, read_write, none] , account:[read, read_write, none] , block_trade:[read, read_write, none] . If scope is not provided, it value is set as none. Please check details described in Access scope |
› name | string | Api key name that can be displayed in transaction log |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
/private/set_email_for_subaccount
curl -X GET "https://test.deribit.com/api/v2/private/set_email_for_subaccount?email=user_1_1%40email.com&sid=7" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 1667,
"method" : "private/set_email_for_subaccount",
"params" : {
"sid" : 7,
"email" : "user_1_1@email.com"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 1667,
"method" : "private/set_email_for_subaccount",
"params" : {
"sid" : 7,
"email" : "user_1_1@email.com"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 1667,
"result": "ok"
}
Assign an email address to a subaccount. User will receive an email with confirmation link.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
sid | true | integer | The user id for the subaccount | |
true | string | The email address for the subaccount |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/set_email_language
curl -X GET "https://test.deribit.com/api/v2/private/set_email_language?language=en" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 3269,
"method" : "private/set_email_language",
"params" : {
"language" : "en"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3269,
"method" : "private/set_email_language",
"params" : {
"language" : "en"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3269,
"result": "ok"
}
Changes the language to be used for emails.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
language | true | string | The abbreviated language name. Valid values include "en" , "ko" , "zh" , "ja" , "ru" |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/set_password_for_subaccount
curl -X GET "https://test.deribit.com/api/v2/private/set_password_for_subaccount?password=ABCDEFGHIJKLMO&sid=7" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5819,
"method" : "private/set_password_for_subaccount",
"params" : {
"sid" : 7,
"password" : "ABCDEFGHIJKLMO"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5819,
"method" : "private/set_password_for_subaccount",
"params" : {
"sid" : 7,
"password" : "ABCDEFGHIJKLMO"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5819,
"result": "ok"
}
Set the password for the subaccount
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
sid | true | integer | The user id for the subaccount | |
password | true | string | The password for the subaccount |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/toggle_notifications_from_subaccount
curl -X GET "https://test.deribit.com/api/v2/private/toggle_notifications_from_subaccount?sid=7&state=true" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9995,
"method" : "private/toggle_notifications_from_subaccount",
"params" : {
"sid" : 7,
"state" : true
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9995,
"method" : "private/toggle_notifications_from_subaccount",
"params" : {
"sid" : 7,
"state" : True
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9995,
"result": "ok"
}
Enable or disable sending of notifications for the subaccount.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
sid | true | integer | The user id for the subaccount | |
state | true | boolean | enable (true ) or disable (false ) notifications |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/toggle_subaccount_login
curl -X GET "https://test.deribit.com/api/v2/private/toggle_subaccount_login?sid=7&state=enable" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 938,
"method" : "private/toggle_subaccount_login",
"params" : {
"sid" : 7,
"state" : "enable"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 938,
"method" : "private/toggle_subaccount_login",
"params" : {
"sid" : 7,
"state" : "enable"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 938,
"result": "ok"
}
Enable or disable login for a subaccount. If login is disabled and a session for the subaccount exists, this session will be terminated.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
sid | true | integer | The user id for the subaccount | |
state | true | string | enable disable |
enable or disable login. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
Block Trade
/private/execute_block_trade
curl -X GET "https://test.deribit.com/api/v2/private/execute_block_trade?counterparty_signature=1590485595899.1Mn52L_Q.lNyNBzXXo-_QBT_wDuMgnhA7uS9tBqdQ5TLN6rxbuoAiQhyaJYGJrm5IV_9enp9niY_x8D60AJLm3yEKPUY1Dv3T0TW0n5-ADPpJF7Fpj0eVDZpZ6QCdX8snBWrSJ0TtqevnO64RCBlN1dIm2T70PP9dlhiqPDAUYI4fpB1vLYI¤cy=BTC&nonce=bszyprbq&role=maker×tamp=1590485535899&trades=%5B%7B%22price%22%3A8900.0%2C%22instrument_name%22%3A%22BTC-PERPETUAL%22%2C%22direction%22%3A%22sell%22%2C%22amount%22%3A200000%7D%2C%7B%22price%22%3A0.0133%2C%22instrument_name%22%3A%22BTC-28MAY20-9000-C%22%2C%22direction%22%3A%22sell%22%2C%22amount%22%3A5.0%7D%5D" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"method" : "private/execute_block_trade",
"params" : {
"currency" : "BTC",
"nonce" : "bszyprbq",
"timestamp" : 1590485535899,
"role" : "maker",
"trades" : [
{
"instrument_name" : "BTC-PERPETUAL",
"direction" : "sell",
"price" : 8900.0,
"amount" : 200000
},
{
"instrument_name" : "BTC-28MAY20-9000-C",
"direction" : "sell",
"amount" : 5.0,
"price" : 0.0133
}
],
"counterparty_signature" : "1590485595899.1Mn52L_Q.lNyNBzXXo-_QBT_wDuMgnhA7uS9tBqdQ5TLN6rxbuoAiQhyaJYGJrm5IV_9enp9niY_x8D60AJLm3yEKPUY1Dv3T0TW0n5-ADPpJF7Fpj0eVDZpZ6QCdX8snBWrSJ0TtqevnO64RCBlN1dIm2T70PP9dlhiqPDAUYI4fpB1vLYI"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"method" : "private/execute_block_trade",
"params" : {
"currency" : "BTC",
"nonce" : "bszyprbq",
"timestamp" : 1590485535899,
"role" : "maker",
"trades" : [
{
"instrument_name" : "BTC-PERPETUAL",
"direction" : "sell",
"price" : 8900.0,
"amount" : 200000
},
{
"instrument_name" : "BTC-28MAY20-9000-C",
"direction" : "sell",
"amount" : 5.0,
"price" : 0.0133
}
],
"counterparty_signature" : "1590485595899.1Mn52L_Q.lNyNBzXXo-_QBT_wDuMgnhA7uS9tBqdQ5TLN6rxbuoAiQhyaJYGJrm5IV_9enp9niY_x8D60AJLm3yEKPUY1Dv3T0TW0n5-ADPpJF7Fpj0eVDZpZ6QCdX8snBWrSJ0TtqevnO64RCBlN1dIm2T70PP9dlhiqPDAUYI4fpB1vLYI"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc":"2.0",
"result":{
"trades":[
{
"trade_seq":30289730,
"trade_id":"48079573",
"timestamp":1590485535978,
"tick_direction":0,
"state":"filled",
"self_trade":false,
"reduce_only":false,
"price":8900.0,
"post_only":false,
"order_type":"limit",
"order_id":"4009043192",
"matching_id":"None",
"mark_price":8895.19,
"liquidity":"M",
"instrument_name":"BTC-PERPETUAL",
"index_price":8900.45,
"fee_currency":"BTC",
"fee":-0.00561798,
"direction":"sell",
"block_trade_id":"6165",
"amount":200000.0
},
{
"underlying_price":8902.86,
"trade_seq":1,
"trade_id":"48079574",
"timestamp":1590485535979,
"tick_direction":1,
"state":"filled",
"self_trade":false,
"reduce_only":false,
"price":0.0133,
"post_only":false,
"order_type":"limit",
"order_id":"4009043194",
"matching_id":"None",
"mark_price":0.01831619,
"liquidity":"M",
"iv":62.44,
"instrument_name":"BTC-28MAY20-9000-C",
"index_price":8900.45,
"fee_currency":"BTC",
"fee":0.002,
"direction":"sell",
"block_trade_id":"6165",
"amount":5.0
}
],
"timestamp":1590485535980,
"initiator_user_id":3,
"id":"6165",
"executor_user_id":76,
"currency":"BTC"
}
}
Creates block trade
The whole request have to be exact the same as in private/verify_block_trade
, only role field should be set appropriately - it basically means that both sides have to agree on the same timestamp, nonce, trades fields and server will assure that role field is different between sides (each party accepted own role).
Using the same timestamp and nonce by both sides in private/verify_block_trade
assures that even if unintentionally both sides execute given block trade with valid counterparty_signature, the given block trade will be executed only once.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
timestamp | true | integer | Timestamp, shared with other party | |
nonce | true | string | Nonce, shared with other party | |
role | true | string | maker taker |
Describes if user wants to be maker or taker of trades |
trades | true | array of objects | List of trades for block trade | |
› instrument_name | true | string | Instrument name | |
› price | true | number | Price for trade | |
› amount | true | number | It represents the requested trade size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH | |
› direction | true | string | buy sell |
Direction of trade from the maker perspective |
counterparty_signature | true | string | Signature of block trade generated by private/verify_block_trade_method |
|
currency | false | string | BTC ETH USDT |
The currency symbol |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› executor_user_id | integer | Id of user that executed block_trade |
› id | string | Block trade id |
› initiator_user_id | integer | Id of user that initiated block_trade |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_block_trade
curl -X GET "https://test.deribit.com/api/v2/private/get_block_trade?id=61" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"method" : "private/get_block_trade",
"params" : {
"id" : "61"
},
"jsonrpc" : "2.0"
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"method" : "private/get_block_trade",
"params" : {
"id" : "61"
},
"jsonrpc" : "2.0"
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"result": {
"trades": [
{
"trade_seq": 37,
"trade_id": "92437",
"timestamp": 1565089523719,
"tick_direction": 3,
"state": "filled",
"self_trade": false,
"price": 0.0001,
"order_type": "limit",
"order_id": "343062",
"matching_id": null,
"liquidity": "T",
"iv": 0,
"instrument_name": "BTC-9AUG19-10250-C",
"index_price": 11738,
"fee_currency": "BTC",
"fee": 0.00025,
"direction": "sell",
"block_trade_id": "61",
"amount": 10
},
{
"trade_seq": 25350,
"trade_id": "92435",
"timestamp": 1565089523719,
"tick_direction": 3,
"state": "filled",
"self_trade": false,
"price": 11590,
"order_type": "limit",
"order_id": "343058",
"matching_id": null,
"liquidity": "T",
"instrument_name": "BTC-PERPETUAL",
"index_price": 11737.98,
"fee_currency": "BTC",
"fee": 0.00000164,
"direction": "buy",
"block_trade_id": "61",
"amount": 190
}
],
"timestamp": 1565089523720,
"initiator_user_id": 2,
"id": "61",
"executor_user_id": 3,
"currency": "BTC"
}
}
Returns information about users block trade
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
id | true | string | Block trade id |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› executor_user_id | integer | Id of user that executed block_trade |
› id | string | Block trade id |
› initiator_user_id | integer | Id of user that initiated block_trade |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_last_block_trades_by_currency
curl -X GET "https://test.deribit.com/api/v2/private/get_last_block_trades_by_currency?count=1¤cy=BTC" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"method" : "private/get_last_block_trades_by_currency",
"params" : {
"currency" : "BTC",
"count" : 1
},
"jsonrpc" : "2.0"
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"method" : "private/get_last_block_trades_by_currency",
"params" : {
"currency" : "BTC",
"count" : 1
},
"jsonrpc" : "2.0"
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"result": [
{
"trades": [
{
"trade_seq": 4,
"trade_id": "92462",
"timestamp": 1565093070164,
"tick_direction": 2,
"state": "filled",
"self_trade": false,
"price": 0.0151,
"order_type": "limit",
"order_id": "343121",
"matching_id": null,
"liquidity": "M",
"iv": 72.38,
"instrument_name": "BTC-9AUG19-11500-P",
"index_price": 11758.65,
"fee_currency": "BTC",
"fee": 0,
"direction": "sell",
"block_trade_id": "66",
"amount": 2.3
},
{
"trade_seq": 41,
"trade_id": "92460",
"timestamp": 1565093070164,
"tick_direction": 2,
"state": "filled",
"self_trade": false,
"price": 11753,
"order_type": "limit",
"order_id": "343117",
"matching_id": null,
"liquidity": "M",
"instrument_name": "BTC-9AUG19",
"index_price": 11758.65,
"fee_currency": "BTC",
"fee": 0,
"direction": "sell",
"block_trade_id": "66",
"amount": 50
}
],
"timestamp": 1565093070165,
"initiator_user_id": 3,
"id": "66",
"executor_user_id": 12,
"currency": "BTC"
}
]
}
Returns list of last users block trades
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
count | false | integer | Number of requested items, default - 20 |
|
start_id | false | string | The id of the newest block trade to be returned | |
end_id | false | string | The id of the oldest block trade to be returned, start_id is required with end_id |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› executor_user_id | integer | Id of user that executed block_trade |
› id | string | Block trade id |
› initiator_user_id | integer | Id of user that initiated block_trade |
› timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/invalidate_block_trade_signature
curl -X GET "https://test.deribit.com/api/v2/private/invalidate_block_trade_signature?signature=1565173369982.1M9tO0Q-.z9n9WyZUU5op9pEz6Jtd2CI71QxQMMsCZAexnIfK9HQRT1pKH3clxeIbY7Bqm-yMcWIoE3IfCDPW5VEdiN-6oS0YkKUyXPD500MUf3ULKhfkmH81EZs" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"method" : "private/invalidate_block_trade_signature",
"params" : {
"signature" : "1565173369982.1M9tO0Q-.z9n9WyZUU5op9pEz6Jtd2CI71QxQMMsCZAexnIfK9HQRT1pKH3clxeIbY7Bqm-yMcWIoE3IfCDPW5VEdiN-6oS0YkKUyXPD500MUf3ULKhfkmH81EZs"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"method" : "private/invalidate_block_trade_signature",
"params" : {
"signature" : "1565173369982.1M9tO0Q-.z9n9WyZUU5op9pEz6Jtd2CI71QxQMMsCZAexnIfK9HQRT1pKH3clxeIbY7Bqm-yMcWIoE3IfCDPW5VEdiN-6oS0YkKUyXPD500MUf3ULKhfkmH81EZs"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc":"2.0",
"result":"ok"
}
User at any time (before the private/execute_block_trade is called) can invalidate its own signature effectively cancelling block trade
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
signature | true | string | Signature of block trade that will be invalidated |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/verify_block_trade
curl -X GET "https://test.deribit.com/api/v2/private/verify_block_trade?currency=BTC&nonce=okpdjkdo&role=maker×tamp=1565172650935&trades=%5B%7B%22price%22%3A11624%2C%22instrument_name%22%3A%22BTC-PERPETUAL%22%2C%22direction%22%3A%22buy%22%2C%22amount%22%3A40%7D%2C%7B%22price%22%3A0.0707%2C%22instrument_name%22%3A%22BTC-9AUG19-10250-P%22%2C%22direction%22%3A%22buy%22%2C%22amount%22%3A1.2%7D%5D" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"method" : "private/verify_block_trade",
"params" : {
"currency" : "BTC",
"nonce" : "okpdjkdo",
"timestamp" : 1565172650935,
"role" : "maker",
"trades" : [
{
"instrument_name" : "BTC-PERPETUAL",
"direction" : "buy",
"price" : 11624,
"amount" : 40
},
{
"instrument_name" : "BTC-9AUG19-10250-P",
"direction" : "buy",
"amount" : 1.2,
"price" : 0.0707
}
]
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"method" : "private/verify_block_trade",
"params" : {
"currency" : "BTC",
"nonce" : "okpdjkdo",
"timestamp" : 1565172650935,
"role" : "maker",
"trades" : [
{
"instrument_name" : "BTC-PERPETUAL",
"direction" : "buy",
"price" : 11624,
"amount" : 40
},
{
"instrument_name" : "BTC-9AUG19-10250-P",
"direction" : "buy",
"amount" : 1.2,
"price" : 0.0707
}
]
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc":"2.0",
"result":{
"signature":"1565172710935.1ESE83qh.g6fbgRd4VWagaJz7xdi2WaV-q-d3J0njoz1jZavuRudZJZif9uH8XdUAx1LHsu0E3e0ZG_xe1UPYlwo41xRVrkWU6OMgygDRafUkEmBuk9iLqjc9rh4"
}
}
Verifies and creates block trade signature
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
timestamp | true | integer | Timestamp, shared with other party | |
nonce | true | string | Nonce, shared with other party | |
role | true | string | maker taker |
Describes if user wants to be maker or taker of trades |
trades | true | array of objects | List of trades for block trade | |
› instrument_name | true | string | Instrument name | |
› price | true | number | Price for trade | |
› amount | true | number | It represents the requested trade size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH | |
› direction | true | string | buy sell |
Direction of trade from the maker perspective |
currency | false | string | BTC ETH USDT |
The currency symbol |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› signature | string | Signature of block trade It is valid only for 5 minutes “around” given timestamp |
Trading
/private/buy
curl -X GET "https://test.deribit.com/api/v2/private/buy?amount=40&instrument_name=ETH-PERPETUAL&label=market0000234&type=market" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5275,
"method" : "private/buy",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"amount" : 40,
"type" : "market",
"label" : "market0000234"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5275,
"method" : "private/buy",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"amount" : 40,
"type" : "market",
"label" : "market0000234"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5275,
"result": {
"trades": [
{
"trade_seq": 1966056,
"trade_id": "ETH-2696083",
"timestamp": 1590483938456,
"tick_direction": 0,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 203.3,
"post_only": false,
"order_type": "market",
"order_id": "ETH-584849853",
"matching_id": null,
"mark_price": 203.28,
"liquidity": "T",
"label": "market0000234",
"instrument_name": "ETH-PERPETUAL",
"index_price": 203.33,
"fee_currency": "ETH",
"fee": 0.00014757,
"direction": "buy",
"amount": 40
}
],
"order": {
"web": false,
"time_in_force": "good_til_cancelled",
"replaced": false,
"reduce_only": false,
"profit_loss": 0.00022929,
"price": 207.3,
"post_only": false,
"order_type": "market",
"order_state": "filled",
"order_id": "ETH-584849853",
"max_show": 40,
"last_update_timestamp": 1590483938456,
"label": "market0000234",
"is_liquidation": false,
"instrument_name": "ETH-PERPETUAL",
"filled_amount": 40,
"direction": "buy",
"creation_timestamp": 1590483938456,
"commission": 0.00014757,
"average_price": 203.3,
"api": true,
"amount": 40
}
}
}
Places a buy order for an instrument.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
amount | true | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH | |
type | false | string | limit stop_limit market stop_market |
The order type, default: "limit" |
label | false | string | user defined label for the order (maximum 64 characters) | |
price | false | number | The order price in base currency (Only for limit and stop_limit orders) When adding order with advanced=usd, the field price should be the option price value in USD. When adding order with advanced=implv, the field price should be a value of implied volatility in percentages. For example, price=100, means implied volatility of 100% |
|
time_in_force | false | string | good_til_cancelled fill_or_kill immediate_or_cancel |
Specifies how long the order remains in effect. Default
|
max_show | false | number | Maximum amount within an order to be shown to other customers, 0 for invisible order |
|
post_only | false | boolean | If true, the order is considered post-only. If the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the spread. Only valid in combination with time_in_force= |
|
reject_post_only | false | boolean | If an order is considered post-only and this field is set to true then the order is put to order book unmodified or request is rejected and order is canceled. Only valid in combination with |
|
reduce_only | false | boolean | If true , the order is considered reduce-only which is intended to only reduce a current position |
|
stop_price | false | number | Stop price, required for stop limit orders (Only for stop orders) | |
trigger | false | string | index_price mark_price last_price |
Defines trigger type, required for "stop_limit" and "stop_market" order types |
advanced | false | string | usd implv |
Advanced option order type. (Only for options) |
mmp | false | boolean | Order MMP flag, only for order_type 'limit' |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› order | object | |
› › order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› › max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› › api | boolean | true if created with API |
› › amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › web | boolean | true if created via Deribit frontend (optional) |
› › instrument_name | string | Unique instrument identifier |
› › advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› › triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› › block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› › original_order_type | string | Original order type. Optional field |
› › price | number | Price in base currency |
› › time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› › auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› › stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› › last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › post_only | boolean | true for post-only orders only |
› › replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› › filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › average_price | number | Average fill price of the order |
› › order_id | string | Unique order identifier |
› › reduce_only | boolean | true for reduce-only orders only |
› › commission | number | Commission paid so far (in base currency) |
› › app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› › stop_price | number | Stop price (Only for future stop orders) |
› › label | string | User defined label (up to 64 characters) |
› › creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › direction | string | Direction: buy , or sell |
› › is_liquidation | boolean | true if order was automatically created during liquidation |
› › order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› › usd | number | Option price in USD (Only if advanced="usd" ) |
› › profit_loss | number | Profit and loss in base currency. |
› › implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› › trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/sell
curl -X GET "https://test.deribit.com/api/v2/private/sell?amount=123&instrument_name=ETH-PERPETUAL&price=1.45610000000000013642e%2B02&stop_price=145&trigger=last_price&type=stop_limit" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2148,
"method" : "private/sell",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"amount" : 123,
"type" : "stop_limit",
"price" : 145.61,
"stop_price" : 145,
"trigger" : "last_price"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2148,
"method" : "private/sell",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"amount" : 123,
"type" : "stop_limit",
"price" : 145.61,
"stop_price" : 145,
"trigger" : "last_price"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2148,
"result": {
"trades": [],
"order": {
"triggered": false,
"trigger": "last_price",
"time_in_force": "good_til_cancelled",
"stop_price": 145,
"reduce_only": false,
"profit_loss": 0,
"price": 145.61,
"post_only": false,
"order_type": "stop_limit",
"order_state": "untriggered",
"order_id": "ETH-SLTS-28",
"max_show": 123,
"last_update_timestamp": 1550659803407,
"label": "",
"is_liquidation": false,
"instrument_name": "ETH-PERPETUAL",
"direction": "sell",
"creation_timestamp": 1550659803407,
"api": true,
"amount": 123
}
}
}
Places a sell order for an instrument.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
amount | true | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH | |
type | false | string | limit stop_limit market stop_market |
The order type, default: "limit" |
label | false | string | user defined label for the order (maximum 64 characters) | |
price | false | number | The order price in base currency (Only for limit and stop_limit orders) When adding order with advanced=usd, the field price should be the option price value in USD. When adding order with advanced=implv, the field price should be a value of implied volatility in percentages. For example, price=100, means implied volatility of 100% |
|
time_in_force | false | string | good_til_cancelled fill_or_kill immediate_or_cancel |
Specifies how long the order remains in effect. Default
|
max_show | false | number | Maximum amount within an order to be shown to other customers, 0 for invisible order |
|
post_only | false | boolean | If true, the order is considered post-only. If the new price would cause the order to be filled immediately (as taker), the price will be changed to be just above the spread. Only valid in combination with time_in_force= |
|
reject_post_only | false | boolean | If an order is considered post-only and this field is set to true then the order is put to order book unmodified or request is rejected and order is canceled. Only valid in combination with |
|
reduce_only | false | boolean | If true , the order is considered reduce-only which is intended to only reduce a current position |
|
stop_price | false | number | Stop price, required for stop limit orders (Only for stop orders) | |
trigger | false | string | index_price mark_price last_price |
Defines trigger type, required for "stop_limit" and "stop_market" order types |
advanced | false | string | usd implv |
Advanced option order type. (Only for options) |
mmp | false | boolean | Order MMP flag, only for order_type 'limit' |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› order | object | |
› › order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› › max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› › api | boolean | true if created with API |
› › amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › web | boolean | true if created via Deribit frontend (optional) |
› › instrument_name | string | Unique instrument identifier |
› › advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› › triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› › block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› › original_order_type | string | Original order type. Optional field |
› › price | number | Price in base currency |
› › time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› › auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› › stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› › last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › post_only | boolean | true for post-only orders only |
› › replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› › filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › average_price | number | Average fill price of the order |
› › order_id | string | Unique order identifier |
› › reduce_only | boolean | true for reduce-only orders only |
› › commission | number | Commission paid so far (in base currency) |
› › app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› › stop_price | number | Stop price (Only for future stop orders) |
› › label | string | User defined label (up to 64 characters) |
› › creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › direction | string | Direction: buy , or sell |
› › is_liquidation | boolean | true if order was automatically created during liquidation |
› › order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› › usd | number | Option price in USD (Only if advanced="usd" ) |
› › profit_loss | number | Profit and loss in base currency. |
› › implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› › trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/edit
curl -X GET "https://test.deribit.com/api/v2/private/edit?advanced=implv&amount=4&order_id=438994&price=222" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 3725,
"method" : "private/edit",
"params" : {
"order_id" : "438994",
"amount" : 4,
"price" : 222,
"advanced" : "implv"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3725,
"method" : "private/edit",
"params" : {
"order_id" : "438994",
"amount" : 4,
"price" : 222,
"advanced" : "implv"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3725,
"result": {
"trades": [],
"order": {
"time_in_force": "good_til_cancelled",
"reduce_only": false,
"profit_loss": 0,
"price": 0.1448,
"post_only": false,
"order_type": "limit",
"order_state": "open",
"order_id": "438994",
"max_show": 4,
"last_update_timestamp": 1550585797677,
"label": "",
"is_liquidation": false,
"instrument_name": "BTC-22FEB19-3500-C",
"implv": 222,
"filled_amount": 0,
"direction": "buy",
"creation_timestamp": 1550585741277,
"commission": 0,
"average_price": 0,
"api": false,
"amount": 4,
"advanced": "implv"
}
}
}
Change price, amount and/or other properties of an order.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
order_id | true | string | The order id | |
amount | true | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH | |
price | false | number | The order price in base currency. When editing an option order with advanced=usd, the field price should be the option price value in USD. When editing an option order with advanced=implv, the field price should be a value of implied volatility in percentages. For example, price=100, means implied volatility of 100% |
|
post_only | false | boolean | If true, the order is considered post-only. If the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below or above the spread (accordingly to the original order type). Only valid in combination with time_in_force= |
|
reduce_only | false | boolean | If true , the order is considered reduce-only which is intended to only reduce a current position |
|
reject_post_only | false | boolean | If an order is considered post-only and this field is set to true then the order is put to order book unmodified or request is rejected and order is canceled. Only valid in combination with |
|
advanced | false | string | usd implv |
Advanced option order type. If you have posted an advanced option order, it is necessary to re-supply this parameter when editing it (Only for options) |
stop_price | false | number | Stop price, required for stop limit orders (Only for stop orders) | |
mmp | false | boolean | Order MMP flag, only for order_type 'limit' |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› order | object | |
› › order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› › max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› › api | boolean | true if created with API |
› › amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › web | boolean | true if created via Deribit frontend (optional) |
› › instrument_name | string | Unique instrument identifier |
› › advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› › triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› › block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› › original_order_type | string | Original order type. Optional field |
› › price | number | Price in base currency |
› › time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› › auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› › stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› › last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › post_only | boolean | true for post-only orders only |
› › replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› › filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › average_price | number | Average fill price of the order |
› › order_id | string | Unique order identifier |
› › reduce_only | boolean | true for reduce-only orders only |
› › commission | number | Commission paid so far (in base currency) |
› › app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› › stop_price | number | Stop price (Only for future stop orders) |
› › label | string | User defined label (up to 64 characters) |
› › creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › direction | string | Direction: buy , or sell |
› › is_liquidation | boolean | true if order was automatically created during liquidation |
› › order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› › usd | number | Option price in USD (Only if advanced="usd" ) |
› › profit_loss | number | Profit and loss in base currency. |
› › implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› › trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/cancel
curl -X GET "https://test.deribit.com/api/v2/private/cancel?order_id=ETH-SLIS-12" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 4214,
"method" : "private/cancel",
"params" : {
"order_id" : "ETH-SLIS-12"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 4214,
"method" : "private/cancel",
"params" : {
"order_id" : "ETH-SLIS-12"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 4214,
"result": {
"triggered": false,
"trigger": "index_price",
"time_in_force": "good_til_cancelled",
"stop_price": 144.73,
"reduce_only": false,
"profit_loss": 0,
"price": "market_price",
"post_only": false,
"order_type": "stop_market",
"order_state": "untriggered",
"order_id": "ETH-SLIS-12",
"max_show": 5,
"last_update_timestamp": 1550575961291,
"label": "",
"is_liquidation": false,
"instrument_name": "ETH-PERPETUAL",
"direction": "sell",
"creation_timestamp": 1550575961291,
"api": false,
"amount": 5
}
}
Cancel an order, specified by order id
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
order_id | true | string | The order id |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› api | boolean | true if created with API |
› amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› web | boolean | true if created via Deribit frontend (optional) |
› instrument_name | string | Unique instrument identifier |
› advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› original_order_type | string | Original order type. Optional field |
› price | number | Price in base currency |
› time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› post_only | boolean | true for post-only orders only |
› replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› average_price | number | Average fill price of the order |
› order_id | string | Unique order identifier |
› reduce_only | boolean | true for reduce-only orders only |
› commission | number | Commission paid so far (in base currency) |
› app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› stop_price | number | Stop price (Only for future stop orders) |
› label | string | User defined label (up to 64 characters) |
› creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› direction | string | Direction: buy , or sell |
› is_liquidation | boolean | true if order was automatically created during liquidation |
› order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› usd | number | Option price in USD (Only if advanced="usd" ) |
› profit_loss | number | Profit and loss in base currency. |
› implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/cancel_all
curl -X GET "https://test.deribit.com/api/v2/private/cancel_all?" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8748,
"method" : "private/cancel_all",
"params" : {
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8748,
"method" : "private/cancel_all",
"params" : {
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8748,
"result": 37
}
This method cancels all users orders and stop orders within all currencies and instrument kinds.
Parameters
This method takes no parameters
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
object | ||
result | number | Total number of successfully cancelled orders |
/private/cancel_all_by_currency
curl -X GET "https://test.deribit.com/api/v2/private/cancel_all_by_currency?currency=BTC&kind=option" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5663,
"method" : "private/cancel_all_by_currency",
"params" : {
"currency" : "BTC",
"kind" : "option"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5663,
"method" : "private/cancel_all_by_currency",
"params" : {
"currency" : "BTC",
"kind" : "option"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5663,
"result": 3
}
Cancels all orders by currency, optionally filtered by instrument kind and/or order type.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
kind | false | string | future option |
Instrument kind, if not provided instruments of all kinds are considered |
type | false | string | all limit stop |
Order type - limit, stop or all, default - all |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
object | ||
result | number | Total number of successfully cancelled orders |
/private/cancel_all_by_instrument
curl -X GET "https://test.deribit.com/api/v2/private/cancel_all_by_instrument?instrument_name=ETH-22FEB19-120-P&type=all" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 4122,
"method" : "private/cancel_all_by_instrument",
"params" : {
"instrument_name" : "ETH-22FEB19-120-P",
"type" : "all"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 4122,
"method" : "private/cancel_all_by_instrument",
"params" : {
"instrument_name" : "ETH-22FEB19-120-P",
"type" : "all"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 4122,
"result": 7
}
Cancels all orders by instrument, optionally filtered by order type.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
type | false | string | all limit stop |
Order type - limit, stop or all, default - all |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
object | ||
result | number | Total number of successfully cancelled orders |
/private/cancel_by_label
curl -X GET "https://test.deribit.com/api/v2/private/cancel_by_label?label=label" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"id" : 47,
"method" : "private/cancel_by_label",
"params" : {
"label" : "label"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"id" : 47,
"method" : "private/cancel_by_label",
"params" : {
"label" : "label"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc":"2.0",
"id":47,
"result":4
}
Cancels orders by label. All user's orders (stop orders too), with given label are canceled in all currencies
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
label | true | string | user defined label for the order (maximum 64 characters) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
object | ||
result | number | Total number of successfully cancelled orders |
/private/close_position
curl -X GET "https://test.deribit.com/api/v2/private/close_position?instrument_name=ETH-PERPETUAL&price=1.45169999999999987494e%2B02&type=limit" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 6130,
"method" : "private/close_position",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"type" : "limit",
"price" : 145.17
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 6130,
"method" : "private/close_position",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"type" : "limit",
"price" : 145.17
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 6130,
"result": {
"trades": [
{
"trade_seq": 1966068,
"trade_id": "ETH-2696097",
"timestamp": 1590486335742,
"tick_direction": 0,
"state": "filled",
"self_trade": false,
"reduce_only": true,
"price": 202.8,
"post_only": false,
"order_type": "limit",
"order_id": "ETH-584864807",
"matching_id": null,
"mark_price": 202.79,
"liquidity": "T",
"instrument_name": "ETH-PERPETUAL",
"index_price": 202.86,
"fee_currency": "ETH",
"fee": 0.00007766,
"direction": "sell",
"amount": 21
}
],
"order": {
"web": false,
"time_in_force": "good_til_cancelled",
"replaced": false,
"reduce_only": true,
"profit_loss": -0.00025467,
"price": 198.75,
"post_only": false,
"order_type": "limit",
"order_state": "filled",
"order_id": "ETH-584864807",
"max_show": 21,
"last_update_timestamp": 1590486335742,
"label": "",
"is_liquidation": false,
"instrument_name": "ETH-PERPETUAL",
"filled_amount": 21,
"direction": "sell",
"creation_timestamp": 1590486335742,
"commission": 0.00007766,
"average_price": 202.8,
"api": true,
"amount": 21
}
}
}
Makes closing position reduce only order .
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
type | true | string | limit market |
The order type |
price | false | number | Optional price for limit order. |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› order | object | |
› › order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› › max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› › api | boolean | true if created with API |
› › amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › web | boolean | true if created via Deribit frontend (optional) |
› › instrument_name | string | Unique instrument identifier |
› › advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› › triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› › block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› › original_order_type | string | Original order type. Optional field |
› › price | number | Price in base currency |
› › time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› › auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› › stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› › last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › post_only | boolean | true for post-only orders only |
› › replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› › filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › average_price | number | Average fill price of the order |
› › order_id | string | Unique order identifier |
› › reduce_only | boolean | true for reduce-only orders only |
› › commission | number | Commission paid so far (in base currency) |
› › app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› › stop_price | number | Stop price (Only for future stop orders) |
› › label | string | User defined label (up to 64 characters) |
› › creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › direction | string | Direction: buy , or sell |
› › is_liquidation | boolean | true if order was automatically created during liquidation |
› › order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› › usd | number | Option price in USD (Only if advanced="usd" ) |
› › profit_loss | number | Profit and loss in base currency. |
› › implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› › trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_margins
curl -X GET "https://test.deribit.com/api/v2/private/get_margins?amount=10000&instrument_name=BTC-PERPETUAL&price=3725" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7,
"method" : "private/get_margins",
"params" : {
"instrument_name" : "BTC-PERPETUAL",
"amount" : 10000,
"price" : 3725
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7,
"method" : "private/get_margins",
"params" : {
"instrument_name" : "BTC-PERPETUAL",
"amount" : 10000,
"price" : 3725
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this:
{
"jsonrpc": "2.0",
"result": {
"buy": 0.01681367,
"max_price": 42.0,
"min_price": 42.0,
"sell": 0.01680479
}
}
Get margins for given instrument, amount and price.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
amount | true | number | Amount, integer for future, float for option. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. | |
price | true | number | Price |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› buy | number | Margin when buying |
› max_price | number | The maximum price for the future. Any buy orders you submit higher than this price, will be clamped to this maximum. |
› min_price | number | The minimum price for the future. Any sell orders you submit lower than this price will be clamped to this minimum. |
› sell | number | Margin when selling |
/private/get_mmp_config
curl -X GET "https://test.deribit.com/api/v2/private/get_mmp_config?currency=BTC" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/get_mmp_config",
"params" : {
"currency" : "BTC"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/get_mmp_config",
"params" : {
"currency" : "BTC"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7859,
"result": {
"currency": "BTC",
"interval": 60,
"frozen_time": 0,
"quantity_limit": 0.5
}
}
Get current config for MMP
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› delta_limit | number | Delta limit |
› frozen_time | integer | MMP frozen time in seconds, if set to 0 manual reset is required |
› interval | integer | MMP Interval in seconds, if set to 0 MMP is disabled |
› quantity_limit | number | Quantity limit |
/private/get_open_orders_by_currency
curl -X GET "https://test.deribit.com/api/v2/private/get_open_orders_by_currency?currency=BTC" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 1953,
"method" : "private/get_open_orders_by_currency",
"params" : {
"currency" : "BTC"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 1953,
"method" : "private/get_open_orders_by_currency",
"params" : {
"currency" : "BTC"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 1953,
"result": [
{
"time_in_force": "good_til_cancelled",
"reduce_only": false,
"profit_loss": 0,
"price": 0.0028,
"post_only": false,
"order_type": "limit",
"order_state": "open",
"order_id": "146062",
"max_show": 10,
"last_update_timestamp": 1550050597036,
"label": "",
"is_liquidation": false,
"instrument_name": "BTC-15FEB19-3250-P",
"filled_amount": 0,
"direction": "buy",
"creation_timestamp": 1550050597036,
"commission": 0,
"average_price": 0,
"api": true,
"amount": 10
}
]
}
Retrieves list of user's open orders.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
kind | false | string | future option |
Instrument kind, if not provided instruments of all kinds are considered |
type | false | string | all limit stop_all stop_limit stop_market |
Order type, default - all |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› api | boolean | true if created with API |
› amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› web | boolean | true if created via Deribit frontend (optional) |
› instrument_name | string | Unique instrument identifier |
› advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› original_order_type | string | Original order type. Optional field |
› price | number | Price in base currency |
› time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› post_only | boolean | true for post-only orders only |
› replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› average_price | number | Average fill price of the order |
› order_id | string | Unique order identifier |
› reduce_only | boolean | true for reduce-only orders only |
› commission | number | Commission paid so far (in base currency) |
› app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› stop_price | number | Stop price (Only for future stop orders) |
› label | string | User defined label (up to 64 characters) |
› creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› direction | string | Direction: buy , or sell |
› is_liquidation | boolean | true if order was automatically created during liquidation |
› order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› usd | number | Option price in USD (Only if advanced="usd" ) |
› profit_loss | number | Profit and loss in base currency. |
› implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/get_open_orders_by_instrument
curl -X GET "https://test.deribit.com/api/v2/private/get_open_orders_by_instrument?instrument_name=ETH-22FEB19-120-C" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8442,
"method" : "private/get_open_orders_by_instrument",
"params" : {
"instrument_name" : "ETH-22FEB19-120-C"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8442,
"method" : "private/get_open_orders_by_instrument",
"params" : {
"instrument_name" : "ETH-22FEB19-120-C"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 8442,
"result": [
{
"time_in_force": "good_til_cancelled",
"reduce_only": false,
"profit_loss": 0,
"price": 0.135,
"post_only": false,
"order_type": "limit",
"order_state": "open",
"order_id": "ETH-252017",
"max_show": 10,
"last_update_timestamp": 1550050594882,
"label": "",
"is_liquidation": false,
"instrument_name": "ETH-22FEB19-120-C",
"filled_amount": 0,
"direction": "sell",
"creation_timestamp": 1550050594882,
"commission": 0,
"average_price": 0,
"api": true,
"amount": 10
}
]
}
Retrieves list of user's open orders within given Instrument.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
type | false | string | all limit stop_all stop_limit stop_market |
Order type, default - all |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› api | boolean | true if created with API |
› amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› web | boolean | true if created via Deribit frontend (optional) |
› instrument_name | string | Unique instrument identifier |
› advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› original_order_type | string | Original order type. Optional field |
› price | number | Price in base currency |
› time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› post_only | boolean | true for post-only orders only |
› replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› average_price | number | Average fill price of the order |
› order_id | string | Unique order identifier |
› reduce_only | boolean | true for reduce-only orders only |
› commission | number | Commission paid so far (in base currency) |
› app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› stop_price | number | Stop price (Only for future stop orders) |
› label | string | User defined label (up to 64 characters) |
› creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› direction | string | Direction: buy , or sell |
› is_liquidation | boolean | true if order was automatically created during liquidation |
› order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› usd | number | Option price in USD (Only if advanced="usd" ) |
› profit_loss | number | Profit and loss in base currency. |
› implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/get_order_history_by_currency
curl -X GET "https://test.deribit.com/api/v2/private/get_order_history_by_currency?count=1¤cy=BTC&kind=future" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9305,
"method" : "private/get_order_history_by_currency",
"params" : {
"currency" : "BTC",
"kind" : "future",
"count" : 1
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9305,
"method" : "private/get_order_history_by_currency",
"params" : {
"currency" : "BTC",
"kind" : "future",
"count" : 1
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9305,
"result": [
{
"time_in_force": "good_til_cancelled",
"reduce_only": false,
"profit_loss": 0,
"price": 3886.5,
"post_only": false,
"order_type": "limit",
"order_state": "filled",
"order_id": "146475",
"max_show": 40,
"last_update_timestamp": 1550661808761,
"label": "",
"is_liquidation": false,
"instrument_name": "BTC-PERPETUAL",
"filled_amount": 40,
"direction": "buy",
"creation_timestamp": 1550661808761,
"commission": 0.00000547,
"average_price": 3659.8,
"api": true,
"amount": 40
}
]
}
Retrieves history of orders that have been partially or fully filled.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
kind | false | string | future option |
Instrument kind, if not provided instruments of all kinds are considered |
count | false | integer | Number of requested items, default - 20 |
|
offset | false | integer | The offset for pagination, default - 0 |
|
include_old | false | boolean | Include in result orders older than 2 days, default - false |
|
include_unfilled | false | boolean | Include in result fully unfilled closed orders, default - false |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› api | boolean | true if created with API |
› amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› web | boolean | true if created via Deribit frontend (optional) |
› instrument_name | string | Unique instrument identifier |
› advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› original_order_type | string | Original order type. Optional field |
› price | number | Price in base currency |
› time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› post_only | boolean | true for post-only orders only |
› replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› average_price | number | Average fill price of the order |
› order_id | string | Unique order identifier |
› reduce_only | boolean | true for reduce-only orders only |
› commission | number | Commission paid so far (in base currency) |
› app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› stop_price | number | Stop price (Only for future stop orders) |
› label | string | User defined label (up to 64 characters) |
› creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› direction | string | Direction: buy , or sell |
› is_liquidation | boolean | true if order was automatically created during liquidation |
› order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› usd | number | Option price in USD (Only if advanced="usd" ) |
› profit_loss | number | Profit and loss in base currency. |
› implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/get_order_history_by_instrument
curl -X GET "https://test.deribit.com/api/v2/private/get_order_history_by_instrument?count=1&instrument_name=BTC-PERPETUAL" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 1032,
"method" : "private/get_order_history_by_instrument",
"params" : {
"instrument_name" : "BTC-PERPETUAL",
"count" : 1
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 1032,
"method" : "private/get_order_history_by_instrument",
"params" : {
"instrument_name" : "BTC-PERPETUAL",
"count" : 1
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 1032,
"result": [
{
"time_in_force": "good_til_cancelled",
"reduce_only": false,
"profit_loss": 0,
"price": 3886.5,
"post_only": false,
"order_type": "limit",
"order_state": "filled",
"order_id": "146475",
"max_show": 40,
"last_update_timestamp": 1550661808761,
"label": "",
"is_liquidation": false,
"instrument_name": "BTC-PERPETUAL",
"filled_amount": 40,
"direction": "buy",
"creation_timestamp": 1550661808761,
"commission": 0.00000547,
"average_price": 3659.8,
"api": true,
"amount": 40
}
]
}
Retrieves history of orders that have been partially or fully filled.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
count | false | integer | Number of requested items, default - 20 |
|
offset | false | integer | The offset for pagination, default - 0 |
|
include_old | false | boolean | Include in result orders older than 2 days, default - false |
|
include_unfilled | false | boolean | Include in result fully unfilled closed orders, default - false |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› api | boolean | true if created with API |
› amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› web | boolean | true if created via Deribit frontend (optional) |
› instrument_name | string | Unique instrument identifier |
› advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› original_order_type | string | Original order type. Optional field |
› price | number | Price in base currency |
› time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› post_only | boolean | true for post-only orders only |
› replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› average_price | number | Average fill price of the order |
› order_id | string | Unique order identifier |
› reduce_only | boolean | true for reduce-only orders only |
› commission | number | Commission paid so far (in base currency) |
› app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› stop_price | number | Stop price (Only for future stop orders) |
› label | string | User defined label (up to 64 characters) |
› creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› direction | string | Direction: buy , or sell |
› is_liquidation | boolean | true if order was automatically created during liquidation |
› order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› usd | number | Option price in USD (Only if advanced="usd" ) |
› profit_loss | number | Profit and loss in base currency. |
› implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/get_order_margin_by_ids
curl -X GET "https://test.deribit.com/api/v2/private/get_order_margin_by_ids?ids=%5B%22ETH-349280%22%2C%22ETH-349279%22%2C%22ETH-349278%22%5D" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5625,
"method" : "private/get_order_margin_by_ids",
"params" : {
"ids" : [
"ETH-349280",
"ETH-349279",
"ETH-349278"
]
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5625,
"method" : "private/get_order_margin_by_ids",
"params" : {
"ids" : [
"ETH-349280",
"ETH-349279",
"ETH-349278"
]
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5625,
"result": [
{
"order_id": "ETH-349278",
"initial_margin": 0.00091156
},
{
"order_id": "ETH-349279",
"initial_margin": 0
},
{
"order_id": "ETH-349280",
"initial_margin": 0
}
]
}
Retrieves initial margins of given orders
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
ids | true | array | Ids of orders |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | array of object | |
› initial_margin | number | Initial margin of order, in base currency |
› order_id | string | Unique order identifier |
/private/get_order_state
curl -X GET "https://test.deribit.com/api/v2/private/get_order_state?order_id=ETH-331562" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 4316,
"method" : "private/get_order_state",
"params" : {
"order_id" : "ETH-331562"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 4316,
"method" : "private/get_order_state",
"params" : {
"order_id" : "ETH-331562"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 4316,
"result": {
"time_in_force": "good_til_cancelled",
"reduce_only": false,
"profit_loss": 0.051134,
"price": 118.94,
"post_only": false,
"order_type": "limit",
"order_state": "filled",
"order_id": "ETH-331562",
"max_show": 37,
"last_update_timestamp": 1550219810944,
"label": "",
"is_liquidation": false,
"instrument_name": "ETH-PERPETUAL",
"filled_amount": 37,
"direction": "sell",
"creation_timestamp": 1550219749176,
"commission": 0.000031,
"average_price": 118.94,
"api": false,
"amount": 37
}
}
Retrieve the current state of an order.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
order_id | true | string | The order id |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› order_state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" |
› max_show | number | Maximum amount within an order to be shown to other traders, 0 for invisible order. |
› api | boolean | true if created with API |
› amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› web | boolean | true if created via Deribit frontend (optional) |
› instrument_name | string | Unique instrument identifier |
› advanced | string | advanced type: "usd" or "implv" (Only for options; field is omitted if not applicable). |
› triggered | boolean | Whether the stop order has been triggered (Only for stop orders) |
› block_trade | boolean | true if order made from block_trade trade, added only in that case. |
› original_order_type | string | Original order type. Optional field |
› price | number | Price in base currency |
› time_in_force | string | Order time in force: "good_til_cancelled" , "fill_or_kill" , "immediate_or_cancel" |
› auto_replaced | boolean | Options, advanced orders only - true if last modification of the order was performed by the pricing engine, otherwise false . |
› stop_order_id | string | Id of the stop order that was triggered to create the order (Only for orders that were created by triggered stop orders). |
› last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› post_only | boolean | true for post-only orders only |
› replaced | boolean | true if the order was edited (by user or - in case of advanced options orders - by pricing engine), otherwise false . |
› filled_amount | number | Filled amount of the order. For perpetual and futures the filled_amount is in USD units, for options - in units or corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› average_price | number | Average fill price of the order |
› order_id | string | Unique order identifier |
› reduce_only | boolean | true for reduce-only orders only |
› commission | number | Commission paid so far (in base currency) |
› app_name | string | Name of the application that placed the order on behalf of the user (optional). |
› stop_price | number | Stop price (Only for future stop orders) |
› label | string | User defined label (up to 64 characters) |
› creation_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› direction | string | Direction: buy , or sell |
› is_liquidation | boolean | true if order was automatically created during liquidation |
› order_type | string | Order type: "limit" , "market" , "stop_limit" , "stop_market" |
› usd | number | Option price in USD (Only if advanced="usd" ) |
› profit_loss | number | Profit and loss in base currency. |
› implv | number | Implied volatility in percent. (Only if advanced="implv" ) |
› trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/get_stop_order_history
curl -X GET "https://test.deribit.com/api/v2/private/get_stop_order_history?count=10¤cy=ETH" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2552,
"method" : "private/get_stop_order_history",
"params" : {
"currency" : "ETH",
"count" : 10
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2552,
"method" : "private/get_stop_order_history",
"params" : {
"currency" : "ETH",
"count" : 10
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2192,
"result": [
{
"trigger": "index",
"timestamp": 1555918941451,
"stop_price": 5285,
"stop_id": "SLIS-103",
"order_state": "new",
"request": "trigger:order",
"price": 5179.28,
"order_id": "671473",
"offset": 277,
"instrument_name": "BTC-PERPETUAL",
"amount": 10,
"direction": "buy"
}
]
}
Retrieves detailed log of the user's stop-orders.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
instrument_name | false | string | Instrument name | |
count | false | integer | Number of requested items, default - 20 |
|
continuation | false | string | Continuation token for pagination |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› continuation | string | Continuation token for pagination. |
› entries | array of object | |
› › amount | number | It represents the requested order size. For perpetual and futures the amount is in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › direction | string | Direction: buy , or sell |
› › instrument_name | string | Unique instrument identifier |
› › label | string | User defined label (presented only when previously set for order by user) |
› › last_update_timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › order_id | string | Unique order identifier |
› › order_state | string | Order state: "triggered" , "cancelled" , or "rejected" with rejection reason (e.g. "rejected:reduce_direction" ). |
› › order_type | string | Requested order type: "limit or "market" |
› › post_only | boolean | true for post-only orders only |
› › price | number | Price in base currency |
› › reduce_only | boolean | true for reduce-only orders only |
› › request | string | Type of last request performed on the stop order by user or system. "cancel" - when order was cancelled, "trigger:order" - when stop order spawned market or limit order after being triggered |
› › stop_id | string | Id of the user stop-order used for the stop-order reference before triggering |
› › stop_price | number | Stop price (Only for future stop orders) |
› › timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › trigger | string | Trigger type (Only for stop orders). Allowed values: "index_price" , "mark_price" , "last_price" . |
/private/get_user_trades_by_currency
curl -X GET "https://test.deribit.com/api/v2/private/get_user_trades_by_currency?count=2¤cy=ETH&start_id=ETH-34066" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9367,
"method" : "private/get_user_trades_by_currency",
"params" : {
"currency" : "ETH",
"start_id" : "ETH-34066",
"count" : 2
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9367,
"method" : "private/get_user_trades_by_currency",
"params" : {
"currency" : "ETH",
"start_id" : "ETH-34066",
"count" : 2
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9367,
"result": {
"trades": [
{
"underlying_price": 204.5,
"trade_seq": 3,
"trade_id": "ETH-2696060",
"timestamp": 1590480363130,
"tick_direction": 2,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 0.361,
"post_only": false,
"order_type": "limit",
"order_id": "ETH-584827850",
"matching_id": null,
"mark_price": 0.364585,
"liquidity": "T",
"iv": 0,
"instrument_name": "ETH-29MAY20-130-C",
"index_price": 203.72,
"fee_currency": "ETH",
"fee": 0.002,
"direction": "sell",
"amount": 5
},
{
"underlying_price": 204.82,
"trade_seq": 3,
"trade_id": "ETH-2696062",
"timestamp": 1590480416119,
"tick_direction": 0,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 0.015,
"post_only": false,
"order_type": "limit",
"order_id": "ETH-584828229",
"matching_id": null,
"mark_price": 0.000596,
"liquidity": "T",
"iv": 352.91,
"instrument_name": "ETH-29MAY20-140-P",
"index_price": 204.06,
"fee_currency": "ETH",
"fee": 0.002,
"direction": "buy",
"amount": 5
}
],
"has_more": true
}
}
Retrieve the latest user trades that have occurred for instruments in a specific currency symbol.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
kind | false | string | future option |
Instrument kind, if not provided instruments of all kinds are considered |
start_id | false | string | The ID number of the first trade to be returned | |
end_id | false | string | The ID number of the last trade to be returned | |
count | false | integer | Number of requested items, default - 10 |
|
include_old | false | boolean | Include trades older than a few recent days, default - false |
|
sorting | false | string | asc desc default |
Direction of results sorting (default value means no sorting, results will be returned in order in which they left the database) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› has_more | boolean | |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_user_trades_by_currency_and_time
curl -X GET "https://test.deribit.com/api/v2/private/get_user_trades_by_currency_and_time?count=2¤cy=BTC&end_timestamp=1510480630731&start_timestamp=1590480630731" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9292,
"method" : "private/get_user_trades_by_currency_and_time",
"params" : {
"currency" : "BTC",
"start_timestamp" : 1590480630731,
"end_timestamp" : 1510480630731,
"count" : 2
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 9292,
"method" : "private/get_user_trades_by_currency_and_time",
"params" : {
"currency" : "BTC",
"start_timestamp" : 1590480630731,
"end_timestamp" : 1510480630731,
"count" : 2
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 9292,
"result": {
"trades": [
{
"underlying_price": 8994.95,
"trade_seq": 1,
"trade_id": "48078936",
"timestamp": 1590480620145,
"tick_direction": 1,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 0.028,
"post_only": false,
"order_type": "limit",
"order_id": "4008699030",
"matching_id": null,
"mark_price": 0.03135383,
"liquidity": "M",
"iv": 38.51,
"instrument_name": "BTC-27MAY20-8750-C",
"index_price": 8993.47,
"fee_currency": "BTC",
"fee": 0.0004,
"direction": "sell",
"amount": 1
},
{
"trade_seq": 299513,
"trade_id": "47958936",
"timestamp": 1589923311862,
"tick_direction": 2,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 9681.5,
"post_only": false,
"order_type": "limit",
"order_id": "3993343822",
"matching_id": null,
"mark_price": 9684,
"liquidity": "M",
"instrument_name": "BTC-26JUN20",
"index_price": 9679.48,
"fee_currency": "BTC",
"fee": -2.1e-7,
"direction": "buy",
"amount": 10
}
],
"has_more": false
}
}
Retrieve the latest user trades that have occurred for instruments in a specific currency symbol and within given time range.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
kind | false | string | future option |
Instrument kind, if not provided instruments of all kinds are considered |
start_timestamp | true | integer | The earliest timestamp to return result for | |
end_timestamp | true | integer | The most recent timestamp to return result for | |
count | false | integer | Number of requested items, default - 10 |
|
include_old | false | boolean | Include trades older than a few recent days, default - false |
|
sorting | false | string | asc desc default |
Direction of results sorting (default value means no sorting, results will be returned in order in which they left the database) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› has_more | boolean | |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_user_trades_by_instrument
curl -X GET "https://test.deribit.com/api/v2/private/get_user_trades_by_instrument?count=2&instrument_name=ETH-PERPETUAL&start_seq=1966042" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 5728,
"method" : "private/get_user_trades_by_instrument",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"start_seq" : 1966042,
"count" : 2
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 5728,
"method" : "private/get_user_trades_by_instrument",
"params" : {
"instrument_name" : "ETH-PERPETUAL",
"start_seq" : 1966042,
"count" : 2
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 5728,
"result": {
"trades": [
{
"trade_seq": 1966042,
"trade_id": "ETH-2696068",
"timestamp": 1590480712800,
"tick_direction": 3,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 203.8,
"post_only": false,
"order_type": "market",
"order_id": "ETH-584830574",
"matching_id": null,
"mark_price": 203.78,
"liquidity": "T",
"instrument_name": "ETH-PERPETUAL",
"index_price": 203.89,
"fee_currency": "ETH",
"fee": 0.00036801,
"direction": "buy",
"amount": 100
},
{
"trade_seq": 1966043,
"trade_id": "ETH-2696069",
"timestamp": 1590480724473,
"tick_direction": 3,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 203.8,
"post_only": false,
"order_type": "market",
"order_id": "ETH-584830695",
"matching_id": null,
"mark_price": 203.81,
"liquidity": "T",
"instrument_name": "ETH-PERPETUAL",
"index_price": 203.92,
"fee_currency": "ETH",
"fee": 0.00036801,
"direction": "sell",
"amount": 100
}
],
"has_more": true
}
}
Retrieve the latest user trades that have occurred for a specific instrument.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
start_seq | false | integer | The sequence number of the first trade to be returned | |
end_seq | false | integer | The sequence number of the last trade to be returned | |
count | false | integer | Number of requested items, default - 10 |
|
include_old | false | boolean | Include trades older than a few recent days, default - false |
|
sorting | false | string | asc desc default |
Direction of results sorting (default value means no sorting, results will be returned in order in which they left the database) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› has_more | boolean | |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_user_trades_by_instrument_and_time
curl -X GET "https://test.deribit.com/api/v2/private/get_user_trades_by_instrument_and_time?count=2&end_timestamp=1590480872894&instrument_name=BTC-PERPETUAL&start_timestamp=1590470872894" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 276,
"method" : "private/get_user_trades_by_instrument_and_time",
"params" : {
"instrument_name" : "BTC-PERPETUAL",
"start_timestamp" : 1590470872894,
"end_timestamp" : 1590480872894,
"count" : 2
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 276,
"method" : "private/get_user_trades_by_instrument_and_time",
"params" : {
"instrument_name" : "BTC-PERPETUAL",
"start_timestamp" : 1590470872894,
"end_timestamp" : 1590480872894,
"count" : 2
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 276,
"result": {
"trades": [
{
"trade_seq": 30289127,
"trade_id": "48078944",
"timestamp": 1590480866924,
"tick_direction": 2,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 8988.5,
"post_only": false,
"order_type": "limit",
"order_id": "4008716877",
"matching_id": null,
"mark_price": 8990.52,
"liquidity": "T",
"instrument_name": "BTC-PERPETUAL",
"index_price": 8995.15,
"fee_currency": "BTC",
"fee": 0.00037465,
"direction": "sell",
"amount": 4490
},
{
"trade_seq": 30289128,
"trade_id": "48078945",
"timestamp": 1590480866924,
"tick_direction": 2,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 8983.5,
"post_only": false,
"order_type": "limit",
"order_id": "4008716877",
"matching_id": null,
"mark_price": 8990.52,
"liquidity": "T",
"instrument_name": "BTC-PERPETUAL",
"index_price": 8995.15,
"fee_currency": "BTC",
"fee": 0.00001503,
"direction": "sell",
"amount": 180
}
],
"has_more": true
}
}
Retrieve the latest user trades that have occurred for a specific instrument and within given time range.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
start_timestamp | true | integer | The earliest timestamp to return result for | |
end_timestamp | true | integer | The most recent timestamp to return result for | |
count | false | integer | Number of requested items, default - 10 |
|
include_old | false | boolean | Include trades older than a few recent days, default - false |
|
sorting | false | string | asc desc default |
Direction of results sorting (default value means no sorting, results will be returned in order in which they left the database) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› has_more | boolean | |
› trades | array of object | |
› › amount | number | Trade amount. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. |
› › block_trade_id | string | Block trade id - when trade was part of block trade |
› › direction | string | Direction: buy , or sell |
› › fee | number | User's fee in units of the specified fee_currency |
› › fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
› › index_price | number | Index Price at the moment of trade |
› › instrument_name | string | Unique instrument identifier |
› › iv | number | Option implied volatility for the price (Option only) |
› › label | string | User defined label (presented only when previously set for order by user) |
› › liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
› › liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
› › mark_price | number | Mark Price at the moment of trade |
› › matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
› › order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
› › order_type | string | Order type: "limit , "market" , or "liquidation" |
› › post_only | string | true if user order is post-only |
› › price | number | Price in base currency |
› › profit_loss | number | Profit and loss in base currency. |
› › reduce_only | string | true if user order is reduce-only |
› › self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
› › state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
› › tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
› › timestamp | integer | The timestamp of the trade |
› › trade_id | string | Unique (per currency) trade identifier |
› › trade_seq | integer | The sequence number of the trade within instrument |
› › underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/get_user_trades_by_order
curl -X GET "https://test.deribit.com/api/v2/private/get_user_trades_by_order?order_id=ETH-584830574" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 3466,
"method" : "private/get_user_trades_by_order",
"params" : {
"order_id" : "ETH-584830574"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 3466,
"method" : "private/get_user_trades_by_order",
"params" : {
"order_id" : "ETH-584830574"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 3466,
"result": [
{
"trade_seq": 1966042,
"trade_id": "ETH-2696068",
"timestamp": 1590480712800,
"tick_direction": 3,
"state": "filled",
"self_trade": false,
"reduce_only": false,
"price": 203.8,
"post_only": false,
"order_type": "market",
"order_id": "ETH-584830574",
"matching_id": null,
"mark_price": 203.78,
"liquidity": "T",
"instrument_name": "ETH-PERPETUAL",
"index_price": 203.89,
"fee_currency": "ETH",
"fee": 0.00036801,
"direction": "buy",
"amount": 100
}
]
}
Retrieve the list of user trades that was created for given order
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
order_id | true | string | The order id | |
sorting | false | string | asc desc default |
Direction of results sorting (default value means no sorting, results will be returned in order in which they left the database) |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
array of | amount | number |
block_trade_id | string | Block trade id - when trade was part of block trade |
direction | string | Direction: buy , or sell |
fee | number | User's fee in units of the specified fee_currency |
fee_currency | string | Currency, i.e "BTC" , "ETH" , "USDT" |
index_price | number | Index Price at the moment of trade |
instrument_name | string | Unique instrument identifier |
iv | number | Option implied volatility for the price (Option only) |
label | string | User defined label (presented only when previously set for order by user) |
liquidation | string | Optional field (only for trades caused by liquidation): "M" when maker side of trade was under liquidation, "T" when taker side was under liquidation, "MT" when both sides of trade were under liquidation |
liquidity | string | Describes what was role of users order: "M" when it was maker order, "T" when it was taker order |
mark_price | number | Mark Price at the moment of trade |
matching_id | string | Always null , except for a self-trade which is possible only if self-trading is switched on for the account (in that case this will be id of the maker order of the subscriber) |
order_id | string | Id of the user order (maker or taker), i.e. subscriber's order id that took part in the trade |
order_type | string | Order type: "limit , "market" , or "liquidation" |
post_only | string | true if user order is post-only |
price | number | Price in base currency |
profit_loss | number | Profit and loss in base currency. |
reduce_only | string | true if user order is reduce-only |
self_trade | boolean | true if the trade is against own order. This can only happen when your account has self-trading enabled. Contact an administrator if you think you need that |
state | string | Order state: "open" , "filled" , "rejected" , "cancelled" , "untriggered" or "archive" (if order was archived) |
tick_direction | integer | Direction of the "tick" (0 = Plus Tick, 1 = Zero-Plus Tick, 2 = Minus Tick, 3 = Zero-Minus Tick). |
timestamp | integer | The timestamp of the trade |
trade_id | string | Unique (per currency) trade identifier |
trade_seq | integer | The sequence number of the trade within instrument |
underlying_price | number | Underlying price for implied volatility calculations (Options only) |
/private/reset_mmp
curl -X GET "https://test.deribit.com/api/v2/private/reset_mmp?currency=BTC" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/reset_mmp",
"params" : {
"currency" : "BTC"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/reset_mmp",
"params" : {
"currency" : "BTC"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7859,
"result": "ok"
}
Reset MMP
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/set_mmp_config
curl -X GET "https://test.deribit.com/api/v2/private/set_mmp_config?currency=BTC&frozen_time=0&interval=60&quantity_limit=3.00000000000000000000e%2B00" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/set_mmp_config",
"params" : {
"currency" : "BTC",
"interval" : 60,
"frozen_time" : 0,
"quantity_limit" : 3.0
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 7859,
"method" : "private/set_mmp_config",
"params" : {
"currency" : "BTC",
"interval" : 60,
"frozen_time" : 0,
"quantity_limit" : 3.0
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 7859,
"result": "ok"
}
Set config for MMP - triggers MMP reset
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
interval | true | integer | MMP Interval in seconds, if set to 0 MMP is disabled | |
frozen_time | true | integer | MMP frozen time in seconds, if set to 0 manual reset is required | |
quantity_limit | false | number | Quantity limit | |
delta_limit | false | number | Delta limit |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | string | Result of method execution. ok in case of success |
/private/get_settlement_history_by_instrument
curl -X GET "https://test.deribit.com/api/v2/private/get_settlement_history_by_instrument?count=1&instrument_name=ETH-22FEB19&type=settlement" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 2192,
"method" : "private/get_settlement_history_by_instrument",
"params" : {
"instrument_name" : "ETH-22FEB19",
"type" : "settlement",
"count" : 1
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 2192,
"method" : "private/get_settlement_history_by_instrument",
"params" : {
"instrument_name" : "ETH-22FEB19",
"type" : "settlement",
"count" : 1
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 2192,
"result": {
"settlements": [
{
"type": "settlement",
"timestamp": 1550475692526,
"session_profit_loss": 0.038358299,
"profit_loss": -0.001783937,
"position": -66,
"mark_price": 121.67,
"instrument_name": "ETH-22FEB19",
"index_price": 119.8
}
],
"continuation": "xY7T6cusbMBNpH9SNmKb94jXSBxUPojJEdCPL4YociHBUgAhWQvEP"
}
}
Retrieves public settlement, delivery and bankruptcy events filtered by instrument name
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
instrument_name | true | string | Instrument name | |
type | false | string | settlement delivery bankruptcy |
Settlement type |
count | false | integer | Number of requested items, default - 20 |
|
continuation | false | string | Continuation token for pagination | |
search_start_timestamp | false | integer | The latest timestamp to return result for |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› continuation | string | Continuation token for pagination. |
› settlements | array of object | |
› › funded | number | funded amount (bankruptcy only) |
› › funding | number | funding (in base currency ; settlement for perpetual product only) |
› › index_price | number | underlying index price at time of event (in quote currency; settlement and delivery only) |
› › instrument_name | string | instrument name (settlement and delivery only) |
› › mark_price | number | mark price for at the settlement time (in quote currency; settlement and delivery only) |
› › position | number | position size (in quote currency; settlement and delivery only) |
› › profit_loss | number | profit and loss (in base currency; settlement and delivery only) |
› › session_bankrupcy | number | value of session bankrupcy (in base currency; bankruptcy only) |
› › session_profit_loss | number | total value of session profit and losses (in base currency) |
› › session_tax | number | total amount of paid taxes/fees (in base currency; bankruptcy only) |
› › session_tax_rate | number | rate of paid texes/fees (in base currency; bankruptcy only) |
› › socialized | number | the amount of the socialized losses (in base currency; bankruptcy only) |
› › timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › type | string | The type of settlement. settlement , delivery or bankruptcy . |
/private/get_settlement_history_by_currency
curl -X GET "https://test.deribit.com/api/v2/private/get_settlement_history_by_currency?count=1¤cy=BTC&type=delivery" \
-H "Authorization: Bearer 1529453804065.h2QrBgvn.oS36pCOmuK9EX7954lzCSkUioEtTMg7F5ShToM0ZfYlqU05OquXkQIe2_DDEkPhzmoPp1fBp0ycXShR_0jf-SMSXEdVqxLRWuOw-_StG5BMjToiAl27CbHY4P92MPhlMblTOtTImE81-5dFdyDVydpBwmlfKM3OSQ39kulP9bbfw-2jhyegOL0AgqJTY_tj554oHCQFTbq0A0ZWukukmxL2yu6iy34XdzaJB26Igy-3UxGBMwFu53EhjKBweh7xyP2nDm57-wybndJMtSyTGDXH3vjBVclo1iup5yRP" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 8304,
"method" : "private/get_settlement_history_by_currency",
"params" : {
"currency" : "BTC",
"type" : "delivery",
"count" : 1
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response...
console.log('received from server : ', e.data);
};
ws.onopen = function () {
// -------------------
// Before sending message, make sure that your connection
// is authenticated (use public/auth call before)
// -------------------
ws.send(JSON.stringify(msg));
};
import asyncio
import websockets
import json
msg = \
{
"jsonrpc" : "2.0",
"id" : 8304,
"method" : "private/get_settlement_history_by_currency",
"params" : {
"currency" : "BTC",
"type" : "delivery",
"count" : 1
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
###############
# Before sending message, make sure that your connection
# is authenticated (use public/auth call before)
###############
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))
The above command returns JSON structured like this (real example):
{
"jsonrpc": "2.0",
"id": 6074,
"result": {
"settlements": [
{
"type": "delivery",
"timestamp": 1550242800013,
"session_profit_loss": 1.567969302,
"profit_loss": -0.251617338,
"position": 13,
"mark_price": 0.121679828,
"instrument_name": "BTC-15FEB19-4000-P",
"index_price": 3566.08
}
],
"continuation": "AHmpC39UH5EeGVjryrf731YEhjL16oqCQorSvBFZFAbbwvCN7GCbMFgno7U5JKW"
}
}
Retrieves settlement, delivery and bankruptcy events that have affected your account.
Parameters
Parameter | Required | Type | Enum | Description |
---|---|---|---|---|
currency | true | string | BTC ETH USDT |
The currency symbol |
type | false | string | settlement delivery bankruptcy |
Settlement type |
count | false | integer | Number of requested items, default - 20 |
|
continuation | false | string | Continuation token for pagination | |
search_start_timestamp | false | integer | The latest timestamp to return result for |
Response
Name | Type | Description |
---|---|---|
id | integer | The id that was sent in the request |
jsonrpc | string | The JSON-RPC version (2.0) |
result | object | |
› continuation | string | Continuation token for pagination. |
› settlements | array of object | |
› › funded | number | funded amount (bankruptcy only) |
› › funding | number | funding (in base currency ; settlement for perpetual product only) |
› › index_price | number | underlying index price at time of event (in quote currency; settlement and delivery only) |
› › instrument_name | string | instrument name (settlement and delivery only) |
› › mark_price | number | mark price for at the settlement time (in quote currency; settlement and delivery only) |
› › position | number | position size (in quote currency; settlement and delivery only) |
› › profit_loss | number | profit and loss (in base currency; settlement and delivery only) |
› › session_bankrupcy | number | value of session bankrupcy (in base currency; bankruptcy only) |
› › session_profit_loss | number | total value of session profit and losses (in base currency) |
› › session_tax | number | total amount of paid taxes/fees (in base currency; bankruptcy only) |
› › session_tax_rate | number | rate of paid texes/fees (in base currency; bankruptcy only) |
› › socialized | number | the amount of the socialized losses (in base currency; bankruptcy only) |
› › timestamp | integer | The timestamp (milliseconds since the Unix epoch) |
› › type | string | The type of settlement. settlement , delivery or bankruptcy . |
Market data
/public/get_book_summary_by_currency
curl -X GET "https://test.deribit.com/api/v2/public/get_book_summary_by_currency?currency=BTC&kind=future" \
-H "Content-Type: application/json"
var msg =
{
"jsonrpc" : "2.0",
"id" : 9344,
"method" : "public/get_book_summary_by_currency",
"params" : {
"currency" : "BTC",
"kind" : "future"
}
};
var ws = new WebSocket('wss://test.deribit.com/ws/api/v2');
ws.onmessage = function (e) {
// do something with the response.