Skip to main content
In this recipe we’ll show you how to use the Codex api to render a token chart, complete with OHLCV data, and more. This data powers the charts on defined.fi.
Chart

Fetch

Start by implementing the following query to fetch the OHLCV data for a given token.

Chart for BNB token for day with 5 minute bars

Render

Sample Response
{
  "data": {
    "getBars": {
      "o": [
        639.962297445,
        639.948026102,
      ],
      "h": [
        640.343357275,
        640.081660228,
      ],
      "l": [
        639.795898952,
        639.914833559,
      ],
      "c": [
        639.948026102,
        639.983598149,
      ],
      "t": [
        1750353300,
        1750353600,
      ],
      "volume": [
        "577495.066850454",
        "302268.420570785",
      ]
    }
  }
}
The result uses the “response-as-a-table” pattern, which means you can use the o, h, l, c, t, and volume fields to render the chart. This is adapted from the TradingView documentation, and is intended to be used with their charting library here.

Realtime updates

Now that we have all the data we need to render a chart, we can use the onBarsUpdated subscription to get realtime updates.

Realtime

After receiving the realtime updates, you can use the o, h, l, c, t, and volume fields to update the chart.

Aggregated Charts

Create token charts with aggregated data across all valid pairs with getTokenBars. Note that this data has limited historical data, back to timestamp 1753121580. For real-time aggregate charts, subscribe to onTokenBarsUpdated.
You can refer to this datafeed example using the SDK for onTokenBarsUpdated to get you started with a chart rendering subscription.
Check out all of our charting queries and subscriptions in the api reference