Skip to content

bitquery/crypto-price-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Crypto Price API

πŸ“Š Crypto Price API is a lightweight suite of API provided by Bitquery to fetch and stream live cryptocurrency prices, historical data, and token analytics across multiple blockchains, using its Trading API Endpoints.


What is Crypto Price API?

A Crypto Price API allows developers to access real-time and historical cryptocurrency prices programmatically. Bitquery’s Crypto Price API provides data for tokens across chains like Ethereum, Solana, BSC, Polygon, and Tron β€” all through simple GraphQL queries or WebSocket streams.


πŸš€ Crypto Price API Features

  • Get the latest token price in USD
  • Stream live token price updates
  • Get price change percentage for ROI calculations
  • Get token volume data with configurable time intervals
  • Stream live token volume updates
  • Get volume data for multiple tokens simultaneously
  • Stream live volume updates for multiple tokens simultaneously
  • Convert token addresses into currencyId for queries
  • Extendable query SDK workflow for adding new APIs
  • Open source & developer-friendly

List of Chains Supported by Crypto Price API

How Does


πŸ“¦ Installation

npm install bitquery-crypto-price

Access Token

Get Your Bitquery Access Token here


⚑ Quick Start for Crypto Price API

1. Get the latest price for a token

const { getTokenPrice } = require("bitquery-crypto-price");

(async () => {
  const data = await getTokenPrice("<Access Token>", "TOKEN ADDRESS");
  console.log(data);
})();

2. Stream live token price updates

const { getTokenPriceStream } = require("bitquery-crypto-price");

const ws = getTokenPriceStream("<Access Token>", "TOKEN ADDRESS", {
  autoCloseMs: 15000, // optional: auto-close after 15 seconds
  onData: (data) => {
    console.log("Live BTC Price:", JSON.stringify(data, null, 2));
  },
  onError: (err) => {
    console.error("Stream error:", err);
  },
});

// ws.close() // manually close if needed

3. Get 5-min price change of a token

const { getPriceChange } = require("bitquery-crypto-price");

(async () => {
  const data = await getPriceChange("<Access Token>", "CURRENCY_ID");
  console.log( JSON.stringify(data, null, 2));
})();

4. Stream live price change updates

const { getPriceChangeStream } = require("bitquery-crypto-price");

const ws = getPriceChangeStream("<Access Token>", "CURRENCY_ID", {
  autoCloseMs: 30000, // optional: auto-close after 30 seconds
  onData: (data) => {
    console.log("Live price changes:", JSON.stringify(data, null, 2));
  },
  onError: (err) => {
    console.error("Stream error:", err);
  },
});

// ws.close() // manually close if needed

5. Get token volume data

const { getTokenVolume } = require("bitquery-crypto-price");

(async () => {
  const data = await getTokenVolume("<Access Token>", "TOKEN ADDRESS", 3600); // 3600 = 1 hour interval
  console.log(JSON.stringify(data, null, 2));
})();

6. Stream live token volume updates

const { getTokenVolumeStream } = require("bitquery-crypto-price");

const ws = getTokenVolumeStream("<Access Token>", "TOKEN ADDRESS", {
  interval: 3600, // optional: time interval in seconds (default: 3600)
  autoCloseMs: 30000, // optional: auto-close after 30 seconds
  onData: (data) => {
    console.log("Live token volume:", JSON.stringify(data, null, 2));
  },
  onError: (err) => {
    console.error("Stream error:", err);
  },
});

// ws.close() // manually close if needed

7. Get volume data for multiple tokens

const { getMultipleTokenVolume } = require("bitquery-crypto-price");

(async () => {
  const tokenAddresses = [
    "0x4d15a3a2286d883af0aa1b3f21367843fac63e07", // WETH
    "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
    "0xdac17f958d2ee523a2206206994597c13d831ec7"  // USDT
  ];
  const data = await getMultipleTokenVolume("<Access Token>", tokenAddresses, 3600); // 3600 = 1 hour interval
  console.log(JSON.stringify(data, null, 2));
})();

