URI: 
       tfx: add CoinGecko and CoinCap - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 95a122596e0451bd8f4d6d963b1f1e72d8ec8cef
   DIR parent df8e2c3cc2dbd9ffa1b8477b53640a643e3fbf84
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Fri, 22 Mar 2019 16:35:02 +0100
       
       fx: add CoinGecko and CoinCap
       
       somewhat based on
       Electron-Cash/Electron-Cash@b3c76cd31125368f8c216531291c56e188f84245
       Electron-Cash/Electron-Cash@adf8f943a1713c21230bb318a3045119c68c241d
       Electron-Cash/Electron-Cash@8879e41fa0205b8ff74f359e5477f89185aa0077
       
       Diffstat:
         M electrum/currencies.json            |      59 +++++++++++++++++++++++++++++++
         M electrum/exchange_rate.py           |      37 +++++++++++++++++++++++++++++++
       
       2 files changed, 96 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/electrum/currencies.json b/electrum/currencies.json
       t@@ -386,6 +386,9 @@
                "TWD",
                "USD"
            ],
       +    "CoinCap": [
       +        "USD"
       +    ],
            "CoinDesk": [
                "AED",
                "AFN",
       t@@ -555,6 +558,62 @@
                "ZMW",
                "ZWL"
            ],
       +    "CoinGecko": [
       +        "AED",
       +        "ARS",
       +        "AUD",
       +        "BCH",
       +        "BDT",
       +        "BHD",
       +        "BMD",
       +        "BNB",
       +        "BRL",
       +        "BTC",
       +        "CAD",
       +        "CHF",
       +        "CLP",
       +        "CNY",
       +        "CZK",
       +        "DKK",
       +        "EOS",
       +        "ETH",
       +        "EUR",
       +        "GBP",
       +        "HKD",
       +        "HUF",
       +        "IDR",
       +        "ILS",
       +        "INR",
       +        "JPY",
       +        "KRW",
       +        "KWD",
       +        "LKR",
       +        "LTC",
       +        "MMK",
       +        "MXN",
       +        "MYR",
       +        "NOK",
       +        "NZD",
       +        "PHP",
       +        "PKR",
       +        "PLN",
       +        "RUB",
       +        "SAR",
       +        "SEK",
       +        "SGD",
       +        "THB",
       +        "TRY",
       +        "TWD",
       +        "USD",
       +        "VEF",
       +        "VND",
       +        "XAG",
       +        "XAU",
       +        "XDR",
       +        "XLM",
       +        "XRP",
       +        "ZAR"
       +    ],
            "Coinbase": [
                "AED",
                "AFN",
   DIR diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py
       t@@ -248,6 +248,24 @@ class Coinbase(ExchangeBase):
                return {ccy: Decimal(rate) for (ccy, rate) in json["data"]["rates"].items()}
        
        
       +class CoinCap(ExchangeBase):
       +
       +    async def get_rates(self, ccy):
       +        json = await self.get_json('api.coincap.io', '/v2/rates/bitcoin/')
       +        return {'USD': Decimal(json['data']['rateUsd'])}
       +
       +    def history_ccys(self):
       +        return ['USD']
       +
       +    async def request_history(self, ccy):
       +        # Currently 2000 days is the maximum in 1 API call
       +        # (and history starts on 2017-03-23)
       +        history = await self.get_json('api.coincap.io',
       +                                      '/v2/assets/bitcoin/history?interval=d1&limit=2000')
       +        return dict([(datetime.utcfromtimestamp(h['time']/1000).strftime('%Y-%m-%d'), h['priceUsd'])
       +                     for h in history['data']])
       +
       +
        class CoinDesk(ExchangeBase):
        
            async def get_currencies(self):
       t@@ -277,6 +295,25 @@ class CoinDesk(ExchangeBase):
                return json['bpi']
        
        
       +class CoinGecko(ExchangeBase):
       +
       +    async def get_rates(self, ccy):
       +        json = await self.get_json('api.coingecko.com', '/api/v3/exchange_rates')
       +        return dict([(ccy.upper(), Decimal(d['value']))
       +                     for ccy, d in json['rates'].items()])
       +
       +    def history_ccys(self):
       +        # CoinGecko seems to have historical data for all ccys it supports
       +        return CURRENCIES[self.name()]
       +
       +    async def request_history(self, ccy):
       +        history = await self.get_json('api.coingecko.com',
       +                                      '/api/v3/coins/bitcoin/market_chart?vs_currency=%s&days=max' % ccy)
       +
       +        return dict([(datetime.utcfromtimestamp(h[0]/1000).strftime('%Y-%m-%d'), h[1])
       +                     for h in history['prices']])
       +
       +
        class itBit(ExchangeBase):
        
            async def get_rates(self, ccy):