command.subscription.create
Create a data subscription.
Method
command.subscription.create
Description
Creates a server-side subscription for real-time data. After creating a subscription, you must also subscribe to the corresponding Centrifugo channel to receive updates.
Subscription Types
Order Book Subscription
Subscribe to real-time order book updates for an instrument.
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | "ORDER_BOOK" |
instrumentId | string | Yes | Instrument to subscribe |
depth | integer | No | Order book depth (default: 20) |
Trading Account Subscription
Subscribe to trading account updates (orders, portfolio, balances).
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | "TRADING_ACCOUNT" |
tradingAccountId | string | Yes | Account to subscribe |
Result
Returns the created subscription object.
Subscription Object
| Field | Type | Description |
|---|---|---|
subscriptionId | string | Unique subscription identifier |
type | string | Subscription type |
channel | string | Centrifugo channel to subscribe |
status | string | Subscription status (ACTIVE) |
createdAt | integer | Creation timestamp (ms) |
Usage
# Subscribe to order book
result = await client.rpc("command.subscription.create", {
"type": "ORDER_BOOK",
"instrumentId": "BINANCE:BTC/USDT",
"depth": 10
})
# Then subscribe to the Centrifugo channel
sub = client.new_subscription(result["channel"])
sub.subscribe()
# Subscribe to trading account
result = await client.rpc("command.subscription.create", {
"type": "TRADING_ACCOUNT",
"tradingAccountId": "550e8400-e29b-41d4-a716-446655440000"
})
# Then subscribe to the Centrifugo channel
sub = client.new_subscription(result["channel"])
sub.subscribe()
Example Response
Order Book Subscription
{
"subscriptionId": "sub-001",
"type": "ORDER_BOOK",
"channel": "market:orderBook:BINANCE:BTC/USDT",
"instrumentId": "BINANCE:BTC/USDT",
"status": "ACTIVE",
"createdAt": 1703052635110
}
Trading Account Subscription
{
"subscriptionId": "sub-002",
"type": "TRADING_ACCOUNT",
"channel": "tradingAccount:550e8400-e29b-41d4-a716-446655440000",
"tradingAccountId": "550e8400-e29b-41d4-a716-446655440000",
"status": "ACTIVE",
"createdAt": 1703052635110
}
Two-Step Subscription Flow
┌──────────┐ ┌──────────┐ ┌──────────────┐
│ Client │ │ Cadenza │ │ Centrifugo │
└────┬─────┘ └────┬─────┘ └──────┬───────┘
│ │ │
│ 1. RPC: create │ │
│ subscription │ │
│───────────────────▶│ │
│ │ Start data feed │
│ │─────────────────────▶│
│ channel name │ │
│◀───────────────────│ │
│ │ │
│ 2. Subscribe to │ │
│ channel │ │
│─────────────────────────────────────────▶│
│ │ │
│ Real-time updates │
│◀─────────────────────────────────────────│
Notes
- Server-side subscription (step 1) sets up the data feed
- Centrifugo subscription (step 2) receives the updates
- Both steps are required to receive data
- See Channels for data format details