8. Stream live volume updates for multiple tokens

const { getMultipleTokenVolumeStream } = require("bitquery-crypto-price");

const tokenAddresses = [
  "0x4d15a3a2286d883af0aa1b3f21367843fac63e07", // WETH
  "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
  "0xdac17f958d2ee523a2206206994597c13d831ec7"  // USDT
];

const ws = getMultipleTokenVolumeStream("<Access Token>", tokenAddresses, {
  interval: 3600, // optional: time interval in seconds (default: 3600)
  autoCloseMs: 30000, // optional: auto-close after 30 seconds
  onData: (data) => {
    console.log("Live multiple token volumes:", JSON.stringify(data, null, 2));
  },
  onError: (err) => {
    console.error("Stream error:", err);
  },
});

// ws.close() // manually close if needed

πŸ› οΈ Available Functions

Function Description
getCurrencyId Get currencyId from a token address (required for queries)
getTokenPrice Fetch the latest token price (point-in-time query)
getTokenPriceStream Subscribe to real-time token price updates (WebSocket stream)
getPriceChange Get top tokens by price change percentage (point-in-time query)
getPriceChangeStream Subscribe to real-time price change updates (WebSocket stream)
getTokenVolume Fetch token volume data (point-in-time query)
getTokenVolumeStream Subscribe to real-time token volume updates (WebSocket stream)
getMultipleTokenVolume Fetch volume data for multiple tokens (point-in-time query)
getMultipleTokenVolumeStream Subscribe to real-time volume updates for multiple tokens (WebSocket stream)

πŸ’° Subscription/Stream Pricing

When using the stream functions (*Stream functions), you are charged based on simultaneous active streams. We don't count based on number of tokens monitored.

  • Billing Model: Each active stream subscription is charged
  • Separate Subscriptions: Each stream function call counts as a separate subscription:
    • getTokenPriceStream() = 1 subscription
    • getMultipleTokenVolume() = 1 subscription
    • getTokenVolumeStream() = 1 subscription
    • Running multiple streams simultaneously = multiple subscriptions

Important Notes:

  • Billing is based on number of subscriptions and duration, not query complexity or data volume
  • Check your points usage and manage subscriptions at your Bitquery Account Dashboard

For detailed pricing information, contact sales by filling the form on the Bitquery website

🧩 Extending the Crypto Price API (Adding New Queries and Streams)

To add support for more Trading APIs (e.g., OHLC candles, trades, liquidity pools):

Workflow

  1. Create a new query file in queries/ with naming convention: <result-returned>-query.js Example: sample-query.js

    const sampleQuery = (currencyId) => {
      return `
      <Your GraphQL Query>
      `;
    };
    
    const sampleStream = (currencyId) => {
      return `
      <Your GraphQL Subscription>
      `;
    };
    
    module.exports = { sampleQuery, sampleStream };
  2. Import into index.js:

    const { sampleQuery, sampleStream } = require("./queries/sample-query.js");
  3. Wrap with a function for queries or streams in index.js:

    const getSample = async (token, tokenId) => {
      const query = sampleQuery(tokenId);
      const data = await queryRunner(query, token);
      return data;
    };
    
    const getSample = (token, tokenId, options = {}) => {
      const subscription = sampleStream(tokenId);
      return streamRunner(subscription, token, options);
    };

That’s it! Your new query is available to all SDK users after PR merge and release.


🀝 Contributing

  1. Fork this repo https://github.com/bitquery/crypto-price-api
  2. Create a feature branch
  3. Follow the workflow for adding queries
  4. Submit a PR πŸŽ‰
  5. Make sure to follow the Contribution Guidelines

πŸ“œ License

MIT License. Free to use and modify.


Contact

Contact our team via Telegram for any support. Fill out this form, if you are interested in purchasing any product or service from Bitquery.