const WebSocket = require('ws')
const ws = new WebSocket('wss://ws.sfox.com/ws')
ws.on('open', function() {
const authMessage = {
type: 'authenticate',
apiKey: '<ENTERPRISE_API_KEY>',
enterprise: 'true'
}
ws.send(JSON.stringify(authMessage))
})
// After successful authentication, subscribe to trades feed
const subscribeMsg = {
type: 'subscribe',
feeds: ['trades.sfox.btcusd', 'trades.sfox.ethusd']
}
ws.send(JSON.stringify(subscribeMsg))
import asyncio
import json
import websockets
async def main(uri):
async with websockets.connect(uri) as ws:
await ws.send(json.dumps({
"type": "authenticate",
"apiKey": "<ENTERPRISE_API_KEY>",
"enterprise": "true"
}))
# After successful authentication message, subscribe to the trades feed
await ws.send(json.dumps({
"type": "subscribe",
"feeds": ["trades.sfox.btcusd"]
}))
async for msg in ws:
print(msg)
asyncio.run(main("wss://ws.sfox.com/ws"))
{
"sequence": 24,
"recipient": "trades.sfox.btcusd",
"timestamp": 1649901441593380244,
"payload": {
"id": "1062696823",
"quantity": "0.005",
"price": "41492",
"exchange": "market1",
"exchange_id": 2,
"side": "buy",
"pair": "btcusd",
"pair_id": 1,
"timestamp": "2022-04-14T01:57:21.521999872Z",
"timeStamp": "2022-04-14T01:57:21.521",
"buyOrderId": "",
"sellOrderId": "",
"is_decimal": true
}
}