Skip to content

Assets and Prices API ​

Getting Started ​

This guide will help you get started with the Assets and Prices API.

The Assets and Prices API is a free API that provides real-time and historical data on assets and prices for various blockchains. The API is designed to be easy to use and provides a wide range of data, including:

  • Asset information, such as name, symbol, and decimals
  • Price information, such as current price, market cap, and 24-hour trading volume
  • Historical price data, such as price changes over time

The API is available for a wide range of blockchains, including Ethereum, Binance Smart Chain, and Solana, and supports a variety of assets, such as tokens, coins, and NFTs.

The base URL for all API endpoints is: https://gql-router.xdefi.services/graphql

Get Assets Tokens ​

Get Assets Tokens provides information about tokens on various blockchains, including Ethereum, Binance Smart Chain, and Solana. The API returns data such as the token's name, symbol, icon, market cap, price, and contracts.

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";

const query = `
  query Tokens($page: ConnectionArgs!, $after: DateTime, $afterPrice: DateTime, $filter: TokenFilter) {
    assets {
      tokens(page: $page, after: $after, afterPrice: $afterPrice, filter: $filter) {
        pageData {
          count
          limit
          offset
        }
        page {
          pageInfo {
            endCursor
            hasNextPage
          }
          edges {
            node {
              id
              name
              symbol
              icon
              marketCap
              price {
                amount
                scalingFactor
              }
              contracts {
                symbol
                scalingFactor
                address
                chain
                id
              }
            }
          }
        }
      }
    }
  }`;

const vars = {
  page: {
    first: 5,
    before: null,
    after: null,
    last: null,
  },
  after: null,
  afterPrice: null,
  filter: {
    address: null,
    chains: null,
    ids: null,
    symbols: null,
  },
};

const getAssetsTokens = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
      variables: vars,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getAssetsTokens();
js
{
  "page": {
    "first": Float,
    "before": String | null,
    "after": String | null,
    "last": Float | null
  },
  "after": DateTime | null,
  "afterPrice": DateTime | null,
  "filter": {
    "address": [String!] | null,
    "chains": [AssetChain!] | null,
    "ids": [String!] | null,
    "symbols": [String!] | null
  }
}

Get Assets Supported Chains ​

Get Assets Supported Chains provides information about the supported chains for assets on the platform. The API return a list of supported chains, including Ethereum, Binance Smart Chain, Solana, and others.

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `
  query SupportedChains {
    assets {
      supportedChains
    }
  }`;

const getSupportedChains = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getSupportedChains();

Get Assets Crypto Currencies ​

Get Assets Crypto Currencies provides information about cryptocurrencies on various blockchains, including Ethereum, Binance Smart Chain, and Solana. The API returns data such as the cryptocurrency's name, symbol, icon, type, external data, scaling factor, chain, market cap, and price.

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `
  query CryptoCurrencies($page: ConnectionArgs!, $filter: CryptoCurrencyFilter, $afterPrice: DateTime, $after: DateTime) {
    assets {
      cryptoCurrencies(page: $page, filter: $filter, afterPrice: $afterPrice, after: $after) {
        pageData {
          count
          limit
          offset
        }
        page {
          pageInfo {
            hasNextPage
            endCursor
          }
          edges {
            node {
              id
              name
              symbol
              icon
              type
              externalData
              marketCap
              scalingFactor
              chain
              price {
                amount
              }
            }
          }
        }
      }
    }
  }`;

const vars = {
  page: {
    first: 5,
    after: null,
  },
  filter: {
    chains: null,
    ids: null,
    symbols: null,
  },
  afterPrice: null,
  after: null,
};

const getCryptoCurrencies = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
      variables: vars,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getCryptoCurrencies();
js
{
  "page": {
    "first": Float,
    "after": String | null
  },
  "filter": {
    "chains": [AssetChain!] | null,
    "ids": [String!] | null,
    "symbols": [String!] | null
  },
  "afterPrice": DateTime | null,
  "after": DateTime | null
}

Get Crypto Assets ​

Get Crypto Assets provides information about crypto assets on various blockchains, including Ethereum, Binance Smart Chain, and Solana. The API returns data such as the crypto asset's name, symbol, icon, type, external data, scaling factor, chain, market cap, and price.

Query GraphQL directly here

Chains supported in Get Assets Supported Chains

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `
  query CryptoAssets($input: [CryptoAssetArgs!]!) {
  assets {
    cryptoAssets(input: $input) {
      chain
      contract
      decimals
      id
      image
      name
      price {
        scalingFactor
        amount
      }
      symbol
      type
    }
  }
}`;

const vars = {
  input: [
    {
      chain: "Bitcoin", 
    },
    {
      chain: "Ethereum", 
    },
  ],
};

const getCryptoAssets = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
      variables: vars,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getCryptoAssets();
js
{
  input: [
    {
      chain: String,
    },
    ...
  ]
}

Get Assets Fiat Currencies ​

Get Assets Fiat Currencies provides information about fiat currencies on various blockchains, including Ethereum, Binance Smart Chain, and Solana. The API returns data such as the fiat currency's name, symbol, scaling factor, character, and price.

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `
  query FiatCurrencies($page: ConnectionArgs!, $filter: FiatCurrencyFilter, $after: DateTime, $afterPrice: DateTime) {
    assets {
      fiatCurrencies(page: $page, filter: $filter, after: $after, afterPrice: $afterPrice) {
        pageData {
          count
          limit
          offset
        }
        page {
          pageInfo {
            endCursor
            hasNextPage
          }
          edges {
            node {
              id
              name
              symbol
              scalingFactor
              character
              price {
                amount
              }
            }
          }
        }
      }
    }
  }`;

