NAV Navbar
javascript

REST API for statistic data

Through the REST API, you can get statistical data on all stock instruments in the last 24 hours.

Example:

// Request  
https://api.bitex.one/v1/instruments

// Response
[{"btc_24h":109.38275895,"last_deal":26.031,"leverage":10,"maker_commission":-0.025,"name":"LTCUSDT","taker_commission":0.075,"type":"SWAP","usd_24h":391174.62},
{"btc_24h":99.1654167,"last_deal":107.45,"leverage":10,"maker_commission":-0.025,"name":"BCHABCUSDT-03.19","taker_commission":0.075,"type":"FUT","usd_24h":354635.36},
{"btc_24h":106.76572455,"last_deal":3561.8,"leverage":10,"maker_commission":-0.025,"name":"BTCUSDT-03.19","taker_commission":0.075,"type":"FUT","usd_24h":381815.58},
{"btc_24h":105.29687215,"last_deal":3573.2,"leverage":10,"maker_commission":-0.025,"name":"BTCUSDT","taker_commission":0.075,"type":"SWAP","usd_24h":376562.67},
{"btc_24h":91.2738902,"last_deal":95.58,"leverage":10,"maker_commission":-0.025,"name":"ETHUSDT","taker_commission":0.075,"type":"SWAP","usd_24h":326413.68},
{"btc_24h":99.0154287,"last_deal":108.66,"leverage":10,"maker_commission":-0.025,"name":"BCHABCUSDT","taker_commission":0.075,"type":"SWAP","usd_24h":354098.97},
{"btc_24h":109.22877655,"last_deal":2.021,"leverage":10,"maker_commission":-0.025,"name":"EOSUSDT","taker_commission":0.075,"type":"SWAP","usd_24h":390623.95},
{"btc_24h":91.5819756,"last_deal":96.64,"leverage":10,"maker_commission":-0.025,"name":"ETHUSDT-03.19","taker_commission":0.075,"type":"FUT","usd_24h":327515.46},
{"btc_24h":109.8624868,"last_deal":25.011,"leverage":10,"maker_commission":-0.025,"name":"LTCUSDT-03.19","taker_commission":0.075,"type":"FUT","usd_24h":392890.22},
{"btc_24h":109.2785538,"last_deal":2.0084,"leverage":10,"maker_commission":-0.025,"name":"EOSUSDT-03.19","taker_commission":0.075,"type":"FUT","usd_24h":390801.96}]

Request

https://api.bitex.one/v1/instruments

Response

{"btc_24h":,"last_deal":,"leverage":,"maker_commission":,"name":,"taker_commission":,"type":,"usd_24h":}

Parameter Required Type Description
btc_24h true uint32 Last 24h turnover in BTC
last_deal true int32 Last deal price of the instrument
leverage true uint16 Leverage instrument
maker_commission double int32 Comission of maker deal side in % (if negative then maker takes rebate)
name true string Instrument name
taker_commission double int32 Comission of taker deal side in %
type true uint8 Type of instrument
usd_24h true uint32 Last 24h turnover in USD

WEBSOCKET API

The WEBSOCKET API is designed to receive market data and send trade orders. It can be used for programming trading robots and integrating into various trading terminals.

Instrument params

Request instrument parameters.

Example:

// Request
socket.send('[1104,[]]');
// Response
[1105,[
        [1,"BTCUSD",1,1,10000000,1,10000,1,0.075,-0.025,5,2,10,1,0,101,201,501,0,14400,28800,0],
        [13,"BCHUSD-12.18",1,1,10000000,1,10000,1,0.075,-0.025,10,2,10,2,1545998400000,102,313,0,402,0,0,0.1],
        [102,"BCHUSDi",1,1,10000000,0,0,1,0,0,0,0,0,5,0,0,0,0,0,0,0,0],
        [201,"BTCUSDm",1,1,10000000,0,0,1,0,0,0,0,0,6,0,0,0,0,0,0,0,0],
        [312,"BTCUSD-12.18m",1,1,10000000,0,0,1,0,0,0,0,0,6,0,0,0,0,0,0,0,0],
        [511,"EOSUSDf_avg_8h",1,1,10000000,0,0,3,0,0,0,0,0,8,0,0,0,0,0,0,0,0]
      ]
]

Request

[1104,[]]

Response

