NAV Navbar
Python Shell Ruby

Introduction

Welcome to the Delta Exchange API! You can use this API to place orders on Delta Exchange and listen to market feed.

We have language bindings in Shell, Python, Ruby and Nodejs! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.

Authentication

Api endpoints that place orders or fetch account related information needs to authenticated using api key and api secret.

Generating an API Key

Before being able to sign any requests, you must create an API key via the Delta website. Upon creating a key you will receive api key and api secret, which you must remember and secure at your end. The Key and Secret will be randomly generated.

API Key Permissions

You can restrict the functionality of API keys. Before creating the key, you must choose what permissions you would like the key to have. The permissions are:

Creating a Request

All Authenticated requests must contain the following headers:

api-key: The api key as a string. signature: The base64-encoded signature (see Signing a Message). timestamp: A timestamp for your request.

All request bodies should have content type application/json and be valid JSON.

Signing a Message

The signature header is generated by creating a sha256 HMAC using the secret key on the prehash string method + timestamp + requestPath + query params + body (where + represents string concatenation) and convert output to hexdigest. The timestamp value is the same as the 'timestamp' header.

Code samples


# GET /orders
# queryString: product_id=1&state=open

# Generating signature:
echo -n "GET1542110948/orders?product_id=1&state=open" | openssl dgst -sha256 -hmac "7b6f39dcf660ec1c7c664f612c60410a2bd0c258416b498bf0311f94228f"

# Sample Request:
# Url:
#  /orders?product_id=1&state=open
# Headers:
#  signature: ad767fead0bdbe91ba1e4feb142079245fecd66aa5e47a70b40ba1a4c9b4e3db
#  api-key: a207900b7693435a8fa9230a38195d
  #timestamp: 1542110948

import hashlib
import hmac
import base64
import requests

api_key = 'a207900b7693435a8fa9230a38195d'
api_secret = '7b6f39dcf660ec1c7c664f612c60410a2bd0c258416b498bf0311f94228f'

def generate_signature(secret, message):
    message = bytes(message, 'utf-8')
    secret = bytes(secret, 'utf-8')
    hash = hmac.new(secret, message, hashlib.sha256)
    return hash.hexdigest()

def get_time_stamp():
    d = datetime.datetime.utcnow()
    epoch = datetime.datetime(1970,1,1)
    return str(int((d - epoch).total_seconds()))

# Get open orders
method = 'GET'
timestamp = get_time_stamp()
path = '/orders'
query = '?product_id=1&state=open'
signature_data = method + timestamp + path + query + payload
signature = generate_signature(api_secret, signature_data)
req_headers = {
  'api-key': api_key,
  'timestamp': timestamp,
  'signature': signature,
  'User-Agent': 'rest-client',
  'Content-Type': 'application/json'
}

# Place new order
method = 'POST'
timestamp = get_time_stamp()
path = '/orders'
query = ''
payload = "{\"order_type\":\"limit_order\",\"size\":3,\"side\":\"buy\",\"limit_price\":\"0.0005\",\"product_id\":1}"

signature = generate_signature(api_secret, signature_data)
req_headers = {
  'api-key': api_key,
  'timestamp': timestamp,
  'signature': signature,
  'User-Agent': 'rest-client',
  'Content-Type': 'application/json'
}

Rate Limits

When a rate limit is exceeded, a status of 429 Too Many Requests will be returned.

REST API

Limits

We throttle unauthenticated api requests by IP and authenticated requests by user ID. These are the limits for different categories of requests in a 5 minute rolling window.

Request Type Limit Description
Chart data 600 Requests for chart data
Public read requests 200 Requests to get list of live products, L2 orderbook etc
Private read requests 200 Requests to get open orders, fills, positions etc
Private write requests 150 Requests to place orders, change leverage, cancel orders etc
Account requests 200 Requests to change password, create api keys etc
Others 300 All other requests

Increasing your rate limits

If you are running up against our limits and believe that you have a legitimate need, please email us at support@delta.exchange to discuss increasing your rate limits.

API

The REST API has endpoints for account and order management as well as public market data.

REST API ENDPOINT URL

Products

Get Product List, 24hr Ticker

