Subscribe Stats
Subscribe to account statistics (UPnL, cross leverage, maintenance margin, account value, free collateral, etc.). Updates are published at a fixed interval (every 5 seconds). Supports delegation - users can subscribe to accounts they are delegated to access.
Subscribe to account stats (requires authentication, supports delegation)#
Subscribe to account statistics (UPnL, cross leverage, maintenance margin, account value, free collateral, etc.). Updates are published at a fixed interval (every 5 seconds). Supports delegation - users can subscribe to accounts they are delegated to access.
Request to subscribe to account stats (requires authentication, supports delegation)
Parameters
sourcestringMust be 'stats'
accountstringEthereum address of the account (must match authenticated user or user must be a delegate)
subaccountIndicesarrayArray of subaccount indices. - Empty array []: Subscribes to ALL subaccounts (owner only - delegation not allowed) - Non-empty array: Subscribes to the specified subaccounts (delegation allowed) For delegated access, delegation is checked for ALL specified subaccounts. Subscription fails if user lacks delegation for any subaccount in the array.
{
"jsonrpc": "2.0",
"method": "subscribe",
"params": {
"source": "stats",
"account": "0xe1c03ec3bcf509b3e8e63abcd03edc661ffe6a78",
"subaccountIndices": [
0
]
},
"id": 10
}Generic success response for subscription requests
Parameters
message?stringSuccess message
{
"jsonrpc": "2.0",
"result": {
"message": "Subscribed to trades"
},
"usIn": 1234567890123,
"usOut": 1234567890456,
"usDiff": 333,
"id": 2
}Published at a fixed interval (every 5 seconds) for the subscribed account and subaccount. Contains UPnL, cross leverage, maintenance margin, account value, free collateral, etc. Wrapped with type field to identify the message type.
Parameters
accountstringEthereum address of the account
subaccountIndexintegerSubaccount index
upnlstringTotal unrealized profit and loss across all positions
crossLeveragestringCross-margin leverage (cross notional / cross account equity)
crossMarginUsagestringCross-margin usage (cross initial margin requirement / cross account equity)
maintMarginstringTotal maintenance margin requirement across all positions
crossMarginRatiostringCross-margin ratio (cross account equity / cross maintenance margin requirement)
accountValuestringAccount value (balance + cross UPnL)
initialMarginRequirementstringTotal initial margin requirement for all positions and orders
freeCollateralstringAmount available for withdrawals
{
"type": "Stats",
"data": {
"account": "0xe1c03ec3bcf509b3e8e63abcd03edc661ffe6a78",
"subaccountIndex": 0,
"upnl": "1234.567",
"crossLeverage": "2.5",
"crossMarginUsage": "0.38",
"maintMargin": "5000.123",
"crossMarginRatio": "0.4",
"accountValue": "10000.0",
"initialMarginRequirement": "5100.0",
"freeCollateral": "4500.0"
}
}Error response for failed requests
Parameters
jsonrpcstringJSON-RPC version
errorobjectusInintegerRequest received timestamp in milliseconds
usOutintegerResponse sent timestamp in milliseconds
usDiffintegerProcessing time in milliseconds
id?string | integer | nullRequest identifier (if provided in request, otherwise null)
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Invalid subscription params"
},
"usIn": 1234567890123,
"usOut": 1234567890456,
"usDiff": 333,
"id": 2
}