npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

bitquery-crypto-price

v1.5.1

Published

SDK for fetching and streaming real-time and historical crypto prices using Bitquery's Trading API. Provides easy-to-use functions for token prices, OHLC candles, market data, and WebSocket streams.

Readme

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.