Get live products

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('https://api.delta.exchange/products', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/products \
  -H 'Accept: application/json'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get 'https://api.delta.exchange/products',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /products

Example responses

200 Response

[
  {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
]

Responses

Status Meaning Description Schema
200 OK List of live products ArrayOfProducts

Get 24hr ticker

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('https://api.delta.exchange/products/ticker/24hr', params={
  'symbol': 'string'
}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/products/ticker/24hr?symbol=string \
  -H 'Accept: application/json'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get 'https://api.delta.exchange/products/ticker/24hr',
  params: {
  'symbol' => 'string'
}, headers: headers

p JSON.parse(result)

GET /products/ticker/24hr

Parameters

Parameter In Type Required Description
symbol query string true product symbol

Example responses

200 Response

{
  "symbol": "string",
  "timestamp": 0,
  "open": 0,
  "high": 0,
  "low": 0,
  "close": 0,
  "volume": 0
}

Responses

Status Meaning Description Schema
200 OK Ticker Date 24hrTicker

Orders

Placing Orders, Cancelling Orders, Get Open orders, Change Orders Leverage

Place Order

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.post('https://api.delta.exchange/orders', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X POST https://api.delta.exchange/orders \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.post 'https://api.delta.exchange/orders',
  params: {
  }, headers: headers

p JSON.parse(result)

POST /orders

Body parameter

{
  "product_id": 0,
  "size": 0,
  "side": "buy",
  "order_type": "limit_order",
  "limit_price": "string",
  "post_only": "true",
  "stop_order_type": "stop_loss_order",
  "stop_price": "string",
  "close_on_trigger": "true"
}

Parameters

Parameter In Type Required Description
body body object true Order which needs to be created
» product_id body integer true none
» size body integer true none
» side body string true none
» order_type body string true none
» limit_price body string false Limit Price for limit order, its a bigdecimal and needs to be passed as a string
» post_only body string false Flag for placing orders in post only mode
» stop_order_type body string false none
» stop_price body string false Stop Price for stop orders
» close_on_trigger body string false Flag for placing orders that should close positions (only for stop orders)

Enumerated Values

Parameter Value
» side buy
» side sell
» order_type limit_order
» order_type market_order
» post_only true
» post_only false
» stop_order_type stop_loss_order
» close_on_trigger true
» close_on_trigger false

Example responses

200 Response

{
  "id": 0,
  "user_id": 0,
  "size": 0,
  "unfilled_size": 0,
  "side": "buy",
  "order_type": "limit_order",
  "limit_price": "string",
  "stop_order_type": "stop_loss_order",
  "stop_price": "string",
  "close_on_trigger": "false",
  "state": "open",
  "created_at": "string",
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

Responses

Status Meaning Description Schema
200 OK Returns back the order object with assigned id and latest state Order
400 Bad Request Returns error if order could not be placed Inline

Response Schema

Status Code 400

Name Type Required Restrictions Description
» error string false none none
» message string false none A more verbose error message

Enumerated Values

Property Value
error InsufficientMargin
error OrderSizeExceededAvailable
error OrderExceedsSizeLimit
error OrderLeverageNotSet
error InvalidProduct
error ImmediateLiquidationOrder
error LowerthanBankruptcy
error SelfMatchingPostOnlyMode
error ImmediateExecutionPostOnlyOrder

Cancel Order

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.delete('https://api.delta.exchange/orders', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X DELETE https://api.delta.exchange/orders \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.delete 'https://api.delta.exchange/orders',
  params: {
  }, headers: headers

p JSON.parse(result)

DELETE /orders

Body parameter

{
  "id": 0,
  "product_id": 0
}

Parameters

Parameter In Type Required Description
body body object true Order which needs to be cancelled
» id body integer true none
» product_id body integer true none

Example responses

200 Response

{
  "id": 0,
  "user_id": 0,
  "size": 0,
  "unfilled_size": 0,
  "side": "buy",
  "order_type": "limit_order",
  "limit_price": "string",
  "stop_order_type": "stop_loss_order",
  "stop_price": "string",
  "close_on_trigger": "false",
  "state": "open",
  "created_at": "string",
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

Responses

Status Meaning Description Schema
200 OK Returns back the order object Order
400 Bad Request Returns error if order could not be cancelled Inline

Response Schema

Status Code 400

Name Type Required Restrictions Description
» error string false none none
» message string false none A more verbose error message

Enumerated Values

Property Value
error ALREADY_FILLED
error InvalidOrder
error InvalidProduct

Get Orders

Code samples

import requests
headers = {
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/orders', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/orders \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/orders',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /orders

Parameters

Parameter In Type Required Description
product_id query integer false get orders for a particular product id
state query string false get orders with a particular state
stop_order_type query string false get stop orders with stop_order_type
page_num query integer false page number for pagination
page_size query integer false page size for pagination

Enumerated Values

Parameter Value
state open
state closed
state cancelled
stop_order_type stop_loss_order

Example responses

200 Response

[
  {
    "id": 0,
    "user_id": 0,
    "size": 0,
    "unfilled_size": 0,
    "side": "buy",
    "order_type": "limit_order",
    "limit_price": "string",
    "stop_order_type": "stop_loss_order",
    "stop_price": "string",
    "close_on_trigger": "false",
    "state": "open",
    "created_at": "string",
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Responses

Status Meaning Description Schema
200 OK List of orders as per the query ArrayOfOrders

Change leverage for open orders

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': '*/*',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.post('https://api.delta.exchange/orders/leverage', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X POST https://api.delta.exchange/orders/leverage \
  -H 'Content-Type: application/json' \
  -H 'Accept: */*' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => '*/*',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.post 'https://api.delta.exchange/orders/leverage',
  params: {
  }, headers: headers

p JSON.parse(result)

POST /orders/leverage

Body parameter

{
  "product_id": 0,
  "leverage": "string"
}

Parameters

Parameter In Type Required Description
body body object true none
» product_id body integer true none
» leverage body string true none

Example responses

200 Response

Responses

Status Meaning Description Schema
200 OK returns the OrderLeverage object OrderLeverage
400 Bad Request Returns error if leverage couldnt be changed Inline

Response Schema

Status Code 400

Name Type Required Restrictions Description
» error string false none none
» message string false none A more verbose error message

Enumerated Values

Property Value
error InsufficientMargin
error LeverageLimitExceeded

Get leverage for all open orders

Code samples

import requests
headers = {
  'Accept': '*/*',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/orders/leverage', params={
  'product_id': '0'
}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/orders/leverage?product_id=0 \
  -H 'Accept: */*' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => '*/*',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/orders/leverage',
  params: {
  'product_id' => 'integer'
}, headers: headers

p JSON.parse(result)

GET /orders/leverage

Parameters

Parameter In Type Required Description
product_id query integer true none

Example responses

200 Response

Responses

Status Meaning Description Schema
200 OK returns the OrderLeverage object OrderLeverage

Positions

Get Open positions, Change Position Margin, Close Position

Get open positions

Code samples

import requests
headers = {
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/positions', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/positions \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/positions',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /positions

Example responses

200 Response

[
  {
    "user_id": 0,
    "size": 0,
    "entry_price": "string",
    "margin": "string",
    "liquidation_price": "string",
    "bankruptcy_price": "string",
    "adl_level": 0,
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Responses

Status Meaning Description Schema
200 OK List of all open positions ArrayOfPositions

Add/Remove position margin

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.post('https://api.delta.exchange/positions/change_margin', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X POST https://api.delta.exchange/positions/change_margin \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.post 'https://api.delta.exchange/positions/change_margin',
  params: {
  }, headers: headers

p JSON.parse(result)

POST /positions/change_margin

Body parameter

{
  "product_id": 0,
  "delta_margin": "string"
}

Parameters

Parameter In Type Required Description
body body object true none
» product_id body integer true none
» delta_margin body string true Delta in the position margin, positive in case of adding margin & negative in case of removing margin

Example responses

200 Response

{
  "user_id": 0,
  "size": 0,
  "entry_price": "string",
  "margin": "string",
  "liquidation_price": "string",
  "bankruptcy_price": "string",
  "adl_level": 0,
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

Responses

Status Meaning Description Schema
200 OK returns the position object Position
400 Bad Request Returns error if position margin could not be changed Inline

Response Schema

Status Code 400

Name Type Required Restrictions Description
» error string false none none
» message string false none A more verbose error message

Enumerated Values

Property Value
error PositionNotSet
error LeverageLimitExceeded
error InsufficientMargin
error ExistingOrderWithLowerThanBankruptcy

Close position

Code samples

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.post('https://api.delta.exchange/positions/close', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X POST https://api.delta.exchange/positions/close \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.post 'https://api.delta.exchange/positions/close',
  params: {
  }, headers: headers

p JSON.parse(result)

POST /positions/close

Body parameter

{
  "product_id": 0,
  "cancel_orders_accepted": "true"
}

Parameters

Parameter In Type Required Description
body body object true none
» product_id body integer true none
» cancel_orders_accepted body string true Flag to choose whether to cancel open orders in case they end up with insufficient margin after closing position

Enumerated Values

Parameter Value
» cancel_orders_accepted true
» cancel_orders_accepted false

Example responses

200 Response

{
  "id": 0,
  "user_id": 0,
  "size": 0,
  "unfilled_size": 0,
  "side": "buy",
  "order_type": "limit_order",
  "limit_price": "string",
  "stop_order_type": "stop_loss_order",
  "stop_price": "string",
  "close_on_trigger": "false",
  "state": "open",
  "created_at": "string",
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

Responses

Status Meaning Description Schema
200 OK returns the order that was placed for closing position Order
400 Bad Request Returns error if position could not be closed Inline

Response Schema

Status Code 400

Name Type Required Restrictions Description
» error string false none none
» message string false none A more verbose error message

Enumerated Values

Property Value
error PositionNotSet
error InsufficientMargin
error InsufficientCommission
error OrderSizeExceededAvailable
error OrderLeverageNotSet
error InvalidProduct
error LowerthanBankruptcy

Trade History

Get Orders History, Get Fill History

Get order history (cancelled and closed)

Code samples

import requests
headers = {
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/orders/history', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/orders/history \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/orders/history',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /orders/history

Parameters

Parameter In Type Required Description
page_num query integer false page number for pagination
page_size query integer false page size for pagination

Example responses

200 Response

[
  {
    "id": 0,
    "user_id": 0,
    "size": 0,
    "unfilled_size": 0,
    "side": "buy",
    "order_type": "limit_order",
    "limit_price": "string",
    "stop_order_type": "stop_loss_order",
    "stop_price": "string",
    "close_on_trigger": "false",
    "state": "open",
    "created_at": "string",
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Responses

Status Meaning Description Schema
200 OK List of orders ArrayOfOrders

Get fills

Code samples

import requests
headers = {
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/fills', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/fills \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/fills',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /fills

Parameters

Parameter In Type Required Description
page_num query integer false page number for pagination
page_size query integer false page size for pagination

Example responses

200 Response

[
  {
    "id": 0,
    "size": 0,
    "side": "buy",
    "price": "string",
    "role": "taker",
    "commission": "string",
    "created_at": "string",
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Responses

Status Meaning Description Schema
200 OK List of Fills ArrayOfFills

Orderbook

L2Orderbook

Get L2 orderbook

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('https://api.delta.exchange/orderbook/{product_id}/l2', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/orderbook/{product_id}/l2 \
  -H 'Accept: application/json'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get 'https://api.delta.exchange/orderbook/{product_id}/l2',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /orderbook/{product_id}/l2

Parameters

Parameter In Type Required Description
product_id path integer true none

Example responses

200 Response

{
  "buy_book": [
    {
      "price": "string",
      "size": 0
    }
  ],
  "sell_book": [
    {
      "price": "string",
      "size": 0
    }
  ],
  "recent_trades": [
    {
      "side": "buy",
      "size": 0,
      "price": "string",
      "timestamp": 0
    }
  ],
  "spot_price": "string",
  "mark_price": "string",
  "product_id": 0
}

Responses

Status Meaning Description Schema
200 OK L2 orderbook for the product L2Orderbook

Wallet

Get balances, Get transaction history

Get Wallet Balances

Code samples

import requests
headers = {
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/wallet/balances', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/wallet/balances \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/wallet/balances',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /wallet/balances

Example responses

200 Response

[
  {
    "balance": "string",
    "order_margin": "string",
    "position_margin": "string",
    "commission": "string",
    "available_balance": "string",
    "asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
]

Responses

Status Meaning Description Schema
200 OK List of wallets attached to the user account ArrayOfWallets

Get Wallet transactions

Code samples

import requests
headers = {
  'Accept': 'application/json',
  'api-key': '****',
  'signature': '****',
  'timestamp': '****'
}

r = requests.get('https://api.delta.exchange/wallet/transactions', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/wallet/transactions \
  -H 'Accept: application/json' \
  -H 'api-key: ****' \
  -H 'signature: ****' \
  -H 'timestamp: ****'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'api-key' => '****',
  'signature' => '****',
  'timestamp' => '****'
}

result = RestClient.get 'https://api.delta.exchange/wallet/transactions',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /wallet/transactions

Parameters

Parameter In Type Required Description
asset_id query integer false asset_id for that particular Wallet
page_num query integer false page number for pagination
page_size query integer false page size for pagination

Example responses

200 Response

[
  {
    "id": 0,
    "amount": "string",
    "balance": "string",
    "transaction_type": "pnl",
    "meta_data": {},
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    },
    "created_at": "string"
  }
]

Responses

Status Meaning Description Schema
200 OK list of transactions for that wallet ArrayOfTransactions

OHLC Candles

Get OHLC candles

Code samples

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('https://api.delta.exchange/chart/history', params={

}, headers = headers)

print r.json()

# You can also use wget
curl -X GET https://api.delta.exchange/chart/history \
  -H 'Accept: application/json'

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get 'https://api.delta.exchange/chart/history',
  params: {
  }, headers: headers

p JSON.parse(result)

GET /chart/history

Parameters

Parameter In Type Required Description
symbol query string false product symbol
from query integer false start time for the interval ( in seconds )
to query integer false end time for the interval ( in seconds )
resolution query string false resolution for the candles

Enumerated Values

Parameter Value
resolution 1
resolution 5
resolution 15
resolution 60
resolution 360
resolution D

Example responses

200 Response

{
  "t": [
    0
  ],
  "o": [
    "string"
  ],
  "h": [
    "string"
  ],
  "l": [
    "string"
  ],
  "c": [
    "string"
  ],
  "v": [
    0
  ]
}

Responses

Status Meaning Description Schema
200 OK OHLC candles OHLCData

Schemas

Asset

{
  "id": 0,
  "symbol": "string",
  "precision": 0
}

Properties

Name Type Required Restrictions Description
id integer(int64) false none none
symbol string false none none
precision integer false none none

Product

{
  "id": 0,
  "symbol": "string",
  "description": "string",
  "product_type": "future",
  "initial_margin": "string",
  "maintenance_margin": "string",
  "settlement_time": "string",
  "impact_size": 0,
  "pricing_source": "string",
  "tick_size": "string",
  "trading_status": "operational",
  "position_size_limit": 0,
  "commission_rate": "string",
  "maker_commission_rate": "string",
  "underlying_asset": {
    "id": 0,
    "symbol": "string",
    "precision": 0
  },
  "quoting_asset": {
    "id": 0,
    "symbol": "string",
    "precision": 0
  },
  "settling_asset": {
    "id": 0,
    "symbol": "string",
    "precision": 0
  }
}

Properties

Name Type Required Restrictions Description
id integer(int64) false none none
symbol string false none none
description string false none none
product_type string false none none
initial_margin string false none none
maintenance_margin string false none none
settlement_time string false none none
impact_size integer false none none
pricing_source string false none none
tick_size string false none none
trading_status string false none none
position_size_limit integer false none none
commission_rate string false none none
maker_commission_rate string false none none
underlying_asset Asset false none none
quoting_asset Asset false none none
settling_asset Asset false none none

Enumerated Values

Property Value
product_type future
product_type inverse_future
trading_status operational
trading_status disrupted_cancel_only
trading_status disrupted_post_only

ArrayOfProducts

[
  {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
]

Properties

Name Type Required Restrictions Description
anonymous [Product] false none none

Order

{
  "id": 0,
  "user_id": 0,
  "size": 0,
  "unfilled_size": 0,
  "side": "buy",
  "order_type": "limit_order",
  "limit_price": "string",
  "stop_order_type": "stop_loss_order",
  "stop_price": "string",
  "close_on_trigger": "false",
  "state": "open",
  "created_at": "string",
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

An Order object

Properties

Name Type Required Restrictions Description
id integer false none none
user_id integer false none none
size integer false none none
unfilled_size integer false none none
side string false none side for which to place order
order_type string false none none
limit_price string false none none
stop_order_type string false none none
stop_price string false none none
close_on_trigger string false none none
state string false none Order Status
created_at string false none none
product Product false none none

Enumerated Values

Property Value
side buy
side sell
order_type limit_order
order_type market_order
stop_order_type stop_loss_order
close_on_trigger false
close_on_trigger true
state open
state pending
state closed
state cancelled

ArrayOfOrders

[
  {
    "id": 0,
    "user_id": 0,
    "size": 0,
    "unfilled_size": 0,
    "side": "buy",
    "order_type": "limit_order",
    "limit_price": "string",
    "stop_order_type": "stop_loss_order",
    "stop_price": "string",
    "close_on_trigger": "false",
    "state": "open",
    "created_at": "string",
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Properties

Name Type Required Restrictions Description
anonymous [Order] false none [An Order object]

Position

{
  "user_id": 0,
  "size": 0,
  "entry_price": "string",
  "margin": "string",
  "liquidation_price": "string",
  "bankruptcy_price": "string",
  "adl_level": 0,
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

A position object

Properties

Name Type Required Restrictions Description
user_id integer false none none
size integer false none Position size, negative for short and positive for long
entry_price string false none none
margin string false none none
liquidation_price string false none none
bankruptcy_price string false none none
adl_level integer false none none
product Product false none none

ArrayOfPositions

[
  {
    "user_id": 0,
    "size": 0,
    "entry_price": "string",
    "margin": "string",
    "liquidation_price": "string",
    "bankruptcy_price": "string",
    "adl_level": 0,
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Properties

Name Type Required Restrictions Description
anonymous [Position] false none [A position object]

Fill

{
  "id": 0,
  "size": 0,
  "side": "buy",
  "price": "string",
  "role": "taker",
  "commission": "string",
  "created_at": "string",
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
}

A fill object

Properties

Name Type Required Restrictions Description
id integer false none none
size integer false none none
side integer false none none
price string false none Price at which the fill happened, BigDecimal sent as string
role string false none none
commission string false none Commission paid on this fill, negative value means commission was earned because of maker role
created_at string false none none
product Product false none none

Enumerated Values

Property Value
side buy
side sell
role taker
role maker

ArrayOfFills

[
  {
    "id": 0,
    "size": 0,
    "side": "buy",
    "price": "string",
    "role": "taker",
    "commission": "string",
    "created_at": "string",
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    }
  }
]

Properties

Name Type Required Restrictions Description
anonymous [Fill] false none [A fill object]

OrderLeverage

{
  "leverage": "string",
  "order_margin": "string",
  "product_id": 0
}

Order Leverage for a product

Properties

Name Type Required Restrictions Description
leverage string false none Leverage of all open orders for this product
order_margin string false none Margin blocked in open orders for this product
product_id integer false none none

L2Orderbook

{
  "buy_book": [
    {
      "price": "string",
      "size": 0
    }
  ],
  "sell_book": [
    {
      "price": "string",
      "size": 0
    }
  ],
  "recent_trades": [
    {
      "side": "buy",
      "size": 0,
      "price": "string",
      "timestamp": 0
    }
  ],
  "spot_price": "string",
  "mark_price": "string",
  "product_id": 0
}

L2 orderbook

Properties

Name Type Required Restrictions Description
buy_book [object] false none none
» price string false none none
» size integer false none none
sell_book [object] false none none
» price string false none none
» size integer false none none
recent_trades [object] false none none
» side string false none none
» size integer false none none
» price string false none none
» timestamp integer false none none
spot_price string false none none
mark_price string false none none
product_id integer false none none

Enumerated Values

Property Value
side buy
side sell

Wallet

{
  "balance": "string",
  "order_margin": "string",
  "position_margin": "string",
  "commission": "string",
  "available_balance": "string",
  "asset": {
    "id": 0,
    "symbol": "string",
    "precision": 0
  }
}

Properties

Name Type Required Restrictions Description
balance string false none Total wallet balance
order_margin string false none Margin blocked in open orders
position_margin string false none Margin blocked in open positions
commission string false none Commissions blocked in open orders and open positions
available_balance string false none Amount available for withdrawals
asset Asset false none none

ArrayOfWallets

[
  {
    "balance": "string",
    "order_margin": "string",
    "position_margin": "string",
    "commission": "string",
    "available_balance": "string",
    "asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  }
]

Properties

Name Type Required Restrictions Description
anonymous [Wallet] false none none

Transaction

{
  "id": 0,
  "amount": "string",
  "balance": "string",
  "transaction_type": "pnl",
  "meta_data": {},
  "product": {
    "id": 0,
    "symbol": "string",
    "description": "string",
    "product_type": "future",
    "initial_margin": "string",
    "maintenance_margin": "string",
    "settlement_time": "string",
    "impact_size": 0,
    "pricing_source": "string",
    "tick_size": "string",
    "trading_status": "operational",
    "position_size_limit": 0,
    "commission_rate": "string",
    "maker_commission_rate": "string",
    "underlying_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "quoting_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    },
    "settling_asset": {
      "id": 0,
      "symbol": "string",
      "precision": 0
    }
  },
  "created_at": "string"
}

Properties

Name Type Required Restrictions Description
id integer false none none
amount string false none amount credited/debited in this transaction (+ for credited, - for debited)
balance string false none net wallet balance after this transaction
transaction_type string false none none
meta_data object false none none
product Product false none none
created_at string false none none

Enumerated Values

Property Value
transaction_type pnl
transaction_type deposit
transaction_type withdrawal
transaction_type commission
transaction_type conversion
transaction_type perpetual_futures_funding
transaction_type withdrawal_cancellation
transaction_type referral_bonus
transaction_type commission_rebate
transaction_type promo_credit

ArrayOfTransactions

[
  {
    "id": 0,
    "amount": "string",
    "balance": "string",
    "transaction_type": "pnl",
    "meta_data": {},
    "product": {
      "id": 0,
      "symbol": "string",
      "description": "string",
      "product_type": "future",
      "initial_margin": "string",
      "maintenance_margin": "string",
      "settlement_time": "string",
      "impact_size": 0,
      "pricing_source": "string",
      "tick_size": "string",
      "trading_status": "operational",
      "position_size_limit": 0,
      "commission_rate": "string",
      "maker_commission_rate": "string",
      "underlying_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "quoting_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      },
      "settling_asset": {
        "id": 0,
        "symbol": "string",
        "precision": 0
      }
    },
    "created_at": "string"
  }
]

Properties

Name Type Required Restrictions Description
anonymous [Transaction] false none none

24hrTicker

{
  "symbol": "string",
  "timestamp": 0,
  "open": 0,
  "high": 0,
  "low": 0,
  "close": 0,
  "volume": 0
}

Properties

Name Type Required Restrictions Description
symbol string false none none
timestamp integer false none none
open number false none none
high number false none none
low number false none none
close number false none none
volume integer false none none

OHLCData

{
  "t": [
    0
  ],
  "o": [
    "string"
  ],
  "h": [
    "string"
  ],
  "l": [
    "string"
  ],
  "c": [
    "string"
  ],
  "v": [
    0
  ]
}

Properties

Name Type Required Restrictions Description
t [integer] false none array of timestamps for which candles are returned
o [string] false none open prices for candles
h [string] false none high prices for candles
l [string] false none low prices for candles
c [string] false none close prices for candles
v [integer] false none volumes for candles

Errors

Delta API uses the following error codes:

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key/Signature is wrong.
404 Not Found -- The specified kitten could not be found.
405 Method Not Allowed -- You tried to access a kitten with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
429 Too Many Requests -- You have exhausted your rate limits! Slow down!
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.

Websocket Feed

Websocket api can be used for the following use cases

Access url

Subscribing to Channels

Subscribe

To begin receiving feed messages, you must first send a subscribe message to the server indicating which channels and contracts to subscribe for. This message is mandatory — you will be disconnected if no subscribe has been received within 5 seconds.

To specify contracts within each channel, just pass a list of symbols inside the channel payload.

Once a subscribe message is received the server will respond with a subscriptions message that lists all channels you are subscribed to. Subsequent subscribe messages will add to the list of subscriptions.

Subscription Sample

// Request
// Subscribe to BTCUSD_28Dec and ETHBTC_28Dec with the ticker and orderbookL2 channels,
{
    "type": "subscribe",
    "payload": {
        "channels": [
            {
                "name": "ticker",
                "symbols": [
                    "BTCUSD_28Dec",
                    "ETHBTC_28Dec"
                ]
            },
            {
                "name": "l2_orderbook",
                "symbols": [
                    "BTCUSD_28Dec"
                ]
            }
        ]
    }
}

// Response
{
    "type": "subscriptions",
    "channels": [
        {
            "name": "l2_orderbook",
            "symbols": [
                "BTCUSD_28Dec"
            ],
        },
        {
            "name": "ticker",
            "symbols": [
                "BTCUSD_28Dec",
                "ETHBTC_28Dec"
            ]
        }
    ]
}

Unsubscribe

If you want to unsubscribe from channel/contracts pairs, send an "unsubscribe" message. The structure is equivalent to subscribe messages. As a shorthand you can also provide no symbols for a channel, which will unsubscribe you from the channel entirely.

As a response to an unsubscribe message you will receive a subscriptions response.

Unsubscribe Sample

// Request
{
    "type": "unsubscribe",
    "payload": {
        "channels": [
            {
                "name": "ticker"
            }
        ]
    }
}

Authenticating a connection

Authentication allows clients to receives private messages, like trading notifications. Examples of the trading notifications are: fills, liquidations, adl and pnl updates.

To authenticate, you need to send a signed request of type 'auth' on your socket connection. Check the authentication section above for more details on how to sign a request using api key and secret.

The payload for the signed request will be 'GET' + timestamp + '/live'

Authentication sample

// auth message with signed request
import websocket
import hashlib
import hmac
import base64

api_key = 'a207900b7693435a8fa9230a38195d'
api_secret = '7b6f39dcf660ec1c7c664f612c60410a2bd0c258416b498bf0311f94228f'

def generate_signature(secret, message):
    message = bytes(message, 'utf-8')
    secret = bytes(secret, 'utf-8')
    hash = hmac.new(secret, message, hashlib.sha256)
    return hash.hexdigest()

def get_time_stamp():
    d = datetime.datetime.utcnow()
    epoch = datetime.datetime(1970,1,1)
    return str(int((d - epoch).total_seconds()))

# Get open orders
method = 'GET'
timestamp = get_time_stamp()
path = '/live'
signature_data = method + timestamp + path
signature = generate_signature(api_secret, signature_data)


ws = websocket.WebSocketApp('wss://api.delta.exchange:3091')
ws.send(json.dumps({
    "type": "auth",
    "payload": {
        "api-key": api_key,
        "signature": signature,
        "timestamp": timestamp
    }
}))

To unsubscribe from all private channels, just send a 'unauth' message on the socket. This will automatically unsubscribe the connection from all authenticated channels.

ws.send(json.dumps({
    "type": 'unauth',
    "payload": {}
}))

Public Channels

ticker

The ticker channel provides price change data for the last 24 hrs (rolling window). It is published every 5 seconds.

On subscribing to ticker channel, socket server will emit messages with type 'ticker' in response.

Ticker Sample

// Response
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "type": "ticker",
    "timestamp": 1542108684,
    "open": 0.0014622,
    "high": 0.0014622,
    "low": 0.0014622,
    "close": 0.0014622,
    "volume": 1
}

l2_orderbook

l2_orderbook channel provides snapshot of the latest level2 orderbook.

L2 Orderbook Sample

// Snapshot Response
{
    "symbol": "BTCUSD_28Dec",
    "product_id": 3,
    "type": "snapshot",
    "timestamp": 1542108684,
    "buy": [{"price":"0.0014577","size":62},{"price":"0.0014571","size":28},{"price":"0.0014562","size":54},{"price":"0.001455","size":34}],
    "sell": [{"price":"6229.0","size":15964},{"price":"6229.5","size":3504},{"price":"6230.0","size":15964},{"price":"6231.0","size":15957}]
}

trades

trades channel provides a real time feed of all recent trades (fills).

// Trades Response
{
    symbol: "BNBBTC_30Nov",
    price: "0.0014579",
    size: 100,
    buyer_role: "maker",
    seller_role: "taker",
    timestamp: 1542108684
}

mark_price

mark_price channel provides a real time feed of mark price. This is the price on which all open positions are marked for liquidation.

Please note that the product symbol is prepended with a "MARK:" to subscribe for mark price.

// Mark Price Response
{
    symbol: "MARK:BNBBTC_30Nov",
    product_id: 7,
    type: "mark_price",
    price: "0.00401010",
    annualized_basis: 25.12,    // in %
    timestamp: 1542108684
}

spot_price

spot_price channel provides a real time feed of the underlying index prices.

// Spot Price Response
{
    symbol: "BNB/BTC",
    price: "0.0014579",
    type: "spot_price
}

Private Channels

Private channels require clients to authenticate.

trading_notifications

trading_notifications channel provides updates of all the private trade notifications.

orderUpdate

// orderUpdate
{
    "type": "orderUpdate",
    "action": "fill",
    "product_id": 3,
    "symbol": "BTCUSD_28Dec",
    "order_id": 3283999,
    "side": "buy",
    "unfilled_size": 1,
    "filled_size": 1,
    "price": "4500.0",
    "state": "open",
    "timestamp": 1544091555086559
}

fill

// Fill
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "type": "fill",
    "user_id": 1998,
    "order_id": 3283999,
    "side": "buy",
    "size": 190,
    "price": "0.00145791",
    "timestamp": 1544091555086559
}

adl

// ADL
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "type": "adl",
    "timestamp": 1544091555086559

}

self_trade

// Self Trade
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "type": "self_trade",
    "user_id": 1998,
    "size": 199,
    "price": "0.00145791",
    "timestamp": 1544091555086559
}

pnl

// PNL
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "type": "pnl",
    "user_id": 1998,
    "side": "sell",
    "size": 180",
    "entry_price": "0.00145797",
    "exit_price": "0.00145791",
    "realized_pnl": "0.00102121",
    "timestamp": 1544091555086559

}

liquidation

// Liquidation
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "type": "liquidation",
    "user_id": 1998,
    "timestamp": 1542108684,
    "side": "buy",
    "size": 180,
    "liquidation_price": "0.00145791",
    "bankruptcy_price": "0.00145700",

}

stop_trigger

// Stop Trigger
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "user_id": 1998
    "type": "stop_trigger",
    "timestamp": 1542108684,
    "side": "buy",
    "size": 180

}

stop_cancel

// Stop Cancel
{
    "symbol": "BNBBTC_30Nov",
    "product_id": 7,
    "user_id": 1998
    "type": "stop_cancel",
    "timestamp": 1542108684,
    "side": "buy",
    "message": "",
    "size": 180
}