[ins_id,ins_name,tick_size,price_min,price_max,volume_min,volume_max,precision,comiss_taker, comiss_maker,tick_value,maintenance,leverage,ins_type,expiration_time,index_id,mark_price_id, funding_index_id,expiration_index_id,funding_begin_time,funding_period_time,expiration_comiss]

Parameter Required Type Description
ins_id true uint16 Instrument ID
ins_name true string Instrument name
tick_size true int32 Minimum price step
price_min true int32 Minimum price limit
price_max true int32 Maximum price limit
volume_min true int32 Minimum order volume
volume_max true int32 Maximum order volume
precision true int8 Number of decimal places in the instrument price
comiss_taker true double Deal commission for taker order, %
comiss_maker true double Deal commission for maker order, %
tick_value true int32 Cost of minimum price step
maintenance true double Maintenance margin, %
leverage true uint8 Leverage
ins_type true uint16 Instrument type:
1 - Swap contract
2 - Futures contract
5 - Instrument price index
6 - Instrument mark price
7 - avg 30m price index (expiration price)
8 - avg 8h index (funding value index)
expiration_time true uint64 Futures expiration time in ms, since Jan 01 1970. (UTC)
index_id true uint16 Index price ID
mark_price_id true uint16 Mark price ID
funding_index_id true uint16 Funding index ID
expiration_index_id true uint16 Expiration index ID
funding_begin_time true uint32 Funding begin time in seconds since 12:00 AM (UTC)
funding_period_time true uint32 Funding period time in seconds
expiration_comiss true double Expiration commission, %

Instrument statistics

In first time after connect client receives statistics on all instruments. Then the data comes as it changes.

Example:

// Response
[1107,[
        [1,62735,33,-287,200203586,7638572],
        [16,4856,-15,-154,209799727,7873820],
        [102,4370,0,-332,0,0],
        [209,1829,0,-139,0,0],
        [301,62725,0,-464,0,0],
        [404,5114,0,-263,0,0],
        [509,1,0,1,0,0]
      ]
]

Response

[ins_id,last_deal_price,last_deal_volume,change_24h,volume_24h,open_interest]

Parameter Required Type Description
ins_id true uint16 Instrument ID
last_deal_price true int32 Last deal price
last_deal_volume true int32 Last deal volume
change_24h true int32 Price change for the last 24 hours
volume_24h true int64 Trade volume for the last 24 hours
open_interest true int64 Open interest

Order Book

Order Book subscribe:

// Subscribe on order book for ins_id = 1
socket.send('[1100, [1]]');

// Subscribe on order book for ins_id = 1 and 2
socket.send('[1100, [1, 2]]');

Request Order Book subscribe

[1100,[ins_id]]

Order Book unsubscribe:

// Unsubscribe on order book for ins_id = 1
socket.send('[1101, [1]]');

// Unsubscribe on order book for ins_id = 1 and 2
socket.send('[1101, [1, 2]]');

Request Order Book unsubscribe

[1101,[ins_id]]

Response Order Book clear

[1,ins_id,[]]

Order Book clear:

[1,1,[]]

Response Order Book snapshot

[2,ins_id,[[price,volume]]]

Order Book snapshot:

[2,1,[
        [1622497,-21488],
        [1622498,-11753],
        [1622499,8598]
     ]
]
Parameter Required Type Description
ins_id true uint16 Instrument ID
price true int32 Order Book level price
volume true int32 Order Book level volume

Response Order Book incremental changes

[3,ins_id,[[price,volume]]]

Order Book incremental changes:

[3,1,[
        [1622497,-2148],
        [1622498,0],
        [1622499,8248]
     ]
]
Parameter Required Type Description
ins_id true uint16 Instrument ID
price true int32 Order Book level price
volume true int32 Order Book level volume

Order Book update logic

Trades

Trades subscribe:

// Subscribe on trades for ins_id = 1
socket.send('[1102, [1]]');

// Subscribe on trades for ins_id = 1 and 2
socket.send('[1102, [1, 2]]');

Request Trades subscribe

[1102,[ins_id]]

Trades unsubscribe:

// Unsubscribe on trades for ins_id = 1
socket.send('[1103, [1]]');

// Unsubscribe on trades for ins_id = 1 and 2
socket.send('[1103, [1, 2]]');

Request Trades unsubscribe

[1103,[ins_id]]

Response Trades clear

[4,ins_id,[]]

