coindesk.js

1.0.2 • Public • Published

coindesk.js

Support me on Patreon Buy me a book PayPal Ask me anything Version Downloads Get help on Codementor

Buy Me A Coffee

Get the current and historical Bitcoin price in different currencies, using Coindesk.

☁️ Installation

Check out the dist directory to download the needed files and include them on your page.

If you're using this module in a CommonJS environment, you can install it using npm or yarn and require it:

# Using npm
npm install --save coindesk.js

# Using yarn
yarn add coindesk.js

📋 Example

const BitcoinValue = require("coindesk.js")

BitcoinValue.historical().then(data => {
    console.log(data)
    // =>
    // { bpi:
    //    { '2017-07-08': 2579.9338,
    //      ...
    //      '2017-08-06': 3255.0025,
    //      '2017-08-07': 3431.9688 },
    //   disclaimer: 'This data was produced from the CoinDesk Bitcoin Price Index. BPI value data returned as USD.',
    //   time:
    //    { updated: 'Aug 8, 2017 00:03:00 UTC',
    //      updatedISO: '2017-08-08T00:03:00+00:00' } }
}).catch(err => {
    console.log(err)
})

BitcoinValue.current("RON", (err, data) => {
    console.log(err || data)
    // =>
    // { time:
    //    {...},
    //   disclaimer: '...',
    //   bpi:
    //    { USD:
    //       {...},
    //      RON:
    //       { code: 'RON',
    //         rate: '13,370.4374',
    //         description: 'Romanian Leu',
    //         rate_float: 13370.4374 } } }
})

BitcoinValue.historical({
    start: new Date(2011, 0, 1)
  , end: new Date(2011, 0, 31)
  , currency: "EUR"
}).then(data => {
    console.log(data)
    // =>
    // { bpi:
    //    { '2011-01-01': 0.2243,
    //        ...
    //      '2011-01-30': 0.3513,
    //      '2011-01-31': 0.3796 },
    //   disclaimer: '...',
    //   time:
    //    {...} }
}).catch(err => {
    console.error(err)
})

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. 🐛
  3. For direct and quick help, you can use Codementor. 🚀

📝 Documentation

current(currency, cb)

Fetches the current price.

Params

  • String currency: The currency. If not provided, the Bitcoin price will be fetched in different currencies.
  • Function cb: The callback function.

Return

  • Promise The request object with a promise.

historical(opts, cb)

Fetches the Bitcoin prices from the past.

Params

  • Object opts: An object containing the following fields:
    • index (String): [USD/CNY] The index to return data for. Defaults to USD.
    • currency (String): The currency to return the data in, specified in ISO 4217 format. Defaults to USD.
    • start (Date) and end (Date): Allows data to be returned for a specific date range. Must be listed as a pair of start and end parameters.
    • for (String): If yesterday, will return a single value for the previous day. Overrides the start/end parameter.
  • Function cb: The callback function.

Return

  • Promise The request object with a promise.

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

💖 Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like 🚀

  • Buy me a book—I love books! I will remember you after years if you buy me one. 😁 📖

  • PayPal—You can make one-time donations via PayPal. I'll probably buy a coffee tea. 🍵

  • Support me on Patreon—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).

  • Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! ❤️

📜 License

MIT © Ionică Bizău

Package Sidebar

Install

npm i coindesk.js

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

391 kB

Total Files

6

Last publish

Collaborators

  • ionicabizau