Subscribing & Unsubscribing
Subscribing or unsubscribing to WebSocket feeds
Once connected to the WebSocket API you can subscribe to various feeds using the subscribe or unsubscribe command.
These commands should be JSON with the following properties:
Property
Type
Description
type
string
Command you are sending to the websocket (subscribe or unsubscribe)
feeds
string[]
List of the feeds that should be subscribed/unsubscribed to
NodeJS
Python
const subscribeMsg = {
type: 'subscribe',
feeds: ['ticker.sfox.btcusd']
}
ws.send(JSON.stringify(subscribeMsg));
...
const unsubscribeMsg = {
type: 'unsubscribe',
feeds: ['ticker.sfox.btcusd']
}
ws.send(JSON.stringify(unsubscribeMsg))
subscribe_msg = {
"type": "subscribe",
"feeds": ["ticker.sfox.btcusd"],
}
await ws.send(json.dumps(subscribe_msg))
...
unsubscribe_msg = {
"type": "unsubscribe",
"feeds": ["ticker.sfox.btcusd"],
}
await ws.send(json.dumps(unsubscribe_msg))
Copy link