Skip to main content

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.

FieldTypeRequiredDescription
typestringYes"ORDER_BOOK"
instrumentIdstringYesInstrument to subscribe
depthintegerNoOrder book depth (default: 20)

Trading Account Subscription

Subscribe to trading account updates (orders, portfolio, balances).

FieldTypeRequiredDescription
typestringYes"TRADING_ACCOUNT"
tradingAccountIdstringYesAccount to subscribe

Result

Returns the created subscription object.

Subscription Object

FieldTypeDescription
subscriptionIdstringUnique subscription identifier
typestringSubscription type
channelstringCentrifugo channel to subscribe
statusstringSubscription status (ACTIVE)
createdAtintegerCreation 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