The best Nodejs price kit you need when working with cryptocurrencies with multiple providers support

Overview

Cryptocurrency Price Kit

STAGE: RFC

The best Nodejs price kit you need when working with cryptocurrencies with multiple providers support.

Goal

  • To provide a simple and easy to use API for working with cryptocurrency prices.
  • To provide a simple API to support multiple data providers
  • To provide cache support, so you only send request to the provider once per minute.
  • To support as many providers as possible.

Installation

npm install cryptocurrency-price-kit
# OR
yarn add cryptocurrency-price-kit

Easy As

const {Cpk} = require('cryptocurrency-price-kit');
const BlockchainInfo = require("cryptocurrency-price-kit/providers/blockchain.info");
const CoinGecko = require("cryptocurrency-price-kit/providers/coingecko.com");
const LiveCoinWatch = require("cryptocurrency-price-kit/providers/livecoinwatch.com");

// Add Providers
Cpk.useProviders([
    BlockchainInfo, // supports bitcoin only
    CoinGecko, // supports almost all coins
    LiveCoinWatch({apiKey: "your-api-key"}), // supports almost all coins
])


async function Run(){
  // Initialize
  const blockchain = new Cpk('blockchain.info');
  const coingecko = new Cpk('coingecko.com');
  const livecoinwatch = new Cpk('livecoinwatch.com');
  
  // Get bitcoin Price and cache for 60 secs by default
  const price = await blockchain.get('BTC');
  // or with custom cache time
  const price2 = await blockchain.get('BTC/EUR', 120); // seconds
  
  console.log("Blockchain - BTC/USD:", price); // The current price of bitcoin in USD
  console.log("Blockchain - BTC/EUR:", price2); // The current price of bitcoin in USD
  
  // OR
  // GET Many Prices and cache for 60 secs
  const prices = await livecoinwatch.getMany(['BTC/USD', 'ETH/USD', "BNB/USD"], 60);
  console.log('LiveCoinWatch - Many:', prices) // {BTC/USD: price, ETH/USD: price, BNB/USD: price}
  
  // Also supports using the symbol your provider supports
  // e.g coingecko supports using code instead of symbol
  // i.e `bitcoin` instead of `BTC`
  const prices2 = await coingecko.getMany(["BITCOIN/EUR", "ETHEREUM", "KADENA"], 60);
  console.log("CoinGecko: Many:", prices2); // {BITCOIN/EUR: price, ETHEREUM/USD: price, KADENA/USD: price}
}

Run().catch(console.error);

What you should know.

  • Default currency is USD
  • cache is enabled by default (tll: 60 seconds)
  • If currency is not defined, it will be USD
  • Error is thrown if request is not successful, so you should catch all requests.
  • We prefer cache over interval because it is more reliable. with interval pulling you may make unnecessary requests when not needed.

Supported providers

Adding custom provider

This can be achieved in two ways.

  • Create an issue on GitHub requesting a certain provider, and we will try to add it. (Try if the provider documentation is clear enough.)
  • OR See how to create it yourself: How to create a custom provider

What may come in the future.

  • Fallback to other providers if the first one fails.
  • Command line support: E.g. npx cpk update-supported-data should update the providers supported coins and currency array. This is considered important because the majority of the providers have an endpoint where your can get the coins and currency they support.
    if supported coins and currency are updated frequently, it will reduce the amount of error requests that may cost you depending on your provider.

How to create a custom provider

Creating a custom provider is as easy as.

