WebSocket API
Cadenza provides a WebSocket API for real-time bidirectional communication, built on Centrifugo.
Overview
The WebSocket API enables you to:
- Stream market data - Real-time order books, trades, and tickers
- Execute trading operations - Submit/cancel orders via RPC
- Monitor portfolios - Live balance and position updates
- Receive notifications - Order status changes, account updates
Architecture
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Your Client │────▶│ Centrifugo │────▶│ Cadenza API │
│ │◀────│ (WebSocket) │◀────│ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Connection Flow:
- Authenticate with Supabase to get JWT token
- Connect to Centrifugo WebSocket with JWT
- Make RPC calls for request/response operations
- Subscribe to channels for real-time push updates
SDK Components
To use the WebSocket API, you need two SDKs:
| SDK | Purpose | Installation |
|---|---|---|
| Cadenza Client SDK | Type-safe schemas for RPC params/results | pip install cadenza-client |
| Centrifugo Client SDK | WebSocket connection & protocol handling | pip install centrifuge-python |
Quick Start
1. Install Dependencies
pip install cadenza-client centrifuge-python supabase
2. Authentication
1. Login to Supabase with email/password
2. Get access_token from session
3. Use token for WebSocket connection
3. Connect to WebSocket
client = Client(WS_URL, token=access_token)
await client.connect()
4. Make RPC Calls
# Create params using SDK model
params = RpcListInstrumentsParams(venue=Venue.BINANCE, limit=50)
# Call RPC method
result = await client.rpc("query.instrument.list", params.to_dict())
# Parse result using SDK model
parsed = RpcListInstrumentsResult.from_dict(result.data)
5. Subscribe to Channels
# Create server-side subscription first (RPC)
await client.rpc("command.subscription.create", subscription_request)
# Then subscribe to Centrifugo channel
sub = client.new_subscription("market:orderbook:BINANCE:BTC/USDT")
await sub.subscribe()
# Receive updates via on_publication callback
Endpoints
| Environment | WebSocket URL |
|---|---|
| UAT | wss://cadenza-ws-uat.algo724.com/connection/websocket |
| Production | wss://cadenza-ws.algo724.com/connection/websocket |
Topics
- Quick Start: Market Data - Stream real-time order books and trades
- Authentication - JWT token flow and connection auth
- RPC Commands - Available RPC methods and usage
- Channels - Real-time data subscriptions
- Error Handling - Error codes and handling patterns