0.1.3 • Published 5 years ago

coindesk v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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!