2019-09-20
getMetric
QueryThe getMetric
API gives a unified API for many different metrics across the whole universe of supported assets. The query allows to get metadata about a given metric and asset, as well as fetch the values of the metric in a unified way.
Note:
The metrics are updated 4 times a day at 6 hour intervals. We are working on reducing this interval.
Supported assets:
Bitcoin | Ethereum | ERC-20 | Ripple | EOS | EOS tokens | Binance Chain |
---|---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
The getMetric
API supports a large list of assets identified by their slug. For a given metrics you can fetch the list of available slugs with this query:
There are 2 fields that can be queried on getMetric
and each of them has additional subfields: metadata
and timeseriesData
To fetch the values for a given metric, slug and time interval you can use the timeseriesData
subquery of the getMetric
API.
Parameters:
Parameter | Description |
---|---|
slug | The slug of the project |
from | From which date to return the values in ISO 8601 format |
to | Till which date to return the values in ISO 8601 format |
interval | The intervals that should be returned. Default is 1d , which is daily |
aggregation | The aggregation to be used when fetching data for longer intervals. Optional |
The aggregation
parameter is optional and if not provided - every metric has a default one that fits best. You can see the default aggregation function using the metadata query.
Example:
{
getMetric(metric: "transaction_volume") {
timeseriesData(
slug: "santiment"
from: "2019-01-01T00:00:00Z"
to: "2019-09-01T00:00:00Z"
interval: "7d"
aggregation: SUM) {
datetime
value
}
}
}
If you change the aggregation
parameter to AVG
it will return the average transaction volume over each 7 day interval. You can see how this API can be quite powerful and flexible.
The set of available metrics is not the same for each asset. We are trying to have all metrics for all assets, but this is not always possible. In order to find which are the available metrics for a given asset you can use the projectBySlug
query, like this:
To fetch the date from which a given metric is available for a project:
A metric is usually available for a given asset since the creation of the contract/blockchain.
Exception to this statement is when pricing data is needed in order to calculate the metric, but we are missing pricing data. For example, Bitcoin is working since the beginning of 2009, but because there were no exchanges and markets for over an year, the pricing data starts from July 2010. This means that MVRV, which requires market capitalization, is also available since July 2010.
Each metric has metadata describing:
Different queries are available with different granularities. The minimal interval you can get data for can be fetched by executing:
When an interval
bigger than minInterval
is provided for a given metric more than 1 data point values will be aggregated into a single data point.
The aggregations types are:
SUM
- The sum of all the valuesAVG
- The average of the valuesMEDIAN
- The median of all the valuesFIRST
- The first valueLAST
- The last valueMAX
- The max valueMIN
- The min valueANY
- Any value falling in the larger interval. This is usually used when all values are expected to have the same result and you just want to take one of them.The following query fetches the default aggregation:
To get the full metadata of a metric do the following: