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
GetTrades
Search the specific trading pair’s transaction history
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (e.g. 'BTC_USD') |
count | YES | number | quantity: 100 limit |
{
"action": "GetTrades",
"symbol": "BTC_USD",
"count": 50
}
Response
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
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading 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
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (e.g. 'BTC_USD') |
{
"action": " UnSubscribe",
"symbol": "BTC_USD"
}
SubOrderBook
Subscribe a specific trading pair's orderbook
params
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (eg: 'BTC_USD') |
len | YES | string | orderbook length( eg:10、25、100) |
{
"action": "SubOrderBook",
"symbol": "BTC_USD",
"len": 100
}
Response
Field | Value/Explanation |
---|---|
MsgType | SubOrderBookResponse |
Symbol | trading pair (eg: 'BTC_USD') |
Data.Asks | Asks array[0] is price, array[1] = volume |
Data.Bids | Bids 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
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (eg: 'BTC_USD') |
len | YES | string | orderbook length( eg:10、25、100) |
{
"action": "UnSubOrderBook",
"symbol": "BTC_USD",
"len": 100
}
PRIVATE MESSAGE
common
Add common field for all kind of requests
params
Parameter | Required | Type | Explanation |
---|---|---|---|
timestamp | YES | timestamp (13) | 13-digit timestamp (Server will not request an expired request over 2s ) |
nonce | YES | string or number | 8-digit random number |
public_key | YES | string | user public key (not username, get it from user control center) |
sign | YES | string | signature (please see the sign.md for the detailed information) |
action | YES | string | message type(support type as below) |
crid | YES | string | If 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
Push ExecReport when order state change. Push AccountInfo when account assets change.
Logout
Unsubscribe push notification
params
use common
field
Response
PlaceOrder
place orders
params
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (e.g. 'BTC_USD') |
side | YES | enum ('SELL', 'BUY') | buy or sell |
order_type | YES | enum ('LIMIT', 'MARKET', 'STOP') | order type: market order, limit order or stop-loss order |
stop_price | NO | number | stop-loss price: >0 , The required change to YES when order_type is STOP order |
price | YES | number | price: >0 |
quantity | YES | number | trading volume:>0 (get different trading pair configuration according to GetActiveContracts) |
Response
GetOpenOrders
Get open orders for specific trading pair, you can query all your trading pairs’ transaction history when symbol
’s status is null
params
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | NO | string | trading pair (e.g. 'BTC_USD') |
begin | NO | timestamp | query begin timestamp: default value 0 |
end | NO | timestamp | query end timestamp: default value Date.now() |
Response
CancelOrder
cancel order
params
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (e.g. 'BTC_USD') |
order_id | YES | string | order ID: OID |
Response
CancelReplaceOrder
Update the information of pending orders
params
Parameter | Required | Type | Explanation |
---|---|---|---|
symbol | YES | string | trading pair (e.g. 'BTC_USD') |
order_id | YES | string | order ID: OID |
price | YES | number | price: >0 |
stop_price | NO | number | stop-loss price: >0 , The required change to YES when order_type is STOP order |
quantity | YES | number | trading volume: >0 (get different trading pair configuration according to GetActiveContracts) |
old_quantity | YES | number | unfilled quantity |
Response
GetAccountInfo
Get account assets’ details
params
use common
field
Response
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'