const vars = {
  page: {
    first: 5, 
    after: null, 
  },
  filter: {
    ids: null, 
  },
  after: null, 
  afterPrice: null, 
};

const getFiatCurrencies = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
      variables: vars,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getFiatCurrencies();
js
{
  "page": {
    "first": Float,
    "after": String | null
  },
  "filter": {
    "ids": [String!] | null
  },
  "after": DateTime | null,
  "afterPrice": DateTime | null
}

Get Trending Tokens provides information about trending tokens Top Market Cap/Gainers/Losers. The API returns data such as the token's symbol, scaling factor, address, chain, fees, defi protocols, and external data.

Get Top Market Cap Tokens ​

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";

const query = `query TopMarketCap {
  assets {
    topMarketCap {
      assetId
      chains
      name
      price {
        amount
        scalingFactor
        marketCapRank
        dailyHigh
        dailyLow
        allTimeLow
        allTimeHigh
      }
      symbol
      type
    }
  }
}`;

const getTopMarketCapTokens = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getTopMarketCapTokens();

Get Gainers Tokens ​

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";

const query = `query Gainers {
  assets {
    gainers {
      assetId
      chains
      name
      price {
        amount
        scalingFactor
        dailyHigh
        dailyLow
        allTimeLow
        allTimeHigh
      }
      symbol
      type
    }
  }
}`;

const getGainersTokens = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getGainersTokens();

Get Losers Tokens ​

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";

const query = `query Losers {
  assets {
    losers {
      assetId
      chains
      name
      price {
        amount
        scalingFactor
        dailyHigh
        dailyLow
        allTimeLow
        allTimeHigh
      }
      symbol
      type
    }
  }
}`;

const getLosersTokens = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};

getLosersTokens();

Get LP Tokens ​

Get LP Tokens is fully the same structure as Get Assets Tokens but it’s like "Low Priority" tokens. The API returns data such as the LP token's symbol, scaling factor, address, chain, fees, defi protocols and external data.

Query GraphQL directly here

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `
  query LPTokens($page: ConnectionArgs!, $filter: TokenFilter, $after: DateTime, $afterPrice: DateTime) {
    assets {
      lpTokens(page: $page, filter: $filter, after: $after, afterPrice: $afterPrice) {
        pageData {
          count
          limit
          offset
        }
        page {
          pageInfo {
            endCursor
            hasNextPage
          }
          edges {
            node {
              contracts {
                id
                symbol
                scalingFactor
                address
                chain
                fee {
                  value
                }
                defiProtocol {
                  chain
                  icon
                  name
                }
              }
              externalData
              id
              icon
              name
              marketCap
              price {
                amount
              }
              symbol
              type
            }
          }
        }
      }
    }
  }`;

const vars = {
  page: {
    first: 5,
    after: null,
    before: null,
    last: null,
  },
  filter: {
    symbols: null,
    ids: null,
    chains: null,
    address: null,
  },
  after: null,
  afterPrice: null,
};

const getAssetsLPTokens = async () => {
  await fetch(GRAPHQL_ENDPOINT, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query,
      variables: vars,
    }),
  })
    .then((response) => response.json())
    .then((result) => {
      console.log(result);
      // Handle the result
    });
};
js
{
  "page": {
    "first": Float,
    "after": String | null,
    "before": String | null,
    "last": Float | null
  },
  "filter": {
    "symbols": [String!] | null,
    "ids": [String!] | null,
    "chains": [AssetChain!] | null,
    "address": [String!] | null
  },
  "after": DateTime | null,
  "afterPrice": DateTime | null
}

Composite Tokens ​

Coming soon!

Subscription Service ​

Subscription Service is a service that allows you to subscribe to real-time updates for assets and prices. Flow the below steps to subscribe to the service:

  1. Get all added by user asset ids Get all added by user asset ids
  2. Subscribe on them using subscription service
  3. Keep up to date his assets and total amount (on the top of wallet)

When you subscribe to the service, you will receive real-time updates for the assets and prices you are interested in. This allows you to stay informed about the latest changes in the market and make informed decisions about your investments. Checkout the websockets API for more information.

Here is the example for Subscription Assets Prices

javascript
import * as pkg from "@apollo/client";
import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
import { createClient } from "graphql-ws";

const { gql, ApolloClient, InMemoryCache } = pkg;

const wsLink = new GraphQLWsLink(
  createClient({
    url: "wss://subscription-service.dev.xdefi.services/graphql",
  }),
);

const query = gql`
  subscription Subscription($ids: [String!]) {
    price(ids: $ids) {
      chain
      id
      price {
        amount
      }
      symbol
      type
      name
      contracts {
        address
        chain
        symbol
        scalingFactor
        defiProtocol {
          icon
          chain
          name
        }
        id
      }
      icon
      externalData
      marketCap
      scalingFactor
    }
  }
`;

const vars = {
  ids: [],
};

const subscriptionServices = async () => {
  if (loading) {
    setLoading(false);
    return;
  }
  setLoading(true);
  setResponse({});

  const client = new ApolloClient({
    link: wsLink,
    cache: new InMemoryCache(),
  });

  client
    .subscribe({
      query,
      variables: vars,
    })
    .subscribe({
      next: (data) => {
        console.log(data);
        // Handle the data
      },
      error: (error) => {
        console.error(error);
      },
      complete: () => {
        console.log("completed");
      },
    });
};

subscriptionServices();