Overview
The Bison API provides real-time market and event data streams via WebSockets. This allows you to receive updates as they happen, rather than polling for updates at fixed intervals.Available WebSocket Endpoints
Bison provides three WebSocket endpoints for different use cases:User Events
Receive updates about your orders, positions, and balances
Market Tickers
Stream live market data for all markets in an event
Orderbook Data
Get real-time orderbook snapshots and deltas
Connection Pattern
All WebSocket endpoints follow the same connection pattern:1
Establish Connection
Connect to the WebSocket endpoint using the
wss:// protocol (or ws:// for local development).2
Handle Messages
Listen for JSON-formatted messages containing real-time updates.
3
Send Heartbeats
Send ping messages every 30 seconds to keep the connection alive.
4
Handle Disconnection
Implement reconnection logic with exponential backoff if the connection drops.
Heartbeat Mechanism
To keep connections alive, send a ping message every 30 seconds:Reconnection Strategy
When a connection closes unexpectedly, implement exponential backoff for reconnection:- First retry: 1 second delay
- Second retry: 2 seconds delay
- Third retry: 4 seconds delay
- Fourth retry: 8 seconds delay
- Fifth retry: 16 seconds delay
- Maximum retry: 30 seconds delay
Error Handling
WebSocket connections can fail for various reasons. Implement proper error handling:Best Practices
1
Always Send Heartbeats
Send ping messages every 30 seconds to prevent connection timeouts.
2
Implement Reconnection
Use exponential backoff to reconnect after disconnections.
3
Handle Partial Updates
For orderbook data, start with the snapshot and apply deltas incrementally.
4
Validate Messages
Always parse and validate incoming JSON messages before processing.
5
Clean Up Resources
Clear intervals and close connections when you’re done listening.
Next Steps
Explore the message formats for each WebSocket endpoint:- User Events - Order, position, and balance updates
- Market Tickers - Live bid/ask prices and volume
- Orderbook Data - Real-time order book depth