LedgerCore
Realtime

Event Reference

Every event name lives in src/core/websocket/event-constants.ts on the server. The client emits a "request" event and receives one or more "response", "progress", and "error" events in return.

System

EventDirectionPayload
connectedserver → you{ userId, sid, timestamp }
pingyou → server()
pongserver → you{ timestamp }
subscribeyou → server{ room: string }
unsubscribeyou → server{ room: string }
subscribedserver → you{ room, subscriberCount }
unsubscribedserver → you{ room }
user_joined_roomserver → room{ userId, room, joinedAt }
user_left_roomserver → room{ userId, room, leftAt }

Query Engine

The unified query engine streams results over WebSocket for queries that take longer than ~200ms.

EventDirectionPayload
queryyou → server{ sql, params?, applicationId }
query_startedserver → you{ queryId, estimatedMs }
query_progressserver → you{ queryId, rowsProcessed, pct }
query_responseserver → you{ queryId, rows, schema }
query_completedserver → you{ queryId, durationMs, totalRows }
query_errorserver → you{ queryId, code, message }

Market Data

Sub-second candles, trades, and chart updates.

EventDirectionPayload
request_market_datayou → server{ symbol, resolution, venues?, window? }
market_data_responseserver → you{ symbol, candles }
market_chart_initial_dataserver → you{ symbol, series: Candle[] }
market_chart_live_updateserver → you{ symbol, open, high, low, close, volume, timestamp }
market_data_errorserver → you{ code, message }

Compliance (LedgerBrain)

Long-running address and transaction analysis with progress updates.

EventDirectionPayload
address_analysisyou → server{ chain, address, hops? }
address_analysis_startedserver → you{ jobId }
address_analysis_progressserver → you{ jobId, stage, pct }
address_analysis_responseserver → you{ jobId, riskScore, riskLevel, clusters, signals }
address_analysis_completedserver → you{ jobId, durationMs }
address_analysis_errorserver → you{ jobId, code, message }
address_transactionsyou → server{ chain, address, limit?, cursor? }
address_transactions_responseserver → you{ chain, address, transactions, nextCursor }
cross_border_flowsyou → server{ corridor, window }
cross_border_flows_responseserver → you{ corridor, flows, totalsUSD }

Credits

Every credit movement is pushed to your personal room (user:<clerkUserId>) automatically — no subscription required.

EventDirectionPayload
credit_balance_updatedserver → you{ newBalance, lifetimeEarned, lifetimeSpent, applicationId }
credits_deductedserver → you{ amount, newBalance, action, transactionId, timestamp }
credits_grantedserver → you{ amount, newBalance, reason, transactionId, timestamp }
insufficient_creditsserver → you{ required, available, action }

Chat / AI (LedgerBrain AI)

Streaming natural-language query responses.

EventDirectionPayload
chatyou → server{ conversationId, message, context? }
chat_typingserver → you{ conversationId }
chat_stop_typingserver → you{ conversationId }
chat_messageserver → you{ conversationId, role, delta, isFinal }
chat_responseserver → you{ conversationId, messageId, tokens, sql? }
chat_errorserver → you{ conversationId, code, message }

Errors

Standard error envelope across every category:

{
  "code": "RATE_LIMITED | UNAUTHORIZED | NOT_FOUND | INTERNAL",
  "message": "Human-readable description",
  "retryAfter": 30
}
EventWhen
rate_limit_errorYou exceeded per-socket or per-user request throttles.
validation_errorYour request payload failed schema validation.
Was this page helpful?