Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
cryptocurrency-price-kit
Advanced tools
The best price kit you need when working with crypto currencies with realtime and multiple providers support.
RFC
The best Nodejs price kit you need when working with cryptocurrencies with multiple providers support.
npm install cryptocurrency-price-kit
# OR
yarn add cryptocurrency-price-kit
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);
USD
cache
is enabled by default (tll: 60 seconds)USD
cache
over interval because it is more reliable. with interval pulling
you may make unnecessary requests when not needed.This can be achieved in two ways.
Try
if the provider documentation is clear enough.)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.
Creating a custom provider is as easy as.
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.
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 hello@trapcode.io
FAQs
The best price kit you need when working with crypto currencies with realtime and multiple providers support.
We found that cryptocurrency-price-kit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.