Skip to main content

WebSocket Trading Bot

Build a real-time bot that reacts to price changes instantly via WebSocket streaming, instead of polling the REST API.

Architecture


Full Source Code


Why WebSocket Over Polling?

Use REST API for order placement and account queries. Use WebSocket for price monitoring and signal detection.

Connection Management

WebSocket tokens expire after 60 seconds. Your bot must handle reconnection:
  1. Detect close/error events
  2. Request a new token via POST /v1/keys/ws-token
  3. Re-subscribe to all markets

Next Steps