CoinTools Update: v0.0.8: Add Coinbase API + Customized History Data


CoinTools Introduction

CoinTools, a handy Chrome Extension, provides a set of useful tools for Cryptocurrency such as Historical Data, Any Two Currency Conversions, Total Market Cap Chart etc.

Previous Contributions

  • v0.0.7: CoinTools: Historical Conversion between Any Two Cryptocurrency
  • v0.0.6: CoinTools Update: Show Full Cryptocurrency Details by Click or Startup, Add Language Handlers
  • CoinTools v0.0.5 Update: Show Full Cryptocurrency Details by Click or Startup, Add Language Handlers
  • CoinTools v0.0.4: Conversion Between Two Fiat or Fiat-Coin + 24 Hour Cap Chart
  • CoinTools v0.0.3: Adding Total Market Cap USD Chart, Localization and Stock Price Emoji
  • v0.0.2 Cryptocurrency Conversion + UI Localization
  • v0.0.1 Introduction to CoinTools! A Cryptocurrency Chrome Extension

Technology Stacks

Javascript that runs in Chrome Extension.

Github of CoinTools

https://github.com/DoctorLai/CoinTools

Chrome Webstore

It is available online at Chrome Webstore.

CoinTools v0.0.8 Feature

This version adds the following features:

  • Add Coinbase API to convert from FIAT to FIAT.
  • Customize Period of History Data.
  • Adds Russian UI translation.
  • Support single FIAT command.

Commits

Here and here

Roadmap of CoinTools

Any good suggestions, please shout at @justyy.

Screenshots

cointools-customize-history-data CoinTools Update: v0.0.8: Add Coinbase API + Customized History Data chrome extension Cryptocurrency javascript

cointools-customize-history-data

Coinbase API

Get Exchange Rate from two Fiats.

1
2
3
4
5
6
7
8
9
10
11
12
13
// ajax calling coinbase to return fiat conversion
const getPriceOf_Coinbase_Fiat = (a, b) => {
    return new Promise((resolve, reject) => {
        let api = 'https://api.coinbase.com/v2/exchange-rates/?currency=' + a.toUpperCase();
        fetch(api, {mode: 'cors'}).then(validateResponse).then(readResponseAsJSON).then(function(result) {
            let data = result.data.rates;
            resolve(data[b.toUpperCase()]);
        }).catch(function(error) {
            logit('Request failed: ' + api + ": " + error);
            reject(error);
        });
    });
}
// ajax calling coinbase to return fiat conversion
const getPriceOf_Coinbase_Fiat = (a, b) => {
    return new Promise((resolve, reject) => {
        let api = 'https://api.coinbase.com/v2/exchange-rates/?currency=' + a.toUpperCase();
        fetch(api, {mode: 'cors'}).then(validateResponse).then(readResponseAsJSON).then(function(result) {
            let data = result.data.rates;
            resolve(data[b.toUpperCase()]);
        }).catch(function(error) {
            logit('Request failed: ' + api + ": " + error);
            reject(error);
        });
    });
}

Then, you can use it:

1
2
3
4
5
6
7
8
9
10
// both are currencies e.g. USD to CNY
if ((!is_coin1) && (!is_coin2)) {
    try {
        return await getPriceOf_Coinbase_Fiat(coin1, coin2);
    } catch (e) { // if anything goes wrong with above coinbase, then use coinmarkecap (two API calls)
        let api1 = getPriceOf1BTC(coin1);        
        let api2 = getPriceOf1BTC(coin2);
        return await api2 / await api1;
    }
}
// both are currencies e.g. USD to CNY
if ((!is_coin1) && (!is_coin2)) {
    try {
        return await getPriceOf_Coinbase_Fiat(coin1, coin2);
    } catch (e) { // if anything goes wrong with above coinbase, then use coinmarkecap (two API calls)
        let api1 = getPriceOf1BTC(coin1);        
        let api2 = getPriceOf1BTC(coin2);
        return await api2 / await api1;
    }
}

If anything goes wrong with above coinbase, then use coinmarkecap (two API calls).

License

MIT

Contribution Welcome

Github: https://github.com/DoctorLai/SteemTools/

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am ‘Add some feature’
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request.

Chrome Webstore

Install the CoinTools Now!

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
691 words
Last Post: Turtle Graphics Programming Update: Adding text, jump, dot, fontsize, download as png
Next Post: LogoTurtle: Make Variables and Comments

The Permanent URL is: CoinTools Update: v0.0.8: Add Coinbase API + Customized History Data

Leave a Reply