Skip to content

Candle Updates

Receive real-time OHLCV price candles for charting and technical analysis across multiple timeframes.

Note: In other exchanges this is sometime called candleSticks.

Endpoint

ws.send() wss://api.synthetix.io/v1/ws/subscriptions

Subscription Request

Subscribe to Candle Updates

{
  "id": "sub-1",
  "method": "subscribe",
  "params": {
    "type": "candles",
    "symbol": "BTC-USDT",
    "interval": "1m"
  }
}

Request Parameters

ParameterTypeRequiredDescription
idstringYesClient-generated unique request identifier
methodstringYesMust be "subscribe"
params.typestringYesMust be "candles"
params.symbolstringYesTrading pair symbol (e.g., "BTC-USDT")
params.intervalstringYesCandle interval (e.g., "1m", "5m", "1h", "1d")

Supported Intervals

IntervalDescription
1m1-minute candles
3m3-minute candles
5m5-minute candles
15m15-minute candles
30m30-minute candles
1h1-hour candles
2h2-hour candles
4h4-hour candles
6h6-hour candles
8h8-hour candles
12h12-hour candles
1d1-day candles
1w1-week candles

Candle Update Messages

New Candle

{
  "method": "candle_update",
  "data": {
    "symbol": "BTC-USDT",
    "timeframe": "1m",
    "open_price": "50000.00",
    "high_price": "50125.50",
    "low_price": "49875.00",
    "close_price": "50050.25",
    "volume": "12.5",
    "open_time": "2025-01-01T00:00:00Z",
    "close_time": "2025-01-01T00:00:59.999Z",
    "quote_volume": "625125.75",
    "trade_count": 145
  }
}

:::warning Field Naming WebSocket candle updates use snake_case field names (open_price, close_time, etc.) while REST API candles use camelCase. This is due to WebSocket using the internal NATS message format directly. :::

Candle Update (In Progress)

Example of an in-progress candle (not yet closed):

{
  "method": "candle_update",
  "data": {
    "symbol": "BTC-USDT",
    "timeframe": "1m",
    "open_price": "50050.25",
    "high_price": "50075.00",
    "low_price": "50025.00",
    "close_price": "50060.50",
    "volume": "3.2",
    "open_time": "2025-01-01T00:01:00Z",
    "close_time": "2025-01-01T00:01:59.999Z",
    "quote_volume": "160193.60",
    "trade_count": 42
  }
}

Candle Data Fields

Candle Object (REST API)

FieldTypeDescription
openTimeintegerCandle open time (Unix milliseconds)
closeTimeintegerCandle close time (Unix milliseconds)
openPricestringOpening price of the period
highPricestringHighest price during the period
lowPricestringLowest price during the period
closePricestringClosing price of the period
volumestringTotal trading volume in base asset
quoteVolumestringTotal trading volume in quote asset
tradeCountintegerNumber of trades in this candle

Candle Object (WebSocket)

FieldTypeDescription
symbolstringMarket symbol (e.g., "BTC-USDT")
timeframestringCandle interval (e.g., "1m", "5m", "1h")
open_pricestringOpening price of the period
high_pricestringHighest price during the period
low_pricestringLowest price during the period
close_pricestringClosing price of the period
volumestringTotal trading volume in base asset
open_timestringCandle open time (RFC3339 format)
close_timestringCandle close time (RFC3339 format)
quote_volumestringTotal trading volume in quote asset
trade_countintegerNumber of trades in this candle

Note: Candles are generated from actual trade executions. The open price is the first trade of the interval, and the close price is the last trade.

WebSocket Candle Update Fields

:::warning Snake Case WebSocket candle updates use snake_case field names as shown in the examples above. :::

FieldTypeDescription
symbolstringTrading pair symbol
timeframestringCandle time interval (e.g., "1m", "5m", "1h")
open_timestringCandle open time (RFC3339 format)
close_timestringCandle close time (RFC3339 format)
open_pricestringOpening price
high_pricestringHighest price in the period
low_pricestringLowest price in the period
close_pricestringClosing price (or current price if in progress)
volumestringBase asset volume
quote_volumestringQuote asset volume
trade_countintegerNumber of trades in the period

