Price Endpoints

Single

The price endpoint,

/v1/tokens/<chain id>/<token address>/price

returns the price of a token, at a requested block, denominated in any other token.

You will find the formal API definition here. To learn more about how prices are extracted from on-chain data, please read the following blog post.

The token address and chain ID are encoded in the URL.

The address of the token in which the price should be quoted can be passed in the optional argument quoteAddress. The default quoteAddress is 0x0000000000000000000000000000000000000348, i.e., USD.

By default this endpoint returns prices derived from on-chain data, i.e., liquidity pools and swaps. These price computations are typically a few blocks behind the present. This means that if the latest price is requested, the result will almost certainly be from our fallback price source, Chainlink.

If the caller wants to prioritize Chainlink as a data source, the input value src should be set to "cex". src's default value is "dex".

The result will always include the following values:

  • src, which will either be "dex" or "cex" depending on the source of the data.

  • srcInternal, which will have one of the following three values:

    • "db"

    • "model"

    • "cache"

    In future other values may be added. Note that srcInternal is primarily used for debugging purposes. That value should never be relevant to clients unless they are performance-testing the API.

Multiple

The price/historical endpoint,

/v1/tokens/<chain id>/<token address>/price/historical

returns a list of prices over time for a token.

The list start and end, as well as periodicity arguments are described in the Historical Data section.

Given the following call, which requests prices for three blocks:

curl \
-H 'Authorization: Bearer <API KEY>' \
'https://gateway.credmark.com/v1/tokens/1/0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9/price/historical?src=dex&startBlockNumber=14966197&endBlockNumber=14966200&blockInterval=1'

the endpoint returns:

{
  "chainId": 1,
  "startBlockNumber": 14966197,
  "endBlockNumber": 14966200,
  "startTimestamp": 1655276429,
  "endTimestamp": 1655276478,
  "tokenAddress": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9",
  "quoteAddress": "0x0000000000000000000000000000000000000348",
  "data": [
    {
      "blockNumber": 14966197,
      "blockTimestamp": 1655276429,
      "price": 57.240959146167235,
      "src": "dex",
      "srcInternal": "db"
    },
    {
      "blockNumber": 14966198,
      "blockTimestamp": 1655276469,
      "price": 57.24095884036671,
      "src": "dex",
      "srcInternal": "db"
    },
    {
      "blockNumber": 14966199,
      "blockTimestamp": 1655276471,
      "price": 57.240956525049775,
      "src": "dex",
      "srcInternal": "db"
    },
    {
      "blockNumber": 14966200,
      "blockTimestamp": 1655276478,
      "price": 57.240956525049775,
      "src": "dex",
      "srcInternal": "db"
    }
  ]
}

Last updated