Websocket API v2
What Is WebSocket?
WebSocket is a protocol providing full-duplex communications channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C.
Connection
Qovex uses its implementation of websocket server for real time data streaming. Server is accessible on the following address: wss://ws.bitstamp.net.
Documentation about websocket protocol can be found on the following link: https://websockets.readthedocs.io/en/stable/.
Once you open a connection via websocket handshake (using HTTP upgrade header), you can subscribe to desired channels.
After this is accomplished, you will start to receive a stream of live events for every channel you are subscribed to.
Subscriptions
Public channels
To subscribe to a channel, JSON message must be sent to the server. It should have a following structure:
{
"event": "bts:subscribe",
"data": {
"channel": "[channel_name]"
}
}
Private channels
To subscribe to a channel, JSON message must be sent to the server. It should have a following structure:
{
"event": "bts:subscribe",
"data": {
"channel": "[channel_name]-[user-id]", "auth": "[token]"
}
}
Token value and user id are generated via HTTP API. See Websockets token section of HTTP API documentation here.
Unsubscriptions
You can also unsubscribe from the channel if you no longer need its stream. Again, you need to send a message to the server.
Its structure is nearly identical to the subscription JSON:
{
"event": "bts:unsubscribe",
"data": {
"channel": "[channel_name]"
}
}
Note: Messages described and defined in this article are the only ones that will be processed by the server. Any other form of message or correct form of message with unexpected content will result in an error response.
Channels
Currency pairs: btcusd, btceur, btcgbp, gbpusd, eurusd, xrpusd, xrpeur, xrpbtc, xrpgbp, ltcbtc, ltcusd, ltceur, ethbtc, ethusd, etheur, ethgbp, bchusd, bcheur, bchbtc, xlmbtc, xlmusd, xlmeur, xlmgbp, linkusd, linkeur, linkgbp, linkbtc, usdcusd, usdceur, btcusdc, ethusdc, eth2eth, aaveusd, aaveeur, aavebtc, batusd, bateur, umausd, umaeur, daiusd, kncusd, knceur, mkrusd, mkreur, zrxusd, zrxeur, algousd, algoeur, audiousd, audioeur, crvusd, crveur, snxusd, snxeur, uniusd, unieur, unibtc, yfiusd, yfieur, compusd, compeur, grtusd, grteur, lrcusd, lrceur, usdtusd, usdteur, usdcusdt, btcusdt, ethusdt, xrpusdt, flrusd, flreur, manausd, manaeur, maticusd, maticeur, sushiusd, sushieur, chzusd, chzeur, enjusd, enjeur, hbarusd, hbareur, axsusd, axseur, sandusd, sandeur, storjusd, storjeur, adausd, adaeur, adabtc, fetusd, feteur, sklusd, skleur, slpusd, slpeur, sgbusd, sgbeur, avaxusd, avaxeur, dydxusd, dydxeur, ftmusd, ftmeur, shibusd, shibeur, ampusd, ampeur, ensusd, enseur, galausd, galaeur, perpusd, perpeur, wbtcbtc, ctsiusd, ctsieur, imxusd, imxeur, nexousd, nexoeur, radusd, radeur, bandusd, bandeur, injusd, injeur, rlyusd, rlyeur, rndrusd, rndreur, 1inchusd, 1incheur, solusd, soleur, apeusd, apeeur, eurocusdc, euroceur, dotusd, doteur, nearusd, neareur, ldousd, ldoeur, dgldusd, dgldeur, dogeusd, dogeeur, suiusd, suieur, eurcvusdt, eurcveur, pyusdusd, pyusdeur, tracusd, traceur, wecanusd, wecaneur, blurusd, blureur, lmwrusd, lmwreur, pepeusd, pepeeur, vextusd, vexteur, csprusd, cspreur, gyenusd, vchfusd, vchfeur, veurusd, veureur, zusdusd, bonkusd, bonkeur, jupusd, jupeur, pythusd, pytheur, wifusd, wifeur, ondousd, ondoeur, smtusd, smteur, trufusd, trufeur, egldusd, egldeur, icpusd, icpeur, xdcusd, xdceur, coreumusd, coreumeur, flokiusd, flokieur, strkusd, strkeur, xchngusd, xchngeur, ctxusd, ctxeur, mogusd, mogeur, wenusd, weneur, arbusd, arbeur, xsgdusd, xsgdusdt, zetausd, zetaeur, mewusd, meweur, rlusdusd, rlusdeur, rlusdusdt, btcrlusd, xrprlusd, ethrlusd, woousd, wooeur, seiusd, seieur, opusd, opeur, bomeusd, bomeeur, cxtusd, cxteur, popcatusd, popcateur, syrupusd, syrupeur, melaniausd, melaniaeur, trumpusd, trumpeur
Below tables include definitions of all existing channels you can subscribe to. Replacing [channel_name] placeholder in one of JSON messages defined in previous paragraphs will subscribe or unsubscribe you to a channel. You also need to replace [currency_pair] placeholder with one of pairs defined at the beginning of this paragraph.
Public channels
Name | Event | Channel |
Live ticker | trade | live_trades_[currency_pair] |
Live orders | order_created, order_changed or order_deleted | live_orders_[currency_pair] |
Live order book | data | order_book_[currency_pair] |
Live detail order book | data | detail_order_book_[currency_pair] |
Live full order book | data | diff_order_book_[currency_pair] |
Private channels
Name | Event | Channel |
Private My Orders | order_created, order_changed or order_deleted | private-my_orders_[currency_pair] |
Private My Trades | trade | private-my_trades_[currency_pair] |
Private Live Trades | self_trade | private-live_trades_[currency_pair] |
Channel JSON structure
Live ticker - JavaScript example: live_trades_v2.html
Property | Description |
id | Trade unique ID. |
id_str | Trade unique ID represented in string format. |
amount | Trade amount. |
amount_str | Trade amount represented in string format. |
price | Trade price. |
price_str | Trade price represented in string format. |
type | Trade type (0 - buy; 1 - sell). |
timestamp | Trade timestamp. |
microtimestamp | Trade microtimestamp. |
buy_order_id | Trade buy order ID. |
sell_order_id | Trade sell order ID. |
Live order book - JavaScript example: order_book_v2.html
Property | Description |
bids | List of top 100 bids. |
asks | List of top 100 asks. |
timestamp | Order book timestamp. |
microtimestamp | Order book microtimestamp. |
Live detail order book
Property | Description |
bids | List of top 100 bids [price, amount, order id]. |
asks | List of top 100 asks [price, amount, order id]. |
timestamp | Order book timestamp. |
microtimestamp | Order book microtimestamp. |
Live full order book - JavaScript example: diff_order_book_v2.html
Property | Description |
bids | List of changed bids since last broadcast. |
asks | List of changed asks since last broadcast. |
timestamp | Order book timestamp. |
microtimestamp | Order book microtimestamp. |
Live orders - JavaScript example: live_orders_v2.html
Property | Description |
id | Order ID. |
amount | Order amount. |
amount_str | Order amount represented in string format. |
price | Order price. |
price_str | Order price represented in string format. |
order_type | Order type (0 - buy; 1 - sell). |
datetime | Order datetime. |
microtimestamp | Order action timestamp represented in microseconds. |
Private My Orders
Property | Description |
id | Order ID. |
id_str | Order ID represented in string format. |
client_order_id | Client order ID (if used when placing order). |
amount | Order amount left to be executed. |
amount_str | Order amount left to be executed represented in string format. |
amount_traded | Executed order amount represented in string format. |
amount_at_create | Original order amount represented in string format. |
price | Order price. |
price_str | Order price represented in string format. |
order_type | Order type (0 - buy, 1 - sell). |
datetime | Order datetime. |
microtimestamp | Order action timestamp represented in microseconds. |
trade_account_id | ID of related trade account (0 for main account, Unique ID for sub accounts). |
Private My Trades
Property | Description |
id | Trade ID. |
id_str | Trade unique ID represented in string format. |
order_id | Order ID associated with the trade. |
client_order_id | Client order ID associated with the trade. |
amount | Trade amount. |
price | Trade price. |
fee | Trade fee. |
side | Trade side (buy or sell). |
microtimestamp | Trade timestamp represented in microseconds. |
trade_account_id | ID of related trade account (0 for main account, Unique ID for sub accounts). |
Private Live Trades
Note: Private-live_trades channels only broadcast self_trade events. Self-trade events occur when orders from the same client are matched against each other and offset against each other instead of executing as a trade due to self-trading prevention.
Property | Description |
buy_order_id | Buy order id. |
sell_order_id | Sell order id. |
amount | Trade amount. |
amount_str | Trade amount represented in string format. |
price | Trade price. |
price_str | Trade price represented in string format. |
type | Order type (0 - buy; 1 - sell). |
timestamp | Timestamp represented in seconds. |
microtimestamp | Timestamp represented in microtimestamp. |
sellers_trade_account_id | ID of related trade account to sell order (0 for main account, Unique ID for sub accounts). |
buyers_trade_account_id | ID of related trade account to buy order (0 for main account, Unique ID for sub accounts). |
Other technical information
1. Heartbeat
If you wish to determine that websocket server is responsive, you should do so by websocket heartbeat. This is a form of control message or "PING / PONG" communication. You can do so by sending the following JSON message to the server:
{
"event": "bts:heartbeat"
}
2. Forced reconnection
In case of websocket server you are currently connected to is to go under maintenance, you will receive a warning message asking you to reconnect. Such a message will look like this:
{
"event": "bts:request_reconnect",
"channel": "",
"data": ""
}
After you receive this request, you will have a few seconds to reconnect. Without doing so, you will automatically be disconnected. If you send reconnection request, you will be placed to a new server. Consequentially, you can continue without any message loss.
3. Maximum connection age
Maximum connection age is 90 days from the time the connection is established. When that period of time elapses, you will be automatically disconnected and will need to re-connect.