Historical Data and Arguments
For historical data, the createdAt_gt
filter is needed. Without it, you only get the latest value.
To use it, add your desired start date like this createdAt_gt:"2022-01-01"
. The format is YYYY-MM-DD
If you want to query the historical data of the reward rate of Ethereum for the types solo-staking
and pos
, you can use this query.
{
rewardOptions(where: {inputAsset: {symbols: ["ETH"]}, typeKeys: ["solo-staking", "pos"]}, limit: 10) {
metrics(where: { metricKeys: ["reward_rate"], createdAt_lt:"2023-01-01"}, limit: 10) {
metricKey
defaultValue
changePercentages
createdAt
}
}
}
Historical data can be grouped by interval
: hour, day, week, month, quarter.
In the results, you get one data point from each interval.
Pick item strategy allows to define which item from the interval should be selected: first or last one.
By default, it's the last one.
Limitations:
- interval query can be run only for single resource (e.g. asset, provider, validator)
- result data points limited by global max limit=500
If you want to query the historical data daily, you can use a query like this:
{
rewardOptions(where: {inputAsset: {symbols: ["ETH"]}}, limit: 1) {
metrics(where: { metricKeys: ["reward_rate"], createdAt_gt:"2023-01-01"}, interval: day, limit: 500) {
metricKey
defaultValue
changePercentages
createdAt
}
}
}
Another example:
{
assets(where: {ids: ["60a27c3d4d60300008d25ecf"]}, limit: 1){
slug
metrics(limit:500,
where:{
metricKeys: ["price"],
createdAt_gt: "2023-01-01",
createdAt_lt: "2023-09-07"
},
order: {createdAt: desc},
interval: week,
pickItem: last
) {
metricKey
defaultValue
createdAt
}
}
}
Arguments
You can also use arguments when constructing your queries.
List of arguments:
{
"slugs": ["ethereum"],
"limit": 500,
"offset": 0,
"metricKeys": ["block_time_30d"],
"timeStart": "2023-01-01"
}
Constructed query:
query getHistoricalMetrics($slugs: [String!], $limit: Int, $offset: Int, $metricKeys: [String!], $timeStart: Date) {
assets(where: {slugs: $slugs}, limit: 1) {
metrics(where: {metricKeys: $metricKeys, createdAt_gt: $timeStart}, limit: $limit, offset: $offset, order: {createdAt: asc}) {
defaultValue
createdAt
id
}
}
}