> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# onBarsUpdated

> Live-streamed bar chart data to track price changes over time. Processed updates are projected into `aggregates` using the confirmed bar shape.

> **Confirmed vs. unconfirmed events:** Use the `commitmentLevel` argument to choose which events you receive.
>
> * `confirmed` — receive events only after they're confirmed on-chain. This is the default if `commitmentLevel` is not specified.
> * `processed`: receive events as soon as they're observed on-chain (unconfirmed; may be reorged out). You must explicitly set `commitmentLevel: processed` to opt in. **Currently available on Solana, Base, and Robinhood.**
>
> For the fastest `processed` data, connect to an [edge node](https://docs.codex.io/concepts/edge-nodes.md).

## GraphQL

```
type Subscription {
  # Requires a Growth or Enterprise plan.
  onBarsUpdated(
    pairId: String
    commitmentLevel: [BarCommitmentLevel!]
    quoteToken: QuoteToken
    statsType: TokenPairStatisticsType
  ): OnBarsUpdatedResponse
}

enum TokenPairStatisticsType {
  FILTERED
  UNFILTERED
}

enum BarCommitmentLevel {
  Processed
  Confirmed
}

type IndividualBarData {
  o: Float!
  h: Float!
  l: Float!
  c: Float!
  v: Int
  t: Int!
  volume: String!
  volumeNativeToken: String!
  buyers: Int!
  buys: Int!
  buyVolume: String!
  sellers: Int!
  sells: Int!
  sellVolume: String!
  liquidity: String!
  traders: Int!
  transactions: Int!
  poolFees: String
  baseFees: String
  priorityFees: String
  builderTips: String
  l1DataFees: String
}

type CurrencyBarData {
  t: Int!
  usd: IndividualBarData!
  token: IndividualBarData!
}

type ResolutionBarData {
  r1S: CurrencyBarData
  r5S: CurrencyBarData
  r15S: CurrencyBarData
  r30S: CurrencyBarData
  r1: CurrencyBarData
  r5: CurrencyBarData
  r15: CurrencyBarData
  r30: CurrencyBarData
  r60: CurrencyBarData
  r240: CurrencyBarData
  r720: CurrencyBarData
  r1D: CurrencyBarData
  r7D: CurrencyBarData
}

enum QuoteToken {
  token0
  token1
}

type OnBarsUpdatedResponse {
  pairAddress: String!
  networkId: Int!
  pairId: String!
  timestamp: Int!
  statsType: TokenPairStatisticsType!
  eventSortKey: String!
  commitmentLevel: BarCommitmentLevel!
  aggregates: ResolutionBarData!
  quoteToken: QuoteToken
  quoteTokenAddress: String!
}
```

### Example

[Test this query in the Explorer →](https://docs.codex.io/explore.md)

```graphql theme={null}
subscription {
  onBarsUpdated(
    pairId: "BGm1tav58oGcsQJehL9WXBFXF7D27vZsKefj4xJKD5Y:1399811149"
    quoteToken: token0
  ) {
    pairAddress
    pairId
    networkId
    timestamp
    quoteToken
    quoteTokenAddress
    eventSortKey
    statsType
    aggregates {
      r1 {
        usd {
          t
          o
          h
          l
          c
          v
          volume
          buyers
          sellers
          buys
          sells
          buyVolume
          sellVolume
          liquidity
          transactions
        }
      }
      r5 {
        usd {
          t
          o
          h
          l
          c
          v
        }
      }
      r60 {
        usd {
          t
          o
          h
          l
          c
          v
        }
      }
    }
  }
}
```

```json Example Response theme={null}
{
  "data": {
    "onBarsUpdated": {
      "pairAddress": "BGm1tav58oGcsQJehL9WXBFXF7D27vZsKefj4xJKD5Y",
      "pairId": "BGm1tav58oGcsQJehL9WXBFXF7D27vZsKefj4xJKD5Y:1399811149",
      "networkId": 1399811149,
      "timestamp": 1769559142,
      "quoteToken": "token0",
      "quoteTokenAddress": "So11111111111111111111111111111111111111112",
      "eventSortKey": "0000000396370575#00001095#00000000#00000012",
      "statsType": "UNFILTERED",
      "aggregates": {
        "r1": {
          "usd": {
            "t": 1769559120,
            "o": 126.91645786,
            "h": 126.91645786,
            "l": 126.906300653,
            "c": 126.906300653,
            "v": 16608,
            "volume": "16607.75618360923",
            "buyers": 5,
            "sellers": 0,
            "buys": 7,
            "sells": 0,
            "buyVolume": "16607",
            "sellVolume": "0",
            "liquidity": "1495261.94023",
            "transactions": 7
          }
        },
        "r5": {
          "usd": {
            "t": 1769559000,
            "o": 126.909482001,
            "h": 126.91645786,
            "l": 126.904001603,
            "c": 126.906300653,
            "v": 16727
          }
        },
        "r60": {
          "usd": {
            "t": 1769558400,
            "o": 127.033618681,
            "h": 127.035495596,
            "l": 126.78034421,
            "c": 126.906300653,
            "v": 52148
          }
        }
      }
    }
  }
}
```

### Usage Guidelines

* Subscribe using `pairId` in the format `pairAddress:networkId`
* Set `quoteToken` to `token0` or `token1` to specify which token in the pair is being priced
* `aggregates` contains OHLCV bar data across multiple resolutions simultaneously (e.g., `r1` for 1-minute, `r5` for 5-minute, `r60` for 1-hour, `r1D` for 1-day)
* Each resolution provides both `usd` (USD-denominated) and `token` (native token-denominated) bars
* Use `o`, `h`, `l`, `c` for open/high/low/close prices, and `v` for volume
* Granular trade metrics like `buyers`, `sellers`, `buyVolume`, and `sellVolume` are available per bar for trade flow analysis
* Updates are streamed in real-time with every on-chain swap event

### Troubleshooting Tips

> [accordion] What resolutions are available?
>
> Resolutions range from 1-second (`r1S`) up to 1-week (`r1W`): `r1S`, `r5S`, `r15S`, `r30S`, `r1` (1 min), `r5`, `r15`, `r30`, `r60`, `r240` (4h), `r720` (12h), `r1D`, `r1W`. You only need to request the resolutions you need in your query.

> [accordion] What's the difference between usd and token bars?
>
> `usd` bars are denominated in US dollars, while `token` bars are denominated in the paired token (e.g., USDC). Use `usd` for standard price charts and `token` for relative price analysis against the quote token.

> [accordion] How do I choose the right quoteToken?
>
> `quoteToken` selects which token in the pair is being priced. For example, in a SOL/USDC pair where SOL is `token0`, setting `quoteToken: token0` returns the price of SOL in terms of USDC, while `token1` returns the price of USDC in terms of SOL. Check the pair metadata to confirm which token is `token0` vs `token1`.

> [accordion] What does statsType: Filtered vs Unfiltered mean?
>
> `Filtered` excludes suspected bot and sandwich attack transactions for cleaner price data. `Unfiltered` includes all transactions. Most charting use cases should use `Filtered` for more accurate price representation.

> [accordion] How often are updates sent?
>
> Updates are sent in real-time with every swap event on the pair. High-volume pairs (e.g., SOL/USDC on Solana) may produce many updates per second, while low-volume pairs update less frequently.

### Related Recipes

* [Charts](https://docs.codex.io/recipes/charts.md): Render token charts with OHLCV data and real-time updates


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.