Skip to content

Get Candles (WebSocket)

Retrieve OHLCV (Open, High, Low, Close, Volume) price data for a specific trading pair through the WebSocket connection. This endpoint provides historical candlestick data for technical analysis and charting without requiring authentication.

Endpoint

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

Request

Request Format

{
  "id": "candles-1",
  "method": "post",
  "params": {
    "action": "getCandles",
    "symbol": "BTC-USDT",
    "interval": "1h",
    "limit": 500,
    "startTime": 1704067200000,
    "endTime": 1704153600000
  }
}

Request Parameters

ParameterTypeRequiredDescription
idstringYesClient-generated unique request identifier
methodstringYesMust be "post"
paramsobjectYesRequest parameters wrapper
params.actionstringYesMust be "getCandles"
params.symbolstringYesTrading pair symbol (e.g., "BTC-USDT")
params.intervalstringYesTime interval: 1m, 5m, 15m, 1h, 4h, 1d, 1w, 1M
params.limitintegerNoNumber of candles to return (0 = no limit)
params.startTimeintegerNoStart time in milliseconds (default: 24 hours ago)
params.endTimeintegerNoEnd time in milliseconds (default: current time)

Valid Intervals

IntervalDescriptionMilliseconds
1m1 minute60,000
5m5 minutes300,000
15m15 minutes900,000
1h1 hour3,600,000
4h4 hours14,400,000
1d1 day86,400,000
1w1 week604,800,000
1M1 month2,592,000,000

Response

Success Response

{
  "id": "candles-1",
  "status": 200,
  "result": {
    "response": {
      "symbol": "BTC-USDT",
      "interval": "1h",
      "candles": [
        {
          "openTime": 1704067200000,
          "closeTime": 1704070800000,
          "openPrice": "45000.50",
          "highPrice": "45100.00",
          "lowPrice": "44950.00",
          "closePrice": "45050.00",
          "volume": "125.5",
          "quoteVolume": "125500.00",
          "tradeCount": 1523
        },
        {
          "openTime": 1704070800000,
          "closeTime": 1704074400000,
          "openPrice": "45050.00",
          "highPrice": "45200.00",
          "lowPrice": "45000.00",
          "closePrice": "45150.00",
          "volume": "98.2",
          "quoteVolume": "98450.00",
          "tradeCount": 1102
        }
      ]
    },
    "status": "success"
  }
}

Response Fields

FieldTypeDescription
result.response.symbolstringTrading pair symbol
result.response.intervalstringTime interval used
result.response.candlesarrayArray of candle objects
result.statusstringAlways "success" for successful responses

Candle Object

FieldTypeDescription
openTimeintegerCandle open time in milliseconds
closeTimeintegerCandle close time in milliseconds
openPricestringOpening price
highPricestringHighest price during the period
lowPricestringLowest price during the period
closePricestringClosing price
volumestringBase asset trading volume
quoteVolumestringQuote asset trading volume
tradeCountintegerNumber of trades in the period

Error Response

{
  "id": "candles-1",
  "status": 400,
  "result": null,
  "error": {
    "code": 400,
    "message": "Invalid interval"
  }
}

WebSocket Connection Example

const ws = new WebSocket('wss://papi.synthetix.io/v1/ws/info');
 
ws.onopen = () => {
  // Request hourly candles for BTC-USDT
  ws.send(JSON.stringify({
    id: 'candles-1',
    method: 'post',
    params: {
      action: 'getCandles',
      symbol: 'BTC-USDT',
      interval: '1h',
      limit: 100
    }
  }));
};
 
ws.onmessage = (event) => {
  const response = JSON.parse(event.data);
 
  if (response.id === 'candles-1' && response.status === 200) {
    const data = response.result.response;
    console.log(`${data.symbol} ${data.interval} candles:`, data.candles);
 
    // Process candle data
    data.candles.forEach(candle => {
      console.log(`Open: ${candle.openPrice}, High: ${candle.highPrice}, Low: ${candle.lowPrice}, Close: ${candle.closePrice}`);
    });
  }
};

Examples

Get Recent 1-Hour Candles

{
  "id": "candles-hourly",
  "method": "post",
  "params": {
    "action": "getCandles",
    "symbol": "BTC-USDT",
    "interval": "1h",
    "limit": 100
  }
}

Get Daily Candles for Date Range

{
  "id": "candles-daily",
  "method": "post",
  "params": {
    "action": "getCandles",
    "symbol": "ETH-USDT",
    "interval": "1d",
    "startTime": 1704067200000,
    "endTime": 1704153600000,
    "limit": 30
  }
}

Get 5-Minute Candles

{
  "id": "candles-5m",
  "method": "post",
  "params": {
    "action": "getCandles",
    "symbol": "BTC-USDT",
    "interval": "5m",
    "limit": 200
  }
}

Get All Candles (No Limit)

{
  "id": "candles-all",
  "method": "post",
  "params": {
    "action": "getCandles",
    "symbol": "BTC-USDT",
    "interval": "1h",
    "limit": 0,
    "startTime": 1704067200000,
    "endTime": 1704153600000
  }
}

Implementation Notes

  • Public Data: No authentication required for this endpoint
  • Symbol Required: A valid market symbol must be provided
  • Interval Required: A valid time interval must be specified
  • Limit Usage: Set limit to 0 for no limit, or specify desired number of candles
  • Time Range: Optional start and end time filtering with millisecond precision
  • Sorting: Candles are returned in ascending order by time (oldest first)

Use Cases

Technical Analysis

  • Chart patterns and trend identification
  • Technical indicator calculations (RSI, MACD, moving averages)
  • Support and resistance level identification

Trading Strategies

  • Backtesting algorithmic strategies
  • Entry and exit point determination
  • Volatility analysis

Market Research

  • Historical price movement analysis
  • Volume trend analysis
  • Market behavior patterns

Risk Management

  • Volatility assessment
  • Drawdown calculations
  • Portfolio performance tracking

Validation Rules

  • No authentication required (public Info WebSocket)
  • Symbol parameter is required and must be a valid market symbol
  • Interval parameter is required and must be one of the valid intervals
  • Limit must be non-negative (≥ 0), where 0 means no limit
  • If both startTime and endTime are provided, startTime must be less than endTime

Common Errors

ErrorDescription
Symbol requiredMissing trading pair symbol
Invalid intervalUnsupported time interval
Invalid limitLimit must be non-negative
Invalid time rangeStart time is after end time
Failed to retrieve dataInternal service error

Performance Considerations

  • Low Latency: WebSocket connection provides faster response times than REST
  • Persistent Connection: Reuse the same connection for multiple requests
  • Efficient Queries: Use specific time ranges to reduce data transfer
  • Caching: Historical candle data is immutable and suitable for caching

Related Endpoints