WS-API

Table of Contents

Examples

Common

You can add crid field for all requests. If you add this field, it will be returned in CRID value. If you do not add this field, then it is a random uuid.

PUBLIC MESSAGE

No signature and common fields

GetActiveContracts

get all of the current trading pairs information by using action field

{
  "action": "GetActiveContracts"
}

Response

GetActiveContractsResponse

GetTrades

Search the specific trading pair’s transaction history

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (e.g. 'BTC_USD')
countYESnumberquantity: 100 limit
{
  "action": "GetTrades",
  "symbol": "BTC_USD",
  "count": 50
}

Response

GetTradesResponse

SubscribeAllTickers

Subscribe all of the trading pairs’ tickers, push all of the ticker arrays every second

{
  "action": "SubscribeAllTickers"
}

Response

{
  "MsgType": "AllTickersResponse",
  "data": ["...tickers"]
}

UnSubscribeAllTickers

Unsubscribe all of the trading pairs’ tickers

{
  "action": "UnSubscribeAllTickers"
}

Subscribe

Subscribe a specific trading pair’s ticker and orderbook

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (e.g. 'BTC_USD')
{
  "action": "Subscribe",
  "symbol": "BTC_USD"
}

Response

Push this trading pair’s 2.2 Ticker message continuously

UnSubscribe

Unsubscribe a specific trading pair’s ticker

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (e.g. 'BTC_USD')
{
  "action": " UnSubscribe",
  "symbol": "BTC_USD"
}

SubOrderBook

Subscribe a specific trading pair's orderbook

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (eg: 'BTC_USD')
lenYESstringorderbook length( eg:10、25、100)
{
  "action": "SubOrderBook",
  "symbol": "BTC_USD",
  "len": 100
}

Response

FieldValue/Explanation
MsgTypeSubOrderBookResponse
Symboltrading pair (eg: 'BTC_USD')
Data.AsksAsks array[0] is price, array[1] = volume
Data.BidsBids array[0] is price, array[1] = volume
Timestamp
{
    "MsgType":"OrderBook.BTC_USD.10",
    "Symbol":"BTC_USD",
    "Data":{
        "Asks":[
            [
                7458.8,
                0.0974
            ],
            [
                7459,
                0.0054
            ],
            [
                7459.4,
                0.0494
            ]
        ],
        "Bids":[
            [
                7458.7,
                0.0001
            ],
            [
                7458.3,
                0.0003
            ],
            [
                7457.4,
                0.0001
            ]
        ]
    },
    "Timestamp":1533106907345
}

UnSubOrderBook

Subscribe a specific trading pair's orderbook,

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (eg: 'BTC_USD')
lenYESstringorderbook length( eg:10、25、100)
{
  "action": "UnSubOrderBook",
  "symbol": "BTC_USD",
  "len": 100
}

PRIVATE MESSAGE

common

Add common field for all kind of requests

params

ParameterRequiredTypeExplanation
timestampYEStimestamp (13)13-digit timestamp (Server will not request an expired request over 2s)
nonceYESstring or number8-digit random number
public_keyYESstringuser public key (not username, get it from user control center)
signYESstringsignature (please see the sign.md for the detailed information)
actionYESstringmessage type(support type as below)
cridYESstringIf you add crid field, it will be returned in CRID value. If you do not add this field, then it is a random uuid.
  action: {
    type: 'string',
    enum: [
      'Login',
      'Logout',
      'PlaceOrder',
      'GetOpenOrders',
      'GetClosedOrders',
      'GetAllOrders',
      'CancelOrder',
      'CancelAllOrders',
      'RetrieveOrder',
      'GetAccountInfo',
      'CancelReplaceOrder'
    ]
  }

Login

Subscribe push notification

params

use common field

Response

LoginResponse

Push ExecReport when order state change. Push AccountInfo when account assets change.

Logout

Unsubscribe push notification

params

use common field

Response

LogoutResponse

PlaceOrder

place orders

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (e.g. 'BTC_USD')
sideYESenum ('SELL', 'BUY')buy or sell
order_typeYESenum ('LIMIT', 'MARKET', 'STOP')order type: market order, limit order or stop-loss order
stop_priceNOnumberstop-loss price: >0, The required change to YES when order_type is STOP order
priceYESnumberprice: >0
quantityYESnumbertrading volume:>0 (get different trading pair configuration according to GetActiveContracts)

Response

PlaceOrderResponse

GetOpenOrders

Get open orders for specific trading pair, you can query all your trading pairs’ transaction history when symbol’s status is null

params

ParameterRequiredTypeExplanation
symbolNOstringtrading pair (e.g. 'BTC_USD')
beginNOtimestampquery begin timestamp: default value 0
endNOtimestampquery end timestamp: default value Date.now()

Response

GetOrdersResponse

CancelOrder

cancel order

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (e.g. 'BTC_USD')
order_idYESstringorder ID: OID

Response

Cancel replace order response

CancelReplaceOrder

Update the information of pending orders

params

ParameterRequiredTypeExplanation
symbolYESstringtrading pair (e.g. 'BTC_USD')
order_idYESstringorder ID: OID
priceYESnumberprice: >0
stop_priceNOnumberstop-loss price: >0, The required change to YES when order_type is STOP order
quantityYESnumbertrading volume: >0 (get different trading pair configuration according to GetActiveContracts)
old_quantityYESnumberunfilled quantity

Response

Cancel replace order response

GetAccountInfo

Get account assets’ details

params

use common field

Response

GetAccountInfoResponse

ERROR RC CODE

exports.TIME_IN_FORCE = {
  DAY: '0',
  GTC: '1'
}

exports.ERROR_REPONSED = {
  INVALID_JSON_PAYLOAD: {
    RC: '-2001',
    data: 'invalid json payload'
  },
  WS_NOT_OK: {
    RC: '-2002',
    data: 'ws not ok, try again later'
  },
  AUTH_ERROR: {
    RC: '-2003',
    data: 'auth error'
  },
  NEED_LOGIN: {
    RC: '-2004',
    data: 'action need login first'
  },
  INVALID_ACTION: {
    RC: '-2005',
    data: 'invalid action'
  },
  INVALID_SYMBOL: {
    RC: '-2007',
    data: 'invalid symbol'
  }
}

exports.VALIDATE_ERROR_CODE = '-2006'