Token trading
OKEx Contract WebSocket URL:wss://real.okex.com:10440/websocket/okexapi
OKEx Spot WebSocket URL:wss://real.okex.com:10441/websocket
Send Request

Request Data Format: {'event':'addChannel','channel':'channelValue','parameters':{'api_key':'value1','sign':'value2'}}.
Note: 'event':'addChannel'(register request)/'removeChannel'(unregister request)
'channel': OKEX provided data type.
'parameters': optional field
binary optional field,compression value: 1 compression data ,0 decompression data default 0 'api_key' and 'secret_key' is apply 'apiKey' and 'secretKey' for users.
Example:
websocket.send("{'event':'addChannel','channel':'ok_btcusd_ticker','binary':'1' }")
websocket.send("[{'event':'addChannel','channel':'ok_btcusd_ticker'},{'event':'addChannel','channel':'ok_btcusd_depth'},{'event':'addChannel','channel':'ok_btcusd_trades'}]"); Support batch register

Server Response

Return Data Format:

[{"channel":"channel","success":"","errorcode":"","data":{}},{"channel":"channel","success":"","errorcode":1,"data":{}}]
channel: requested data type
result: true,false(applicable to WebSocket Trade API)
data: returned data
errorcode: error code(applicable to WebSocket Trade API)
Error Code Description
10000 Required parameter is empty
10001 Illegal parameters
10002 Authentication failure
10003 This connection has requested other user data
10004 This connection did not request this user data
10005 api_key or sign is invalid
10008 Parameter erorr
10009 Order does not exist
10010 Insufficient funds
10011 Order quantity too low
10012 Only support btc_usd ltc_usd
10014 Order price must be between 0 - 1,000,000
10015 Channel subscription temporally not available
10016 Insufficient coins
10017 WebSocket authorization error
10100 user frozen
10216 non-public API
10049 User can not have more than 50 unfilled small orders (amount<0.15BTC)
20001 user does not exist
20002 user frozen
20003 frozen due to force liquidation
20004 contract account frozen
20005 user contract account does not exist
20006 required field can not be null
20007 illegal parameter
20008 contract account fund balance is zero
20009 contract status error
20010 risk rate information does not exist
20011 risk rate bigger than 90% before opening position
20012 risk rate bigger than 90% after opening position
20013 temporally no counter party price
20014 system error
20015 order does not exist
20016 liquidation quantity bigger than holding
20017 not authorized/illegal order ID
20018 order price higher than 105% or lower than 95% of the price of last minute
20019 IP restrained to access the resource
20020 secret key does not exist
20021 index information does not exist
20022 wrong API interface
20023 fixed margin user
20024 signature does not match
20025 leverage rate error
20100 request time out
20101 the format of data is error
20102 invalid login
20103 event type error
20104 subscription type error
20107 JSON format error
20115 The quote is not match
20116 Param not match
1002 The transaction amount exceed the balance
1003 The transaction amount is less than the minimum requirement
1004 The transaction amount is less than 0
1007 No trading market information
1008 No latest market information
1009 No order
1010 Different user of the cancelled order and the original order
1011 No documented user
1013 No order type
1014 No login
1015 No market depth information
1017 Date error
1018 Order failed
1019 Undo order failed
1024 Currency does not exist
1025 No chart type
1026 No base currency quantity
1027 Incorrect parameter may exceeded limits
1028 Reserved decimal failed
1029 Preparing
1030 Account has margin and futures, transactions can not be processed
1031 Insufficient Transferring Balance
1032 Transferring Not Allowed
1035 Password incorrect
1036 Google Verification code Invalid
1037 Google Verification code incorrect
1038 Google Verification replicated
1039 Message Verification Input exceed the limit
1040 Message Verification invalid
1041 Message Verification incorrect
1042 Wrong Google Verification Input exceed the limit
1043 Login password cannot be same as the trading password
1044 Old password incorrect
1045 2nd Verification Needed
1046 Please input old password
1048 Account Blocked
1201 Account Deleted at 00: 00
1202 Account Not Exist
1203 Insufficient Balance
1204 Invalid currency
1205 Invalid Account
1206 Cash Withdrawal Blocked
1207 Transfer Not Support
1208 No designated account
1209 Invalid api
Data Push Process

To reduce data size and ensure real-time data push, 'ticker' and 'depth' will only be pushed only when new data is available. 'trades' is newly completed transactions from previous data push to this data push.

How to know whether connection is lost?

OKEX provides heartbeat verification process. Clients send: {'event':'ping'} per 30 seconds, the server returns heartbeats {"event":"pong"} to indicate connection between the clients and the server. If the clients stop receiving the heartbeats, then they will need to reconnect with the server.

提示

请先登录

客服+852 5808 5768
在线咨询 在线咨询
在线留言 发起提问
聊天室
OKEX聊天室
请遵守聊天室规则!详情>>
客服+852 5808 5768
聊天室规则 X