GraphQL
DIA made API data easily accessible through GraphQL endpoint.
You can use the following link to send GraphQL requests:
https://api.diadata.org/graphql/query
Also you can use a dedicated front-end to try out queries:
https://api.diadata.org/graphql/
Currently only tokens price feed data is available on GraphQL.
Example of schema that can be used for quoting data:
The schema will return the moving average price of ETH calculated every 5min (300 sec) by counting 2min trade blocks.
Query parameters rundown
Parameter | Description |
---|---|
filter | Select trades processing methodology (e.g. VWAP , MAIR , find out all available filters here) |
BlockSizeSeconds | Determine the window for trades inclusion in seconds (e.g. 120 will include all trades into price calculation that happened during the last 2 minutes) |
BlockShiftSeconds | Determine the frequency of price updates in seconds during the selected timeframe (e.g. 600 will return price for every 5min during the selected period) |
StartTime | The start time of the preferred period for price calculation in timestamp format (e.g. 1655084380 will start calculating price from 13.06.2022 01:39:40 GMT time) |
EndTime | The end time of the preferred period for price calculation in timestamp format (e.g. 1655090649 will calculate price until 13.06.2022 03:24:09 GMT time) |
FeedSelection | This is the main module of the query which is responsible for parametrizing asset(s) for which the price data should be retrieved. Available parameters for FeedSelection are described in detail below. |
FeedSelection
filtering options
There are a number of ways to filter out exchanges with DIA’s GraphQL endpoints.
First of all, you should define the desired asset. DIA uses blockchain-address asset identification methodology. You can search for available assets and find out blockchain/address information in the DIA APP asset explorer.
Here’s an example how to define FeedSelection query to return a price for a given range with all sources included:
There are number of ways to filter desired sources from the entire sources library for a given asset. We’ll go over examples of these filters.
To select specific exchanges you can use the following format:
It is also possible to select specific pairs from a given exchange. The query would look as follows:
Another filtering option is to include sources based on available liquidity in the pool. For example if you select a liquidity threshold of 5 000 000 liquidity. The query looks as follows:
It is also possible to merge pairs selection with LiquidityThreshold
, which would result in such query:
One more option is to use two different assets to calculate one unified price. It might be useful for cross-chain assets, e.g. DAI on ETH mainnet & DAI on Arbitrum One. The query which can be used for such cases would look as follows:
Response fields
In the table below you can find the description of response fields:
Field | Description |
---|---|
Time | Time at which the value was generated |
Value | Price of an asset at a give time |
Pools | Pools which had a trade during the block time period and were involved in the price calculation |
Pairs | CEX pairs which had a trade during the block time period and were involved in the price calculation |
Blockchain | Blockchain of an asset |
Address | Address of an asset |