{ return { name: 'provider-domain.com', coinsSupported: ['BTC', 'ETH'] || "any", // if any no validation is done currenciesSupported: ['USD', 'EUR'] || "any", // if any no validation is done // This is the function that will be called to get the price // It will be called with the coin and currency as arguments // The async function should return the price async getPrice(coin, currency) { // return the price return 0; }, // This is the function that will be called to get multiple prices // It will be called with array of coins and currency as arguments // The async function should return the prices as object // The object should have the coin/key and the price as value // E.g. {"BTC/USD": 0, "ETH/EUR": 0} async getPrices(pairs) { // return the prices for (const pair of pairs) { // pair.coin, pair.currency } return {}; } } }) module.exports = CustomProvider;">
const {defineCpkProvider} = require("cryptocurrency-price-kit/src/provider");

// Define a provider
// `config` is an object that contains the configuration passed for the provider.
const CustomProvider = defineCpkProvider((config) => {
    return {
       name: 'provider-domain.com',
       coinsSupported: ['BTC', 'ETH'] || "any", // if any no validation is done
       currenciesSupported: ['USD', 'EUR'] || "any", // if any no validation is done
       
       // This is the function that will be called to get the price
       // It will be called with the coin and currency as arguments
       // The async function should return the price
       async getPrice(coin, currency) {
           // return the price
           return 0;
       },
       
       // This is the function that will be called to get multiple prices
       // It will be called with array of coins and currency as arguments
       // The async function should return the prices as object
       // The object should have the coin/key and the price as value
       // E.g. {"BTC/USD": 0, "ETH/EUR": 0}
       async getPrices(pairs) {
           // return the prices
           for (const pair of pairs) {
               // pair.coin, pair.currency
           }
           return {};
       }
   }
})

module.exports = CustomProvider;

That's all 😁 , all cache function is handled by the package, so you don't need to worry about it. Only return the values, and we will handle the rest.

Sponsor/support

If you like this project, you can support it. Any amount can keep the coffee going. 😁

Coin Address
BTC bc1q4el6ukfe0762rng62gw9augvq49evj3rxh6w09
ETH 0xb39bD9cF75BF29888cB80Cf374ee0822714E31a5
Solana BxcHDVsrk1Y9sX5vqskcMJDhHDT8HkqgYQdZGFMuZKPd
Polygon Matic 0x14033a7232232cf3c6a0671f00ad015df6a6c220

If you want to be listed as sponsor after sending a donation, please contact [email protected]

You might also like...

The best Blooket hacks on the platform! These hacks are always working, all gamemode hacks work and will be fixed when broke.

The best Blooket hacks on the platform! These hacks are always working, all gamemode hacks work and  will be fixed when broke.

Support Discord Server: https://discord.gg/UCHtVM4A Blooket Hack The Blooket Hack provided by Jude Why you should use this tool: Always working. When

Dec 20, 2022

Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Nov 2, 2022

"To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. You will build a simple website that allows for doing that, and you will do it using ES6 and Webpack!

To-do-list Description "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark t

Oct 18, 2022

A superfast and easy to use knowledge base to help your customers get the info they need, when they need it most.

A superfast and easy to use knowledge base to help your customers get the info they need, when they need it most.

A superfast and easy to use knowledge base to help your customers get the info they need, when they need it most. helpkb is an open-source Next.js (A

Dec 5, 2022

The only Backend you'll ever need. Written in NodeJS, works with any stack

The only Backend you'll ever need. Written in NodeJS, works with any stack Conduit Platform Conduit is a NodeJS-based Self-Hosted backend, that aims t

Jan 3, 2023

This project is based on my nodejs starter kit. Simple CRUD project.

nodejs-crud-project Author - Akhil Sharma This project uses the nodeJS-starter project on my github. Just a demo to show you could build any project w

Dec 16, 2022

Ethereum Smart Contracts for locking your Ether and ERC20 tokens based on time and price conditions

SmartHold - a simple way to lock and hold your ETH or ERC20 in a smart contract This is a BETA software that has not been audited for security. USE AT

May 5, 2022

Calculate the price range for property advertised on Domain and Real Estate.

Calculate the price range for property advertised on Domain and Real Estate.

Property Seeker Calculate the price range for property advertised on Domain and Real Estate. Install Chrome Firefox Edge Privacy All searches are perf

Dec 27, 2022

πŸͺ™πŸ’¬ Update a gist to contain a crypto price

πŸͺ™πŸ’¬ Update a gist to contain a crypto price

crypto-box Update a pinned gist to contain a crypto price πŸ“Œ ✨ For more pinned-gist projects like this one, check out: matchai/awesome-pinned-gists Se

Nov 30, 2022
Owner
TrapCode
Open Source Philanthropist πŸ‘¨β€πŸ’»
TrapCode
An IoT bottle that tracks water consumption. Winner of Best Health Hack, MLH's Best Hardware Hack, and QB3's Best Big Data for the Improvement of Health Care Winner at CruzHacks 2022.

An IoT bottle that tracks water consumption. Winner of Best Health Hack, MLH's Best Hardware Hack, and QB3's Best Big Data for the Improvement of Health Care Winner at CruzHacks 2022.

Nathanael Garza 2 Jan 21, 2022
CryptoList allows users to find out the latest information about top cryptocurrencies

CryptoList allows users to find out the latest information about top cryptocurrencies. The app allows users to find the most popular currencies, sort them out by market cap, gainers, and losers.

Eapen Zacharias 4 Aug 19, 2022
Web app to display potential profits of cryptocurrencies.

What_If With the recent stock market and cryptocurrency rally in the past two years I often found myself wondering how much would I have made if I bou

null 3 Feb 12, 2022
The world of cryptocurrencies is diverse and becoming more and more popular

We are providing an user with a simple learning resource for an intro into the CryptoCurrency World. Along with a community grown message board to assist with further learning.

null 3 Jun 20, 2022
πŸ€–β€An action that fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with them from time to time.

Discord Guardian Action ??  This action fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with t

Dalton Menezes 7 Nov 30, 2022
Express middleware for easy OAuth with a variety of providers.

accounted4 Express middleware for easy OAuth2 with a variety of providers. accounted4 is intended to make it easy for developers to add third-party OA

Josh Moore 3 May 7, 2022
πŸ“¬ A quick comparison of private and / or secure email providers

?? Email Comparison A comparison table of private and / or secure email providers Live App The app can be accessed at: lissy93.github.io/email-compari

Alicia Sykes 47 Dec 15, 2022
A flexible gateway for running ML inference jobs through cloud providers or your own GPU. Powered by Replicate and Cloudflare Workers.

Cogflare (Working title) Cogflare is a Cloudflare Workers application that aims to simplify running distributed ML inference jobs through a central AP

NightmareBot 14 Dec 12, 2022
Bun-Bakery is a web framework for Bun. It uses a file based router in style like svelte-kit. No need to define routes during runtime.

Bun Bakery Bun-Bakery is a web framework for Bun. It uses a file based router in style like svelte-kit. No need to define routes during runtime. Quick

Dennis Dudek 44 Dec 6, 2022
Bitcoin terminal tracker is a terminal app which allow you to track bitcoin price from your terminal

BTC Terminal Tracker Bitcoin terminal tracker is a terminal app which allow you to track bitcoin price from your terminal. In this version (V1.2) I ch

Sina yeganeh 9 Jul 27, 2022