Event Types

This reference documents all WebSocket event types in the Trading API, including market data events, order/position updates, and client messages.

Event Message Structure

All events are delivered via WebSocket with a consistent structure:

{
  "type": "event_type",
  "timestamp": "2025-01-15T10:30:00Z",
  ...event-specific fields
}

The type field identifies the event category. Each event type has specific additional fields documented below.

Market Data Events

Candle Event

Delivers OHLCV bar data for subscribed instruments.

Type: candle

FieldTypeDescription
typestringAlways "candle"
barBarThe bar data
timestampdatetimeEvent timestamp (when event was emitted)

Bar Schema

FieldTypeDescription
symbolstringSymbol in canonical format (e.g., "EUR/USD", "AAPL")
providerstringData source provider (e.g., "alpaca", "binance")
timeframeTimeframeBar timeframe
timestampdatetimeBar start timestamp
openstringOpening price
highstringHighest price during the period
lowstringLowest price during the period
closestringClosing price
volumestringTrading volume during the period

Timeframe Enum

ValueDescription
1m1 minute
2m2 minutes
5m5 minutes
10m10 minutes
15m15 minutes
30m30 minutes
1h1 hour
2h2 hours
4h4 hours
12h12 hours
1d1 day
1w1 week

Example

{
  "type": "candle",
  "bar": {
    "symbol": "AAPL",
    "provider": "alpaca",
    "timeframe": "1h",
    "timestamp": "2025-01-15T10:00:00Z",
    "open": "150.00",
    "high": "151.50",
    "low": "149.75",
    "close": "151.25",
    "volume": "1500000"
  },
  "timestamp": "2025-01-15T11:00:00Z"
}

Quote Event

Delivers real-time bid/ask quotes.

Type: quote

FieldTypeDescription
typestringAlways "quote"
quoteQuoteThe quote data
timestampdatetimeEvent timestamp

Quote Schema

FieldTypeDescription
symbolstringSymbol in canonical format
providerstringData source provider
bidstringBest bid price (highest buy offer)
bid_sizestring?Quantity available at bid price
askstringBest ask price (lowest sell offer)
ask_sizestring?Quantity available at ask price
laststringLast traded price
volumestring?Trading volume (if available)
timestampdatetimeQuote timestamp

Example

{
  "type": "quote",
  "quote": {
    "symbol": "EUR/USD",
    "provider": "alpaca",
    "bid": "1.0845",
    "bid_size": "100000",
    "ask": "1.0847",
    "ask_size": "100000",
    "last": "1.0846",
    "timestamp": "2025-01-15T10:30:00.123Z"
  },
  "timestamp": "2025-01-15T10:30:00.125Z"
}

Order Events

Delivers order state changes.

Type: order

FieldTypeDescription
typestringAlways "order"
eventOrderEventTypeType of order event
orderOrderCurrent state of the order
parent_order_idstring?Parent order ID for bracket/OCO child orders
timestampdatetimeEvent timestamp

OrderEventType Enum

ValueDescription
ORDER_CREATEDOrder has been created and submitted
ORDER_MODIFIEDOrder has been modified (price, quantity, etc.)
ORDER_CANCELLEDOrder has been cancelled
ORDER_REJECTEDOrder was rejected by the provider
ORDER_FILLEDOrder has been completely filled
ORDER_PARTIALLY_FILLEDOrder has been partially filled
ORDER_EXPIREDOrder has expired based on time_in_force
BRACKET_ORDER_CREATEDBracket order (with SL/TP) has been created
BRACKET_ORDER_MODIFIEDBracket order has been modified

Example

{
  "type": "order",
  "event": "ORDER_FILLED",
  "order": {
    "id": "ord_abc123",
    "symbol": "AAPL",
    "side": "BUY",
    "order_type": "LIMIT",
    "quantity": "100",
    "filled_quantity": "100",
    "remaining_quantity": "0",
    "average_fill_price": "150.25",
    "status": "FILLED",
    "time_in_force": "GTC",
    "limit_price": "150.50",
    "created_at": "2025-01-15T10:30:00Z",
    "updated_at": "2025-01-15T10:30:05Z"
  },
  "timestamp": "2025-01-15T10:30:05Z"
}

Position Events

Delivers position state changes.

Type: position

FieldTypeDescription
typestringAlways "position"
eventPositionEventTypeType of position event
positionPositionCurrent state of the position
timestampdatetimeEvent timestamp

PositionEventType Enum

ValueDescription
POSITION_OPENEDNew position has been opened
POSITION_MODIFIEDPosition has been modified (partial close, averaging)
POSITION_CLOSEDPosition has been fully closed

Example

{
  "type": "position",
  "event": "POSITION_OPENED",
  "position": {
    "id": "pos_xyz789",
    "symbol": "BTC/USD",
    "side": "LONG",
    "quantity": "0.5",
    "average_entry_price": "42000.00",
    "current_price": "42100.00",
    "unrealized_pnl": "50.00",
    "realized_pnl": "0.00",
    "opened_at": "2025-01-15T10:30:00Z",
    "updated_at": "2025-01-15T10:30:00Z"
  },
  "timestamp": "2025-01-15T10:30:00Z"
}

