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 🙏

© 2024 – Pkg Stats / Ryan Hefner

btc-value

v6.0.0

Published

Get the current Bitcoin value

Downloads

166

Readme

Get the current Bitcoin value

Downloads Coverage Status

Installation

npm install btc-value

Usage

import btcValue, {
	setProvider,
	setApiKey,
	getPercentageChangeLastDay,
	getSupportedCurrencies
} from 'btc-value';

// Set the value provider
setProvider('coingecko');

// Set the API key
setApiKey('example-cmc-API-key');

// Print the current value of Bitcoin in USD
console.log(`$${await btcValue()}`);
// => e.g. $11048

// Print the current value of Bitcoin in NOK (Norwegian krone)
console.log(`kr ${await btcValue('NOK')}`);
// => e.g. kr 86664

// Print the current value of 2.2 BTC in USD
console.log(`$${await btcValue({quantity: 2.2})}`);
// => e.g. $24305.82

// Print the percentage change in BTC value the last day
console.log(`${await getPercentageChangeLastDay()} %`);
// => e.g. 5%

// Print all supported currencies for selected value provider
console.log(await getSupportedCurrencies());
// => cmc: [ ..., { name: 'Norwegian Krone', code: 'NOK', symbol: 'kr' }, ... ]
// => coingecko: [ ..., 'nok', ... ]

API

The Bitcoin value can be retrieved from CoinMarketCap or CoinGecko. See the API used for CoinMarketCap here and for CoinGecko here. If using the CoinMarketCap API to retrieve Bitcoin values, it is required to obtain and use an API key. This can be done here. Before using the functions for retrieving the Bitcoin value, one must then call btcValue.setApiKey(<KEY_HERE>) with your key. If using CoinGecko, this is not needed.

btcValue(currencyCode?)

Returns the current Bitcoin value in USD ($).

currencyCode

Type: string Default: USD

Returns the current Bitcoin value in a different currency than USD. All valid currency codes can be retrieved for the selected value provider using the getSupportedCurrencies function.

setProvider(provider)

Sets the selected provider to retrieve Bitcoin values from. Supported providers are: cmc (CoinMarketCap) and coingecko.

provider

Type: string

setApiKey(apiKey)

Sets the API key for the selected value provider. Currently only CoinMarketCap supports using an API key. This is required to call the functions with the CoinMarketCap API.

apiKey

Type: string

getPercentageChangeLastHour()

Returns the percentage change of BTC the last hour.

getPercentageChangeLastDay()

Returns the percentage change of BTC the last day.

getPercentageChangeLastWeek()

Returns the percentage change of BTC the last week.

getSupportedCurrencies()

Returns an array with all the supported currencies for the selected value provider. Example of the format for a single currency in the list using CoinMarketCap:

{
    "name": "Norwegian Krone",
    "code": "NOK",
    "symbol": "kr"
}

Example of a returned array using CoinGecko:

['btc', 'eth']

Related