mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-11 04:59:51 +00:00
Fix CoinDesk exchange rates and update currencies.json
This commit is contained in:
parent
c9d93d30c7
commit
95c5815fe3
2 changed files with 779 additions and 609 deletions
1373
lib/currencies.json
1373
lib/currencies.json
File diff suppressed because it is too large
Load diff
|
@ -33,7 +33,7 @@ class ExchangeBase(PrintError):
|
||||||
def get_json(self, site, get_string):
|
def get_json(self, site, get_string):
|
||||||
# APIs must have https
|
# APIs must have https
|
||||||
url = ''.join(['https://', site, get_string])
|
url = ''.join(['https://', site, get_string])
|
||||||
response = requests.request('GET', url, headers={'User-Agent' : 'Electrum'})
|
response = requests.request('GET', url, headers={'User-Agent' : 'Electrum'}, timeout=10)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def get_csv(self, site, get_string):
|
def get_csv(self, site, get_string):
|
||||||
|
@ -199,18 +199,19 @@ class Coinbase(ExchangeBase):
|
||||||
|
|
||||||
class CoinDesk(ExchangeBase):
|
class CoinDesk(ExchangeBase):
|
||||||
|
|
||||||
def get_rates(self, ccy):
|
def get_currencies(self):
|
||||||
dicts = self.get_json('api.coindesk.com',
|
dicts = self.get_json('api.coindesk.com',
|
||||||
'/v1/bpi/supported-currencies.json')
|
'/v1/bpi/supported-currencies.json')
|
||||||
|
return [d['currency'] for d in dicts]
|
||||||
|
|
||||||
|
def get_rates(self, ccy):
|
||||||
json = self.get_json('api.coindesk.com',
|
json = self.get_json('api.coindesk.com',
|
||||||
'/v1/bpi/currentprice/%s.json' % ccy)
|
'/v1/bpi/currentprice/%s.json' % ccy)
|
||||||
ccys = [d['currency'] for d in dicts]
|
result = {ccy: Decimal(json['bpi'][ccy]['rate_float'])}
|
||||||
result = dict.fromkeys(ccys)
|
|
||||||
result[ccy] = Decimal(json['bpi'][ccy]['rate_float'])
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def history_starts(self):
|
def history_starts(self):
|
||||||
return { 'USD': '2012-11-30' }
|
return { 'USD': '2012-11-30', 'EUR': '2013-09-01' }
|
||||||
|
|
||||||
def history_ccys(self):
|
def history_ccys(self):
|
||||||
return self.history_starts().keys()
|
return self.history_starts().keys()
|
||||||
|
@ -346,7 +347,9 @@ def get_exchanges_and_currencies():
|
||||||
exchange = klass(None, None)
|
exchange = klass(None, None)
|
||||||
try:
|
try:
|
||||||
d[name] = exchange.get_currencies()
|
d[name] = exchange.get_currencies()
|
||||||
|
print(name, "ok")
|
||||||
except:
|
except:
|
||||||
|
print(name, "error")
|
||||||
continue
|
continue
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(json.dumps(d, indent=4, sort_keys=True))
|
f.write(json.dumps(d, indent=4, sort_keys=True))
|
||||||
|
|
Loading…
Add table
Reference in a new issue