Account Events

Delivers account state changes.

Type: account

FieldTypeDescription
typestringAlways "account"
eventAccountEventTypeType of account event
accountAccountCurrent account state
timestampdatetimeEvent timestamp

AccountEventType Enum

ValueDescription
BALANCE_UPDATEDAccount balance has changed
MARGIN_WARNINGMargin utilization approaching limit
MARGIN_CALLMargin call triggered - reduce positions or add funds

Example

{
  "type": "account",
  "event": "BALANCE_UPDATED",
  "account": {
    "balance": "10000.00",
    "equity": "10250.00",
    "margin_used": "1500.00",
    "margin_available": "8500.00",
    "unrealized_pnl": "250.00",
    "currency": "USD"
  },
  "timestamp": "2025-01-15T10:30:05Z"
}

Trade Events

Delivers individual trade/fill records.

Type: trade

FieldTypeDescription
typestringAlways "trade"
eventTradeEventTypeType of trade event
tradeTradeThe executed trade
timestampdatetimeEvent timestamp

TradeEventType Enum

ValueDescription
TRADE_FILLEDA trade has been executed

Trade Schema

FieldTypeDescription
idstringUnique trade identifier
order_idstringOrder ID this trade belongs to
symbolstringSymbol traded
sideSideTrade side (BUY or SELL)
quantitystringFill quantity in base units
pricestringFill price
commissionstringCommission/fee amount
commission_currencystringCurrency of the commission
is_makerboolean?Whether this was a maker trade
timestampdatetimeTrade execution timestamp

Example

{
  "type": "trade",
  "event": "TRADE_FILLED",
  "trade": {
    "id": "trd_123456",
    "order_id": "ord_abc123",
    "symbol": "AAPL",
    "side": "BUY",
    "quantity": "60",
    "price": "150.00",
    "commission": "0.50",
    "commission_currency": "USD",
    "is_maker": false,
    "timestamp": "2025-01-15T10:30:05Z"
  },
  "timestamp": "2025-01-15T10:30:05Z"
}

Connection Events

Delivers connection state changes.

Type: connection

FieldTypeDescription
typestringAlways "connection"
eventConnectionEventTypeType of connection event
errorstring?Error message if disconnecting due to error
timestampdatetimeEvent timestamp

ConnectionEventType Enum

ValueDescription
CONNECTEDSuccessfully connected to the provider
DISCONNECTINGConnection is closing
RECONNECTINGAttempting to reconnect after disconnect

Example

{
  "type": "connection",
  "event": "CONNECTED",
  "timestamp": "2025-01-15T10:30:00Z"
}

Rate Limit Events

Notifies about rate limiting status.

Type: rate_limit

FieldTypeDescription
typestringAlways "rate_limit"
eventRateLimitEventTypeType of rate limit event
requests_remainingintegerNumber of requests remaining in current window
reset_atdatetimeWhen the rate limit window resets
timestampdatetimeEvent timestamp

RateLimitEventType Enum

ValueDescription
RATE_LIMIT_WARNINGApproaching rate limit threshold
RATE_LIMIT_HITRate limit exceeded, requests will be delayed

Example

{
  "type": "rate_limit",
  "event": "RATE_LIMIT_WARNING",
  "requests_remaining": 10,
  "reset_at": "2025-01-15T10:31:00Z",
  "timestamp": "2025-01-15T10:30:50Z"
}

Error Events

Delivers error notifications.

Type: error

FieldTypeDescription
typestringAlways "error"
codeWsErrorCodeError code
messagestringHuman-readable error message
detailsobject?Additional error context
timestampdatetimeEvent timestamp

WsErrorCode Enum

ValueDescription
INVALID_MESSAGEReceived message could not be parsed
INTERNAL_ERRORServer encountered an internal error

Example

{
  "type": "error",
  "code": "INVALID_MESSAGE",
  "message": "Failed to parse order request: missing required field 'symbol'",
  "details": {
    "field": "symbol"
  },
  "timestamp": "2025-01-15T10:30:00Z"
}

Client Messages

Messages sent from your strategy to the server.

Ping/Pong (Heartbeat)

The server sends ping messages to check connection health. Your client must respond with pong.

Server sends:

{
  "type": "ping",
  "timestamp": "2025-01-15T10:30:00Z"
}

Client responds:

{
  "type": "pong"
}

Event Acknowledgment

Strategies must acknowledge received events. This is required for backtest mode (controls time simulation) and informational-only for live trading.

Type: event_ack

FieldTypeDescription
typestringAlways "event_ack"
correlation_idstringUnique ID for tracking this acknowledgment
events_processedstring[]List of event IDs that were processed
timestampintegerUnix timestamp (milliseconds) when events were processed

Example

{
  "type": "event_ack",
  "correlation_id": "550e8400-e29b-41d4-a716-446655440000",
  "events_processed": ["evt_123", "evt_124"],
  "timestamp": 1700000000000
}

Related Types