mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 07:51:27 +00:00
fx: add CoinGecko and CoinCap
somewhat based on Electron-Cash/Electron-Cash@b3c76cd311 Electron-Cash/Electron-Cash@adf8f943a1 Electron-Cash/Electron-Cash@8879e41fa0
This commit is contained in:
parent
df8e2c3cc2
commit
95a122596e
2 changed files with 96 additions and 0 deletions
|
@ -386,6 +386,9 @@
|
||||||
"TWD",
|
"TWD",
|
||||||
"USD"
|
"USD"
|
||||||
],
|
],
|
||||||
|
"CoinCap": [
|
||||||
|
"USD"
|
||||||
|
],
|
||||||
"CoinDesk": [
|
"CoinDesk": [
|
||||||
"AED",
|
"AED",
|
||||||
"AFN",
|
"AFN",
|
||||||
|
@ -555,6 +558,62 @@
|
||||||
"ZMW",
|
"ZMW",
|
||||||
"ZWL"
|
"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": [
|
"Coinbase": [
|
||||||
"AED",
|
"AED",
|
||||||
"AFN",
|
"AFN",
|
||||||
|
|
|
@ -248,6 +248,24 @@ class Coinbase(ExchangeBase):
|
||||||
return {ccy: Decimal(rate) for (ccy, rate) in json["data"]["rates"].items()}
|
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):
|
class CoinDesk(ExchangeBase):
|
||||||
|
|
||||||
async def get_currencies(self):
|
async def get_currencies(self):
|
||||||
|
@ -277,6 +295,25 @@ class CoinDesk(ExchangeBase):
|
||||||
return json['bpi']
|
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):
|
class itBit(ExchangeBase):
|
||||||
|
|
||||||
async def get_rates(self, ccy):
|
async def get_rates(self, ccy):
|
||||||
|
|
Loading…
Add table
Reference in a new issue