Skip to main content

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:

  1. Authenticate with Supabase to get JWT token
  2. Connect to Centrifugo WebSocket with JWT
  3. Make RPC calls for request/response operations
  4. Subscribe to channels for real-time push updates

SDK Components

To use the WebSocket API, you need two SDKs:

SDKPurposeInstallation
Cadenza Client SDKType-safe schemas for RPC params/resultspip install cadenza-client
Centrifugo Client SDKWebSocket connection & protocol handlingpip 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

EnvironmentWebSocket URL
UATwss://cadenza-ws-uat.algo724.com/connection/websocket
Productionwss://cadenza-ws.algo724.com/connection/websocket

Topics