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

coindesk

v0.1.3

Published

Client for retrieving Bitcoin information from Coindesk API service

Downloads

15

Readme

CoinDesk API client

Powered by CoinDesk

Node.js client written in Javascript for CoinDesk API service.

If you like this package please give it a :star: in the Github repo.

Features

  • Get Bitcoin current price
  • Get Bitcoin historical price

Getting Started

These instructions will get you a copy of the project on your local system.

Dependencies

CoinDesk API client for node.js uses a number of open source projects to work properly:

  • @hapi/joi - The most powerful schema description language and data validator for Javascript
  • axios - Promise based HTTP client for the browser and node.js
  • node-fetch - A light-weight module that brings window.fetch to node.js
  • winston - A logger for just about everything

And of course CoinDesk API client for node.js itself is open source with a public repository on GitHub.

Installation

Install the npm package from npmjs.com with the command:

npm install --save coindesk

Quick Start

A series of simple examples for Bitcoin price fetching:

Get currentprice price for Bitcoin in json format

const { CoindeskAPIClient } = require('coindesk');
const apiClient = CoindeskAPIClient.start('currentprice');
const response = apiClient.get()
    .then(response => response)
    .catch(err => console.error(err));

Get currentprice price for Bitcoin in other currency than USD

const { CoindeskAPIClient } = require('coindesk');
const apiClient = CoindeskAPIClient.start('currentprice', { currency: 'EUR' });
const response = apiClient.get()
    .then(response => response)
    .catch(err => console.error(err));

Get historical price for Bitcoin in json format

const { CoindeskAPIClient } = require('coindesk');
const apiClient = CoindeskAPIClient.start('historical');
const response = apiClient.get()
    .then(response => response)
    .catch(err => console.error(err));

Get historical price for Bitcoin providing optional parameters

const { CoindeskAPIClient } = require('coindesk');
const apiClient = CoindeskAPIClient.start('historical', { currency: 'EUR', for: 'yesterday' });
const response = apiClient.get()
    .then(response => response)
    .catch(err => console.error(err));

Get raw http response for either currentprice or historical (defaults to false)

const { CoindeskAPIClient } = require('coindesk');
const apiClient = CoindeskAPIClient.start('currentprice');
const response = apiClient.get(raw=true)
    .then(response => response)
    .catch(err => console.error(err));

Get supported currencies to fetch Bitcoin price in

const { CoindeskAPIClient } = require('coindesk');
const apiClient = new CoindeskAPIClient();
const supportedCurrencies = apiClient.getSupportedCurrencies();

Examples for CoinDesk API response parsing (currentprice or historical):

Parse and validate fetched Bitcoin price response

const { CoindeskAPIClient, CoindeskAPIResponse } = require('coindesk');
const dataType = 'historical';
const apiClient = new CoindeskAPIClient(dataType);
const response = apiClient.get(raw=true)
    .then(response => CoindeskAPIResponse.parse(response, dataType))
    .catch(err => console.error(err));

Get info from parsed Bitcoin price response

const { CoindeskAPIResponse } = require('coindesk');
const parsedResponse = CoindeskAPIResponse.parse(response);
const apiResponse = parsedResponse.response;
const jsonResponse = parsedResponse.JSONResponse;
const items = parsedResponse.responseItems;
const bpi = parsedResponse.getResponseItem('bpi');

Full documentation for CoinDesk API is available at https://www.coindesk.com/api/.

License

MIT

Free Software. Hell Yeah!