Trades clear:

[4,1,[]]

Response trades snapshot

[5,ins_id,[[price,volume,timestamp]]]

Trades snapshot:

[5,1,[
        [1620580,75,1513216484],
        [1620589,33,1513216784],
        [1620589,365,1513266784],
        [1620887,37,1513246631]
     ]
]
Parameter Required Type Description
ins_id true uint16 Instrument ID
price true int32 Deal price
volume true int32 Deal volume
timestamp true uint64 Deal time in sec, since Jan 01 1970. (UTC)

Response trades incremental changes

[6,ins_id,[[price,volume,timestamp]]]

Trades incremental changes:

[6,1,[
        [1619715,-4100,1513217115],
        [1619713,-876,1513217115],
        [1619713,5,1513217117]
     ]
]
Parameter Required Type Description
ins_id true uint16 Instrument ID
price true int32 Deal price
volume true int32 Deal volume
timestamp true uint64 Deal time in sec, since Jan 01 1970. (UTC)

Trades update logic

Authentication

Use ApiKey and private key for authorization.

For authorization use this code:

ApiKey = "ieW-nrNVN4qFJsMEiwtVqyjA";
Secret = "5fMhM8dqOzWs22heuSETNw_ED3BuXx_TBTboKJKlS8bFLIrm";

Nonce = "1510929522353"
Signature = HMAC_SHA256(Nonce, Secret)

socket.send('[1000,[ApiKey,Nonce,Signature]]');
// Authorization success response
[1001,[1,"Welcome to bitex.one Realtime API."]]
// Authorization error response
[1001,[16]]

Example message:

socket.send('[1000,["ieW-nrNVN4qFJsMEiwtVqyjA","1510929522353","2e82ed97579f24976295cd895e071402c1776612015e15d1acff112885ae6c91"]]');

Request

[1000,[api_key,nonce,signature]]

Request parameters

Parameter Required Type Description
api_key true string API key
nonce true string Nonce must be a number
signature true string Signature

Response

[1001,[code,message]]

Parameter Required Type Description
code true uint8 Result code
message false string Message string

Order Snapshot

If authorization succeed client gets orders snapshot

Response clear

Response Clear:

// Clear all client orders
[110,[]]

[110,[]]

Response snapshot

Response Snapshot:

// All orders snapshot
[111,[
        [2,1,100000007,72050,64,1,1534029000],
        [1,1,100000005,720510000000,-64050000,1,1534029000]
     ]
]

[111,[[client_order_id,ins_id,order_id,price,volume,status,time]]]

Response parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order id
ins_id true uint16 Instrument ID
order_id true uint64 System order ID
price true int32 Order price
volume true int32 Order volume in contracts
status true uint8 Order status
time true uint64 Time of last order change in sec, since Jan 01 1970. (UTC)

Volume

Status

Value Description
0 Order canceled
1 Order added
2 Order executed

Position Snapshot

If authorization succeed client gets positions snapshot

Response clear

Response Clear:

// Clear all client positions
[112,[]]

[112,[]]

Response snapshot

Response Snapshot:

// Snapshot all client positions
[113,[
        [9,18462520000001,-2000],
        [1,630330330000000,1000]
     ]
]

[113,[[ins_id,price_avg,volume]]]

Response parameters

Parameter Required Type Description
ins_id true uint16 Instrument identificator
price_avg true int64 Average price multiplied by 10^10
volume true int32 Position volume

volume

Balance Snapshot

All balance values in satoshi (1 satoshi = 0.00000001 BTC).

Response snapshot

Response Snapshot:

// Balance snapshot
[114,[2480662205,5754608835,35127000,0,7025400,-810125,5753798710,5718671710,2963326]]

[114,[realized_pnl,wallet_balance,position_margin,order_margin,maintenance_margin,
unrealized_pnl,margin_balance,available_balance,referral_profit]]

Response parameters

Parameter Required Type Description
realized_pnl true int64 Realized profit and loss
wallet_balance true int64 Funds on account exclude unrealized_pnl
position_margin true int64 Margin, reserved by all open positions
order_margin true int64 Margin, reserved by all active orders
maintenance_margin true int64 Critical level of margin. When wallet_balance < maintenance_margin liquidation begins
unrealized_pnl true int64 Sum profit by all open positions
margin_balance true int64 wallet_balance + unrealized_pnl
available_balance true int64 wallet_balance - position_margin - order_margin + unrealized_pnl
referral_profit true int64 Refferal program profit

