GraphQL Endpoint

DIA made API data easily accessibly 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:

Sample Schema
query  {
     GetFeed(
      Filter: "mair",
      BlockSizeSeconds: 480,
      BlockShiftSeconds: 480,
      StartTime: 1690449575,
      EndTime: 1690535975,
      FeedSelection: [
        {
          Address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
          Blockchain:"Ethereum",
          Exchangepairs:[],
        },
      ],
    )
  {
    Name
    Time
    Value
    Address
    Pools
    Pairs
  }
}

The schema will return the moving average price of ETH calculated every 5min (300 sec) by counting 2min trade blocks.

Query parameters rundown

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:

FeedSelection: [
        {
          Address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
          Blockchain:"Ethereum",
          Exchangepairs:[],
        },
      ]

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:

FeedSelection: [
        {
          Address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
          Blockchain:"Ethereum",
          Exchangepairs:[{Exchange:"CoinBase"},{Exchange:"UniswapV3"}],
        },
      ]

It is also possible to select specific pairs from a given exchange. The query would look as follows:

FeedSelection: [
        {
          Address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
          Blockchain:"Ethereum",
          Exchangepairs:[
            {
              Exchange: "CoinBase",
              Pairs:["DAI-USD"],
            },
            {
              Exchange: "UniswapV3",
              Pairs:["0x60594a405d53811d3BC4766596EFD80fd545A270","0x6f48ECa74B38d2936B02ab603FF4e36A6C0E3A77"],
            },
       ]

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, the response will calculate the price of an asset only by including liquidity pools from DEXes which have higher than $5 000 000 liquidity. The query looks as follows:

FeedSelection: [
          {
          Address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
          Blockchain:"Ethereum",
          LiquidityThreshold:5000000.0
          Exchangepairs: [],
          },
       ]

It is also possible to merge pairs selection with LiquidityThreshold, which would result in such query:

FeedSelection: [
        {
          Address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
          Blockchain:"Ethereum",
          Exchangepairs:[
            {
              Exchange: "CoinBase",
              Pairs:["DAI-USD"],
            },
          ]
        },
        {
          Address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
          Blockchain:"Ethereum",
          LiquidityThreshold:5000000.0
          Exchangepairs: [],
        },
      ],

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:

FeedSelection: [
        {
          Address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
          Blockchain:"Ethereum",
          Exchangepairs:[]
        },
        {
          Address: "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1",
          Blockchain:"Arbitrum",
          Exchangepairs:[]
        },
      ],

Response fields

In the table below you can find the description of response fields:

In the next page you can find examples on how to query DIA's GraphQL endpoint in different programming languages.

Last updated