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.
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();
{
"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.
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.
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();
{
"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.
Chains supported in Get Assets Supported Chains
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();
{
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.
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();
{
"page": {
"first": Float,
"after": String | null
},
"filter": {
"ids": [String!] | null
},
"after": DateTime | null,
"afterPrice": DateTime | null
}
Get Trending Tokens β
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 β
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 β
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 β
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.
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
});
};
{
"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 β
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:
- Get all added by user asset ids
- Subscribe on them using subscription service
- 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
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();