Browse Source

fx: add CoinGecko and CoinCap

somewhat based on
Electron-Cash/Electron-Cash@b3c76cd31125368f8c216531291c56e188f84245
Electron-Cash/Electron-Cash@adf8f943a1713c21230bb318a3045119c68c241d
Electron-Cash/Electron-Cash@8879e41fa0205b8ff74f359e5477f89185aa0077
regtest_lnd
SomberNight 6 years ago
parent
commit
95a122596e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 59
      electrum/currencies.json
  2. 37
      electrum/exchange_rate.py

59
electrum/currencies.json

@ -386,6 +386,9 @@
"TWD",
"USD"
],
"CoinCap": [
"USD"
],
"CoinDesk": [
"AED",
"AFN",
@ -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",

37
electrum/exchange_rate.py

@ -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):
@ -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):

Loading…
Cancel
Save