Purpose
The WebSocket API allows you to:- Monitor order lifecycle events in real-time (creation, fills, cancellations)
- Track order state changes like balance and allowance updates
- Receive instant notifications when order status changes
- Access active orders through RPC methods
- Implement custom WebSocket providers for specialized use cases
When to Use WebSocket vs REST
Use WebSocket API when:
- You need real-time updates on order status changes
- You want to monitor multiple orders simultaneously
- You’re building interactive UIs that require instant feedback
- You need to react immediately to order fills or cancellations
- You want to reduce polling overhead for order status checks
Use REST API when:
- You need to fetch historical data or one-time queries
- You’re performing administrative operations like creating quotes
- You want simpler implementation for basic use cases
- You need stateless interactions without persistent connections
Real-time Order Monitoring
The WebSocket API excels at real-time order monitoring through its event-driven architecture:Key Capabilities
Order Events
Subscribe to order creation, fills, partial fills, and cancellations
State Changes
Track balance and allowance changes that affect order execution
Secret Sharing
Receive shared secrets for cross-chain order resolution
RPC Methods
Query active orders and available methods through the connection
Architecture
The WebSocket API is organized into three main components:- Base API (
WebSocketApi) - Core connection management and low-level event handling - Order namespace (
order.*) - Order-specific event subscriptions - RPC namespace (
rpc.*) - Request/response methods for querying data
Next Steps
Setup
Learn how to establish WebSocket connections
Events
Explore available events and their data structures