Order

Add Order

Request

[100,[[client_order_id,ins_id,price,volume,type]]]

Add Order:

// Add sell order
socket.send('[100,[[1,1,72051,-64,1]]]');
// Matching response, order placed
[100,[
        [1,1,100000046,72051,-64,1,0,0,0,0,1526781600,0]
     ]
]
// Add sell and buy orders
socket.send('[100,[[1,1,72051,-64,1],[2,1,72050,64,1]]]');
// Matching response
// Partial first order execution
// First order executed fully
// Second order placed
[100,[
        [1,1,100000047,72051,-64,2,230981,1649637,-50,-14,1526781600,2120],
        [1,1,100000047,72051,-14,2,230982,1649500,-14,0,1526781600,636],
        [2,1,100000048,72050,64,1,0,0,0,0,1526781600,0]
     ]
]

// Add sell and buy orders
socket.send('[100,[[1,1,72051,-64,1],[2,1,72050,64,1]]]');
// Error response. Error code = 18 (NoMoney)
[200,[[1,18],[2,18]]]

Request parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order ID
ins_id true uint16 Instrument ID
price true int32 Order price
volume true int32 Order volume
type true uint8 Order type

volume

type

Value Description
1 Limit.
2 Market.

Error response message

[200,[[client_order_id,code]]]

Error response message parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order ID
code true uint8 Error code

Response matching engine parameters

[100,[[client_order_id,ins_id,order_id,price,volume,type,deal_id,deal_price,deal_volume,leaves_volume,time,fee]]]

Parameter Required Type Description
client_order_id true uint32 Client defined order ID
ins_id true uint16 Instrument ID
order_id true uint64 Order system ID
price true int32 Order price
volume true int32 Order volume
type true uint8 Type of action with order
deal_id true uint64 Deal system ID
deal_price true int32 Deal price
deal_volume true int32 Deal volume
leave_volume true int32 Leave volume in order
time true uint64 Time operation in sec, since Jan 01 1970. (UTC)
fee true int32 Comission for operation in satoshi

type

Value Description
0 Order canceled
1 Order added
2 Order executed
3 Order canceled due to order move
4 Order canceled due to contract expiration
5 Deal generated by expiration module
6 Funding transaction
7 Deleverege module deal
8 Liquidation module order add
9 Liquidation module order cancel
10 Liquidation position deal
11 Risk management order cancel
12 Deleverage module order cancel

Move Order

Request

[101,[[client_order_id,ins_id,order_id,price,volume]]]

Move Order:

// Move buy order
socket.send('[101,[[2,1,100000048,72150,30]]]');
// Order canceled due to order move (type=3)
// Order placed (type=1)
[100,[
        [2,1,100000048,72050,64,3,0,0,0,0,1526781600,0],
        [2,1,100000049,72150,30,1,0,0,0,0,1526781600,0]
     ]
]
// Move two orders request
socket.send('[101,[[1,1,100000048,72051,-64,1],[2,1,100000047,72050,64,1]]]');
// Error response. Error code = 15 (OrderNotFound) 
[201,[[1,15],[2,15]]]
// Move two orders request
socket.send('[101,[[2,1,100000001,72150,30],[1,1,100000000,72051,-64]]]');
// Matching response. First order move succsess
[100,[
        [2,1,100000001,72050,64,3,0,0,0,0,1526781600,0],
        [2,1,100000002,72150,30,1,0,0,0,0,1526781600,0]
     ]
]
// Error response. Error code = 15 (OrderNotFound), 
[201,[[1,15]]]

Request parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order ID
ins_id true uint16 Instrument ID
order_id true uint64 Order system ID
price true int32 Order price
volume true int32 New order volume

Error response message

[201,[[client_order_id,code]]]

Error response message parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order ID
code true uint8 Response code

Cancel Order

Request

[103,[[client_order_id,ins_id,order_id]]]

Cancel Order:

