bbo
Stream real-time best bid and offer for a coin.
Last updated
{
"method": "subscribe",
"subscription": {
"type": "bbo",
"marketTypes": ["perp", "outcome"]
}
}{
"method": "unsubscribe",
"subscription": {
"type": "bbo",
"coin": "BTC"
}
}{
"type": "bbo",
"channel": "bbo",
"seq": 5,
"cursor": "0",
"data": {
"coin": "BTC",
"time": 1704067200000,
"bbo": [
{"px": "70325", "sz": "12.5", "n": 3},
{"px": "70326", "sz": "8.3", "n": 2}
]
}
}const WebSocket = require('ws');
const ws = new WebSocket(`wss://api.hydromancer.xyz/ws?token=${process.env.HYDROMANCER_API_KEY}`);
ws.on('message', (data) => {
const msg = JSON.parse(data);
if (msg.type === 'connected') {
ws.send(JSON.stringify({
method: 'subscribe',
subscription: { type: 'bbo', coin: 'BTC' }
}));
} else if (msg.type === 'ping') {
ws.send(JSON.stringify({ type: 'pong' }));
} else if (msg.channel === 'bbo') {
const { coin, time, bbo } = msg.data;
const [bid, ask] = bbo;
console.log(`${coin}: bid=${bid?.px} ask=${ask?.px}`);
}
});import websocket
import json
import os
def on_message(ws, message):
msg = json.loads(message)
if msg['type'] == 'connected':
ws.send(json.dumps({
"method": "subscribe",
"subscription": {"type": "bbo", "coin": "BTC"}
}))
elif msg['type'] == 'ping':
ws.send(json.dumps({'type': 'pong'}))
elif msg.get('channel') == 'bbo':
d = msg['data']
bid, ask = d['bbo']
print(f"{d['coin']}: bid={bid['px'] if bid else 'n/a'} ask={ask['px'] if ask else 'n/a'}")
ws = websocket.WebSocketApp(
f"wss://api.hydromancer.xyz/ws?token={os.environ.get('HYDROMANCER_API_KEY')}",
on_message=on_message
)
ws.run_forever()