1.0.0 • Published 30 days ago

coindesk-bpi v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
30 days ago

coindesk-bpi

A simple Node.js module to fetch real-time Bitcoin prices from the CoinDesk API.

Description

coindesk-bpi is a lightweight module that allows developers to easily fetch real-time Bitcoin prices in USD, GBP, and EUR from the CoinDesk Bitcoin Price Index (BPI) API. The module uses axios for making HTTP requests and returns the current Bitcoin prices along with the time of the latest update.

Installation

You can install this package using npm:

npm install coindesk-bpi

Usage

const { getBitcoinData } = require('coindesk-bpi');

(async () => {
    try {
        const data = await getBitcoinData();
        console.log('Bitcoin Data:', data);
    } catch (error) {
        console.error('Error:', error);
    }
})();

Example response

API

getBitcoinData() Fetches the current Bitcoin data from the CoinDesk API.

Returns

A promise that resolves to an object containing the entire response from the API:

{
    "time": {
        "updated": "May 17, 2024 15:37:57 UTC",
        "updatedISO": "2024-05-17T15:37:57+00:00",
        "updateduk": "May 17, 2024 at 16:37 BST"
    },
    "disclaimer": "This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org",
    "chartName": "Bitcoin",
    "bpi": {
        "USD": {
            "code": "USD",
            "symbol": "$",
            "rate": "67285.8432",
            "description": "United States Dollar",
            "rate_float": 67285.8432
        },
        "GBP": {
            "code": "GBP",
            "symbol": "£",
            "rate": "52989.9565",
            "description": "British Pound Sterling",
            "rate_float": 52989.9565
        },
        "EUR": {
            "code": "EUR",
            "symbol": "€",
            "rate": "61864.0172",
            "description": "Euro",
            "rate_float": 61864.0172
        }
    }
}
1.0.0

30 days ago