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.

Fetch

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

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.

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

Check out the rest of the similar queries and subscriptions in the api reference