DEV Community

Divyasshree for Bitquery

Posted on

Token Price API for Crypto Developers

The Token Price API provides comprehensive price data from over 40 different blockchains. In this blog, we will explore how developers can utilize it to create applications and analyze blockchain data.

1. Real-Time & Historical Token Prices

Bitquery’s Token Price API helps in accessing both real-time and historical token prices, making it indispensable for market analysis and trading strategy development. This feature allows users to track price movements, identify trends, and analyze market behavior over different timeframes. The historical data aspect is particularly valuable for back-testing trading algorithms and understanding long-term market trends.

Below is the query to check Historical Prices of Blur Token.

{
  EVM(dataset: combined, network: eth) {
    buyside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x5283d291dbcf85356a21ba090e6db59121208b44"}}, Seller: {is: "0x1111111254eeb25477b68fb85ed929f73a960582"}}}, Block: {Time: {since: "2023-03-03T01:00:00Z", till: "2023-03-05T05:15:23Z"}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
    sellside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Sell: {Currency: {SmartContract: {is: "0x5283d291dbcf85356a21ba090e6db59121208b44"}}, Buyer: {is: "0x1111111254eeb25477b68fb85ed929f73a960582"}}}, Block: {Time: {since: "2023-03-03T01:00:00Z", till: "2023-03-05T05:15:23Z"}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Below is the query to check Real-Time Prices of Blur Token.

{
  EVM(dataset: combined, network: eth) {
    buyside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x5283d291dbcf85356a21ba090e6db59121208b44"}}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
    sellside: DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0x5283d291dbcf85356a21ba090e6db59121208b44"}}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

2. DEX Support ( Uniswap, SuShiswap, ... ):

Bitquery’s Token Price API supports real-time trade data for 1+ million tokens from 100+ DEXs & 14+ chains. This wide-ranging coverage is crucial for a complete market analysis, allowing users to compare and analyze token performance across different types of exchanges. This feature is especially beneficial for traders and investors who operate across various platforms, offering them a unified view of the market landscape.

Below is the query to check the latest prices of token on Uniswap v3.

{
  EVM(dataset: combined, network: eth) {
    buyside: DEXTrades(
      limit: {count: 5}
      orderBy: {descending: Block_Time}
      where: {Trade: {Buy: {Currency: {SmartContract: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}}, Dex: {ProtocolName: {is: "uniswap_v3"}}}}
    ) {
      Block {
        Number
        Time
      }
      Transaction {
        From
        To
        Hash
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            Symbol
            SmartContract
          }
          Seller
          Price
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
            Symbol
          }
          Seller
          Price
        }
        Dex {
          ProtocolFamily
          ProtocolName
          SmartContract
          Pair {
            SmartContract
          }
        }
      }
    }
  }
}


Enter fullscreen mode Exit fullscreen mode

3. OHLC Data (Open, High, Low, Close):

Bitquery’s Token Price API helps in retrieving OHLC (Open, High, Low, Close) data and distinct buy/sell information on a daily basis. Users can adjust the parameters within the ‘where’ and ‘Block’ sections to customize the query for their specific needs, such as changing the token smart contract addresses or modifying the date range.

The query below retrieves the OHLC (Open, High, Low, Close) prices and volume for the WETH-USDT pair on Uniswap v3, providing daily updates.

query MyQuery {
  EVM(dataset: combined) {
    DEXTradeByTokens(
      orderBy: {descending: Block_Date}
      where: {Trade: {Currency: {SmartContract: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}, Side: {Currency: {SmartContract: {is: "0xdac17f958d2ee523a2206206994597c13d831ec7"}}, Type: {is: buy}}, Dex: {SmartContract: {is: "0x4e68ccd3e89f51c3074ca5072bbac773960dfa36"}}}}
      limit: {count: 10}
    ) {
      Block {
        Date(interval: {in: days, count: 1})
      }
      volume: sum(of: Trade_Amount)
      Trade {
        high: Price(maximum: Trade_Price)
        low: Price(minimum: Trade_Price)
        open: Price(minimum: Block_Number)
        close: Price(maximum: Block_Number)
        Currency {
          Name
        }
        Dex {
          ProtocolName
          SmartContract
        }
        Side {
          Currency {
            Name
            SmartContract
          }
        }
      }
      count
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

4. Liquidity & Pairs:

This API also enables users to conveniently retrieve information about liquidity providers, trading volumes, fees, and other essential metrics for a wide range of pools.

The query below can be used to find out which tokens are part of a specific liquidity pool.

{
  EVM(dataset: archive, network: arbitrum) {
    DEXTrades(
      where: {Trade: {Dex: {SmartContract: {is: "0xcda53b1f66614552f834ceef361a8d12a0b8dad8"}}}}
      limit: {count: 1}
    ) {
      Trade {
        Dex {
          OwnerAddress
          SmartContract
          Pair {
            SmartContract
          }
        }
        Buy {
          Currency {
            SmartContract
            Symbol
            Name
            ProtocolName
          }
        }
        Sell {
          Currency {
            SmartContract
            Symbol
            Name
            ProtocolName
          }
        }
      }
      Trade_Buy: sum(of: Trade_Buy_Amount)
      Trade_Sell: sum(of: Trade_Sell_Amount)
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Users can also utilize Bitquery’s Token Price API to learn about all pairs associated with a given token.

The query provided below can be used to discover all pairs associated with WETH.

{
  ethereum(network: ethereum) {
    dexTrades(
      baseCurrency: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
      options: {desc: "count", limit: 10, offset: 0, limitBy: {each: "smartContract.address.address", limit: 1}}
    ) {
      baseCurrency {
        symbol
        name
        address
      }
      quoteCurrency {
        symbol
        name
        address
      }
      smartContract {
        address {
          address
        }
      }
      count
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

How to Get Started with Bitquery?

To get started for free, please create an account here with your email: GraphQL IDE

Once created, create your first query. Join the telegram group for any doubts and support. To learn more about how to use the Bitquery API, please see the following resources:

What Developers Can Build with Bitquery Token Price API?

From enhancing the trading experience with real-time data to developing comprehensive tools for market analysis, Bitquery’s API offers a versatile platform for creative and practical solutions in the world of digital currencies. Let’s explore some of the most exciting and impactful applications that developers can bring to life using the robust features of Bitquery’s Token Price API.

1. Cryptocurrency Portfolio Tracker

Developers can leverage the Bitquery Token Price API to build dynamic cryptocurrency portfolio trackers. By integrating real-time and historical price data, these trackers can provide users with up-to-date information on the value of their investments. The API’s multi-chain data aggregation allows for tracking a wide range of assets across various blockchains, offering a comprehensive view of one’s portfolio.

Readers can follow the Crypto Dashboard Project tutorial by the Bitquery team, which guides in building a Cryptocurrency Portfolio Dashboard with React. This dashboard fetches and displays the balances of various currencies for a given Ethereum address using the Bitquery Streaming API.

2. Cryptocurrency Trading Bot

Utilizing the real-time token price data, developers can create sophisticated trading bots. These bots can execute trades based on predefined criteria, such as price fluctuations, trading volume changes, or market sentiment analysis. The historical data available through Bitquery’s API is crucial for back-testing these trading strategies, ensuring their effectiveness before deployment in live markets.

Here is a comprehensive step-by-step guide by the Bitquery team on building trading indicators for crypto data. Technical indicators are an essential tool for cryptocurrency traders, as they can help identify trends, predict price movements, and facilitate informed trading decisions. In this tutorial, we will explore how to easily calculate popular trading indicators using Bitquery APIs in Python.

3. Backtest Your Strategies

The extensive historical data provided by Bitquery’s API is a goldmine for developers aiming to backtest trading strategies. By accessing past price movements and market trends, developers can rigorously test and refine their trading algorithms, enhancing their reliability and profitability in various market conditions.

Readers can also track cryptocurrency in real-time on Telegram using Bitquery. This quick tutorial explains how to get blockchain data on Telegram chat in real-time. By following this guide, you’ll learn to program your Telegram bot to respond to the /start command by initiating a WebSocket connection with Bitquery and sending updates on blockchain data directly to the Telegram chat.

4. Cryptocurrency Price Alert System

Developers can create customizable price alert systems using Bitquery’s API. These systems can notify users of significant price movements, trading volume spikes, or other relevant market events. This tool is especially useful for traders and investors who need to stay informed about market dynamics to make timely decisions.

Here is a quick tutorial on building your own Crypto Profit and Loss Calculator using Bitquery.

5. Cryptocurrency Research and Analysis

For those interested in conducting in-depth market research and analysis, Bitquery’s Token Price API offers a wealth of data. Analysts and developers can utilize this data to identify market trends, compare token performance across different exchanges, and conduct comprehensive market analysis. This is invaluable for developing market insights, writing research papers, or creating data-driven content for cryptocurrency communities.

Here is a quick tutorial on Crypto Charts with TradingView Advanced Charts and Bitquery Data.

Conclusion

In conclusion, Bitquery’s Token Price API emerges as a powerful tool in the ever-evolving landscape of cryptocurrency and blockchain technology. From providing real-time and historical token price data to supporting a multitude of blockchains, Bitquery stands as an invaluable resource for developers, traders, and analysts alike. Whether you’re building a sophisticated trading bot, a comprehensive market analysis tool, or a simple price alert system, Bitquery offers the versatility and depth needed to succeed in the complex world of crypto. So, whether you’re a seasoned developer or just starting out in the world of blockchain, Bitquery offers a treasure trove of possibilities.

About Bitquery

Bitquery is your comprehensive toolkit designed with developers in mind, simplifying blockchain data access. Our products offer practical advantages and flexibility.

  • APIs - Explore API: Easily retrieve precise real-time and historical data for over 40 blockchains using GraphQL. Seamlessly integrate blockchain data into your applications, making data-driven decisions effortless.

  • Coinpath® - Try Coinpath: Streamline compliance and crypto investigations by tracing money movements across 40+ blockchains. Gain insights for efficient decision-making.

  • Data in Cloud - Try Demo Bucket: Access indexed blockchain data cost-effectively and at scale for your data pipeline. We currently support Ethereum, BSC, Solana, with more blockchains on the horizon, simplifying your data access.

  • Explorer - Try Explorer: Discover an intuitive platform for exploring data from 40+ blockchains. Visualize data, generate queries, and integrate effortlessly into your applications.


Written by Yash

Top comments (0)