// Cancel order
socket.send('[103,[[1,1,100000002]]]');
socket.send('[103,[[2,1,100000005]]]');
// Matching response
[100,[
        [1,1,100000002,72150,30,0,0,0,0,0,1526781600,0],
        [2,1,100000005,72350,30,0,0,0,0,0,1526781600,0]
     ]
]
// Cancel two orders
socket.send('[103,[[1,1,100000003],[2,1,100000004]]]');
// Matching response. Second order canceled 
[100,[
        [2,1,100000004,72050,64,0,0,0,0,0,1526781600,0]
     ]
]
// Matching response. Error code = 15 (OrderNotFound) 
[203,[[1,15]]]

Request parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order id
ins_id true uint16 Instrument ID
order_id true uint64 System order id

Error response message

[203,[[client_order_id,code]]]

Error response message parameters

Parameter Required Type Description
client_order_id true uint32 Client defined order id
code true uint8 Response code

Flood control system

Principle of operation

Example of the response message of the flood control system:

// 400 - GeneralError message, 23 - FloodControl error code
[400,[23]]

The client has 100 points, which can be used to send messages to the server. Each sent message reduces them by 1. Points are restored, 1 point every 600 ms. The developer on his side should implement a flood control system and ensure that the number of points does not reach 0.

Penalties

If the points of the flood control system have dropped below 0, the developer will receive a message 400 (GeneralError) with error code 23 (FloodControl) on every sended message. If points dropped below -10 then the connection will forcibly terminate. If the flood control system terminate connection 3 times in an hour, the client will be blocked by the IP address for 1 hour. In the event that the flood control system is terminate connection 6 times in 24 hours, the client will be blocked by the IP on 24 hours.

Commands

Websocket API uses next commands

Public request

Code Name Description
1000 AuthorizationRequest Authorization request
1100 SubscribeOrderBook Subscribe to order book of a specific instrument
1101 UnSubscribeOrderBook Unsubscribe to order book of a specific instrument
1102 SubscribeTrade Subscribe to trades of a specific instrument
1103 UnSubscribeTrade Unsubscribe to trades of a specific instrument
1104 InstrumentParamsRequest Request all instrument parameters

Public response

Code Name Description
1 OrderBookClearResponse Clear order book of a specific instrument
2 OrderBookSnapshotResponse Snapshot of order book
3 OrderBookIncrementalResponse Incremental messages for order book
4 TradeClearResponse Clear trades of specific instrument
5 TradeSnapshotResponse Snapshot of trades
6 TradeIncrementalResponse Incremental messages for trades
400 GeneralErrorResponse General error message
1001 AuthorizationResponse Authorization response message
1105 InstrumentParamsResponse Request all instrument parameters
1107 InstrumentStatisticResponse Instrument statistic message

Authorized request

Code Name Description
100 AddOrderRequest Add order request
101 MoveOrderNewVolumeRequest Move order request
103 CancelOrderRequest Cancel order request

Authorized response

Code Name Description
100 MatchingEngineResponse Message from matching engine
110 ClientOrderClearResponse Clear client orders
111 ClientOrderSnapshotResponse Client orders snapshot
112 PositionClearResponse Clear client positions
113 PositionSnapshotResponse Client positions snapshot
114 BalanceResponse Client balance message
200 AddOrderResponse Add order error message
201 MoveOrderNewVolumeResponse Move order error message
203 CancelOrderResponse Cancel order error message

Error codes

All API messages use the following error codes.

Code Name Description
1 Accept Operation completed successfully
2 WrongDataFormat Wrong format of JSON
3 InstrumentNotFound Instrument not found in system
4 LotLimitExceeds Lot limit exceeds
5 IncorrectLotStep Lot must be integer type
6 PriceLimitExceeds Price value out of limit
7 IncorrectPriceStep Price is not a multiple of the minimum step
8 IncorrectOrderType Incorrect order type
9 IncorrectClientOrderID Incorrect value in client_order_id field
10 IncorrectOrderID Incorrect value in order_id field
11 IncorrectFieldType Incorrect field type
12 TooMuchOrders Too many orders in batch
13 UnknownCommand Uncnown command code
14 AuthorizationRequired Authorization required
15 OrderNotFound Order with order_id not found in system
16 AuthorizationError Authorization error
17 Liquidation Liquidation process
18 NoMoney Not enoth money for operation
19 OrderLessThanOne Order volume less than one
20 TradeDisabled Trade disabled
21 NotEnothLiquidity Not enoth liquidity for operation
22 MaxPosExceeds Exceeds max position for current instrument
23 FloodControl Flood control points decreased to 0
24 InstrumentExpirated Instrument already expirated