Real-Time OHLC Data

Access high-quality candlestick data for technical analysis and trading applications

Overview

Looking for OHLC data? You’re at the right place. The Candlestick API provides real-time access to Open, High, Low, and Close price data at various time intervals.

Currently, we only support OHLC data for onchain data, but it will soon be available for offchain data as well.

Connection

1

Open WebSocket Connection

Connect to our WebSocket endpoint on your preferred environment:

wscat -c wss://ws.devnet.pragma.build/node/v1/onchain/ohlc/subscribe
2

Subscribe to Asset Pair

Send a subscription message with your desired pair, network, interval, and number of candles.

3

Receive OHLC Updates

Once subscribed, you’ll receive candlestick data at your specified interval.

Subscription Management

Subscribing to a Pair

You can only subscribe to one pair at a time. Subscribing to a new pair will automatically replace your current subscription.

{
  "msg_type": "subscribe",
  "pair": "BTC/USD",
  "network": "mainnet",
  "interval": "1min",
  "candles_to_get": "100" // Optional, defaults to 10
}

Available Parameters

ParameterTypeRequiredDefaultDescription
pairstringYes-The trading pair you want to subscribe to (e.g., “BTC/USD”)
networkstringYes-The blockchain network to fetch data from (e.g., “mainnet”)
intervalstringYes-Time interval for each candle. Options include: “1min”, “5min”, “15min”, “30min”, “1hour”, “4hour”, “1day”, “1week”
candles_to_getstringNo”10”Number of historical candles to receive on initial subscription

Unsubscribing

To stop receiving updates for your current subscription:

{
  "msg_type": "unsubscribe",
  "pair": "BTC/USD",
  "network": "mainnet",
  "interval": "1min"
}

The server will unsubscribe you without sending any acknowledgment. Your connection will remain open but you’ll stop receiving updates.

Data Format

{
  "msg_type": "ohlc_update",
  "pair": "BTC/USD",
  "network": "mainnet",
  "interval": "1min",
  "candles": [
    {
      "time": "2025-03-20T19:28:00",
      "open": "8407026302914",
      "high": "8407026302914",
      "low": "8407026302914",
      "close": "8407026302914"
    },
    {
      "time": "2025-03-20T19:27:00",
      "open": "8408636029312",
      "high": "8408636029312",
      "low": "8408636029312",
      "close": "8408636029312"
    },
    {
      "time": "2025-03-20T19:26:00",
      "open": "8410101544145",
      "high": "8410101544145",
      "low": "8410101544145",
      "close": "8410101544145"
    }
    // Additional candles...
  ]
}

Candle Fields

FieldTypeDescription
timestringISO 8601 timestamp marking the start of the candle period
openstringOpening price for the period (in raw price format)
highstringHighest price reached during the period (in raw price format)
lowstringLowest price reached during the period (in raw price format)
closestringClosing price for the period (in raw price format)

Available Intervals

1min

One-minute candles

5min

Five-minute candles

15min

Fifteen-minute candles

30min

Thirty-minute candles

1hour

One-hour candles

4hour

Four-hour candles

1day

Daily candles

1week

Weekly candles

Best Practices

Start with Small Requests

Begin with smaller time intervals and fewer candles to ensure smooth performance

Handle Reconnections

Implement reconnection logic with subscription restoration when connections drop

Error Handling

Add robust error handling for network issues and malformed responses

Data Storage

Consider implementing local storage to cache historical candles when appropriate