Skip to main content

OHLC API

Build OHLC candlestick chart data for any DEX token pair using the dexTrades API. Prices are aggregated at runtime from on-chain swaps, with configurable time intervals, outlier filters, and exchange-specific filtering.

Get Ethereum DEX OHLC for DAI and Quote in Ten Minute Intervals

Get 10-minute OHLC candles for a DAI/WETH pair on Ethereum. Returns open, high, low, close prices with trade counts, base/quote amounts, and USD values using the expression field for derived calculations.

Variations: Change minute(count: 10) to minute(count: 1), hour, or day for different intervals. Swap the token addresses for any pair. Add exchangeName to filter by DEX. Adjust the time range for any period.

{
ethereum(network: ethereum) {
dexTrades(
options: {limit: 6, asc: "timeInterval.minute"}
time: {since: "2023-07-09T17:00:00Z", till: "2023-07-09T18:00:00Z"}
baseCurrency: {is: "0xd0b3a986fff305854a7238a8e099cce1ced01a3d"}
quoteCurrency: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
) {
timeInterval {
minute(count:10)
}
baseCurrency {
symbol
address
}
baseAmount
baseAmountInUSD: baseAmount(in: USD)
quoteCurrency {
symbol
address
}
quoteAmount
quoteAmountInUSD: quoteAmount(in: USD)
trades: count
quotePrice
average_price: quotePrice(calculate: average)
maximum_price: quotePrice(calculate: maximum)
minimum_price: quotePrice(calculate: minimum)
open_price: minimum(of: block, get: quote_price)
close_price: maximum(of: block, get: quote_price)
averagePriceInUSD: expression(get: "quoteAmountInUSD/baseAmount")
}
}
}


Get Uniswap Ethereum WETH USDT OHLC With Outlier Trade Filters

Get 5-minute OHLC candles for WETH/USDT on Uniswap specifically, with outlier filtering. The priceAsymmetry: {lt: 1} filter removes trades with mismatched buy/sell USD values, and tradeAmountUsd: {gt: 500} excludes dust trades. Read more about priceAsymmetry.

Variations: Change exchangeName to "Sushiswap" or remove it for all DEXes. Adjust tradeAmountUsd threshold for your quality requirements. Switch network to bsc or matic for other chains.

Open this query on IDE

{
ethereum(network: ethereum) {
dexTrades(
options: { limit: 10, asc: "timeInterval.minute" }
date: { is: "2023-05-23" }
exchangeName: { is: "Uniswap" }
baseCurrency: { is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" }
quoteCurrency: { is: "0xdac17f958d2ee523a2206206994597c13d831ec7" }
priceAsymmetry: { lt: 1 }
tradeAmountUsd: { gt: 500 }
) {
timeInterval {
minute(count: 5)
}
baseCurrency {
symbol
address
}
baseAmount
quoteCurrency {
symbol
address
}
quoteAmount
trades: count
quotePrice
maximum_price: quotePrice(calculate: maximum)
minimum_price: quotePrice(calculate: minimum)
open_price: minimum(of: block, get: quote_price)
close_price: maximum(of: block, get: quote_price)
}
}
}