Charts Query¶
Retrieve OHLCV (Open, High, Low, Close, Volume) candlestick data for charting.
Try It Now¶
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ chartLogs(first: 24, where: { market: \"0xd99802ee8f16d6ff929e27546de15d03fdcce4bd\" }, orderBy: blockTime, orderDirection: desc) { blockTime open high low close askVolume bidVolume } }"}' \
https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn
import requests
SUBGRAPH_URL = "https://api.goldsky.com/api/public/project_cmicv6kkbhyto01u3agb155hg/subgraphs/sera-pro/1.0.9/gn"
response = requests.post(SUBGRAPH_URL, json={
"query": """
query GetChartData($market: String!) {
chartLogs(
first: 100
where: { market: $market }
orderBy: blockTime
orderDirection: desc
) {
blockTime
open
high
low
close
askVolume
bidVolume
}
}
""",
"variables": {"market": "0xd99802ee8f16d6ff929e27546de15d03fdcce4bd"}
})
print(response.json())
Schema¶
type ChartLog {
id: ID! # Unique identifier
market: Market! # Market this chart data belongs to
blockTime: BigInt! # Unix timestamp of the block
open: BigInt! # Opening price index
high: BigInt! # Highest price index
low: BigInt! # Lowest price index
close: BigInt! # Closing price index
askVolume: BigInt! # Sell volume (raw units)
bidVolume: BigInt! # Buy volume (raw units)
}
Example Queries¶
Get Recent Candles¶
query GetRecentCandles($market: String!, $count: Int!) {
chartLogs(
where: { market: $market }
orderBy: blockTime
orderDirection: desc
first: $count
) {
blockTime
open
high
low
close
askVolume
bidVolume
}
}
Get Candles in Time Range¶
query GetCandlesInRange($market: String!, $start: BigInt!, $end: BigInt!) {
chartLogs(
where: {
market: $market
blockTime_gte: $start
blockTime_lte: $end
}
orderBy: blockTime
orderDirection: asc
) {
blockTime
open
high
low
close
askVolume
bidVolume
}
}
Response Example¶
{
"data": {
"chartLogs": [
{
"blockTime": "1704153600",
"open": "19500",
"high": "19650",
"low": "19450",
"close": "19600",
"askVolume": "15000",
"bidVolume": "12000"
},
{
"blockTime": "1704150000",
"open": "19400",
"high": "19550",
"low": "19350",
"close": "19500",
"askVolume": "8000",
"bidVolume": "10000"
}
]
}
}
Converting to Chart Format¶
async function getOHLCVData(marketId, market, count = 100) {
const query = `
query GetCandles($market: String!, $count: Int!) {
chartLogs(
where: { market: $market }
orderBy: blockTime
orderDirection: desc
first: $count
) {
blockTime
open
high
low
close
askVolume
bidVolume
}
}
`;
const data = await querySubgraph(query, { market: marketId, count });
// Convert price indices to actual prices
const minPrice = BigInt(market.minPrice);
const tickSpace = BigInt(market.tickSpace);
return data.chartLogs.map(candle => ({
time: Number(candle.blockTime),
open: formatPrice(minPrice + tickSpace * BigInt(candle.open)),
high: formatPrice(minPrice + tickSpace * BigInt(candle.high)),
low: formatPrice(minPrice + tickSpace * BigInt(candle.low)),
close: formatPrice(minPrice + tickSpace * BigInt(candle.close)),
volume: Number(candle.askVolume) + Number(candle.bidVolume)
})).reverse();
}
Integration with TradingView¶
// TradingView Lightweight Charts integration
import { createChart } from 'lightweight-charts';
const chart = createChart(document.getElementById('chart'), {
width: 800,
height: 400
});
const candlestickSeries = chart.addCandlestickSeries();
const ohlcvData = await getOHLCVData(MARKET_ID, marketInfo);
candlestickSeries.setData(ohlcvData);
Note
Chart data is recorded per block, not per fixed time interval. For standard OHLCV intervals (1m, 5m, 1h, etc.), you'll need to aggregate the data client-side.