Note: WebSocket candle updates include real-time in-progress candles. The close_price represents the current price until the candle period completes.

Implementation Example

// First authenticate with EIP-712 signature
const domain = {
  name: "Synthetix",
  version: "1",
  chainId: 1,
  verifyingContract: "0x0000000000000000000000000000000000000000"
};
 
// Subscribe to candle updates after authentication
const subscription = {
  id: "sub-1",
  method: "subscribe",
  params: {
    type: "candles",
    symbol: "BTC-USDT",
    timeframe: "1m"
  }
};
 
ws.send(JSON.stringify(subscription));
 
// Handle candle update messages
ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
 
  if (message.method === "candle_update") {
    // WebSocket candles use snake_case field names
    const { symbol, timeframe, open_price, high_price, low_price, close_price } = message.data;
    console.log(`${symbol} ${timeframe} candle: O=${open_price} H=${high_price} L=${low_price} C=${close_price}`);
    
    // Update chart with new candle data
    updateCandlestickChart(message.data);
  }
};
 
function updateCandlestickChart(candleData) {
  // Destructure using actual snake_case field names
  const { 
    open_time,     // RFC3339 string
    open_price, 
    high_price, 
    low_price, 
    close_price, 
    volume 
  } = candleData;
 
  // Parse timestamp from RFC3339 string
  const timestamp = new Date(open_time).getTime();
 
  // Add/update candle in chart
  chart.updateCandle({
    time: timestamp / 1000,  // TradingView expects seconds
    open: parseFloat(open_price),
    high: parseFloat(high_price),
    low: parseFloat(low_price),
    close: parseFloat(close_price),
    volume: parseFloat(volume)
  });
}

Multiple Timeframes

Subscribe to multiple intervals for the same symbol:

// Subscribe to multiple timeframes
const subscriptions = [
  {
    id: "sub-1m",
    method: "subscribe",
    params: { type: "candles", symbol: "BTC-USDT", interval: "1m" }
  },
  {
    id: "sub-5m",
    method: "subscribe",
    params: { type: "candles", symbol: "BTC-USDT", interval: "5m" }
  },
  {
    id: "sub-1h",
    method: "subscribe",
    params: { type: "candles", symbol: "BTC-USDT", interval: "1h" }
  }
];
 
subscriptions.forEach(sub => ws.send(JSON.stringify(sub)));

Use Cases

Charting Applications

  • Real-time Charts: Update candlestick charts with live price data
  • Technical Analysis: Provide OHLCV data for technical indicators
  • Multiple Timeframes: Display different chart intervals simultaneously

Trading Strategies

  • Pattern Recognition: Identify candlestick patterns for trading signals
  • Trend Analysis: Monitor price movements across different timeframes
  • Volume Analysis: Track volume patterns for market strength

Data Collection

  • Historical Data: Build historical price databases
  • Market Analysis: Analyze market behavior and volatility
  • Backtesting: Collect data for strategy backtesting

Implementation Notes

  • Real-time Updates: In-progress candles update continuously until closed
  • Closed Candles: Only add finalized candles to persistent storage
  • Memory Management: Limit the number of historical candles stored in memory
  • Reconnection: Re-subscribe on WebSocket reconnection to maintain data continuity

Error Handling

Subscription Errors

{
  "id": "sub-1",
  "status": 400,
  "result": null,
  "error": {
    "code": 400,
    "message": "Invalid interval: 2m not supported"
  }
}

Common Issues

ErrorDescriptionSolution
Invalid intervalUnsupported time intervalUse supported intervals (1m, 5m, 1h, etc.)
Invalid symbolSymbol not availableCheck supported trading pairs
Rate limit exceededToo many subscriptionsLimit concurrent subscriptions

Related Endpoints