How to use WebSocket API
ProBit Global WebSocket API communicates in JSON string.
Each single request messege should contain single valid JSON string.
WebSocket API entry point is wss://api.probit.com/api/exchange/v1/ws
.
In case of Demo API:
wss://demo-api.probit.com/api/exchange/v1/ws
Each key and string value of JSON string should be double-quoted("") and should not contain any line breaks.
import websocket from 'websocket';
const ws = new websocket.w3cwebsocket('wss://api.probit.com/api/exchange/v1/ws');
ws.onopen = () => {
const msg = {
type: 'subscribe',
channel: 'marketdata',
interval: 500,
market_id: 'BTC-USDT',
filter: ['ticker', 'order_books']
};
ws.send(JSON.stringify(msg));
};
ws.onmessage = (event) => {
console.log(event.data);
};
Channels
ProBit Global WebSocket API provides channels to subscribe.
You may subscribe multiple channels simultaneously which are listed below.
marketdata
exchange_rate
open_order
(Authorization required)trade_history
(Authorization required)order_history
(Authorization required)balance
(Authorization required)
Use "type":"subscribe"
or "type":"unsubscribe"
message to subscribe or unsubscribe respectively and put channel name to subscribe with channel
field.
Multiple requests in same channel updates the existing channel subscription. (In case of marketdata
, refer Marketdata section)
Additional fields for each channel should be contained in the message which can be found in API Reference.
{"type":"subscribe","channel":"marketdata","market_id":"ETH-BTC","interval":100,"filter":["ticker","order_books_l0"]}
{"type":"subscribe","channel":"exchange_rate","filter":["BTC"]}
{"type":"unsubscribe","channel":"marketdata","market_id":"ETH-BTC"}
{"type":"unsubscribe","channel":"exchange_rate"}
Authorization
In order to subscribe channels which require authorization, the connection should be authorized with "type":"authorization"
message. Specify access_token acquired by Authorization API in token
field.
A single authorization could be used subscribing authorization required channels and remains until the end of the connection.
Refer API Reference to more information.
{"type":"authorization","token":"ACCESS_TOKEN"}
{"type":"subscribe","channel":"order_history"}
{"type":"subscribe","channel":"trade_history"}
{"type":"unsubscribe","channel":"order_history"}
{"type":"unsubscribe","channel":"trade_history"}
Marketdata Channel
For more information, see API Reference
marketdata
is public channel which do not require authorization
If you subscribe to marketdata
several times, you can subscribe or unsubscribe multiple times for each 'market_id'.
If you subscribe several times to one market, your subscription will change based on the latest message
The parameters required to subscribe to the marketdata
channel are market_id
, interval
, filter
market_id
: market ID to subscribe or unsubscribeinterval
: Unit time to synchronize market information (ms
)- Available units: 100, 500
filter
: Information you want to receive from the marketticker
recent_trades
order_books
order_books_l0
It does not apply aggregate view, aggregate view is provided in 4 stepsorder_books_l1
order_books_l2
order_books_l3
order_books_l4
{"type":"subscribe","channel":"marketdata","market_id":"ETH-BTC","interval":100,"filter":["ticker","recent_trades","order_books_l0","order_books_l1","order_books_l2","order_books_l3","order_books_l4"]}
{"type":"subscribe","channel":"marketdata","market_id":"ETH-USDT","interval":500,"filter":["ticker"]}
{"type":"subscribe","channel":"marketdata","market_id":"EOS-BTC","interval":100,"filter":["order_books_l0"]}
{"type":"subscribe","channel":"marketdata","market_id":"EOS-BTC","interval":100,"filter":["ticker"]}
{"type":"unsubscribe","channel":"marketdata","market_id":"ETH-USDT"}
{"type":"unsubscribe","channel":"marketdata","market_id":"EOS-BTC"}
Updated almost 2 years ago