Browse Source

Fix CoinDesk exchange rates and update currencies.json

3.1
ThomasV 7 years ago
parent
commit
95c5815fe3
  1. 205
      lib/currencies.json
  2. 15
      lib/exchange_rate.py

205
lib/currencies.json

@ -1,7 +1,4 @@
{
"BTCChina": [
"CNY"
],
"BitPay": [
"AED",
"AFN",
@ -15,6 +12,7 @@
"AZN",
"BAM",
"BBD",
"BCH",
"BDT",
"BGN",
"BHD",
@ -211,7 +209,6 @@
"EGP",
"ERN",
"ETB",
"ETH",
"EUR",
"FJD",
"FKP",
@ -254,7 +251,6 @@
"LKR",
"LRD",
"LSL",
"LTC",
"LYD",
"MAD",
"MDL",
@ -331,10 +327,8 @@
"XPD",
"XPF",
"XPT",
"XRP",
"YER",
"ZAR",
"ZEC",
"ZMW",
"ZWL"
],
@ -371,6 +365,175 @@
"TWD",
"USD"
],
"CoinDesk": [
"AED",
"AFN",
"ALL",
"AMD",
"ANG",
"AOA",
"ARS",
"AUD",
"AWG",
"AZN",
"BAM",
"BBD",
"BDT",
"BGN",
"BHD",
"BIF",
"BMD",
"BND",
"BOB",
"BRL",
"BSD",
"BTC",
"BTN",
"BWP",
"BYR",
"BZD",
"CAD",
"CDF",
"CHF",
"CLF",
"CLP",
"CNY",
"COP",
"CRC",
"CUP",
"CVE",
"CZK",
"DJF",
"DKK",
"DOP",
"DZD",
"EEK",
"EGP",
"ERN",
"ETB",
"EUR",
"FJD",
"FKP",
"GBP",
"GEL",
"GHS",
"GIP",
"GMD",
"GNF",
"GTQ",
"GYD",
"HKD",
"HNL",
"HRK",
"HTG",
"HUF",
"IDR",
"ILS",
"INR",
"IQD",
"IRR",
"ISK",
"JEP",
"JMD",
"JOD",
"JPY",
"KES",
"KGS",
"KHR",
"KMF",
"KPW",
"KRW",
"KWD",
"KYD",
"KZT",
"LAK",
"LBP",
"LKR",
"LRD",
"LSL",
"LTL",
"LVL",
"LYD",
"MAD",
"MDL",
"MGA",
"MKD",
"MMK",
"MNT",
"MOP",
"MRO",
"MTL",
"MUR",
"MVR",
"MWK",
"MXN",
"MYR",
"MZN",
"NAD",
"NGN",
"NIO",
"NOK",
"NPR",
"NZD",
"OMR",
"PAB",
"PEN",
"PGK",
"PHP",
"PKR",
"PLN",
"PYG",
"QAR",
"RON",
"RSD",
"RUB",
"RWF",
"SAR",
"SBD",
"SCR",
"SDG",
"SEK",
"SGD",
"SHP",
"SLL",
"SOS",
"SRD",
"STD",
"SVC",
"SYP",
"SZL",
"THB",
"TJS",
"TMT",
"TND",
"TOP",
"TRY",
"TTD",
"TWD",
"TZS",
"UAH",
"UGX",
"USD",
"UYU",
"UZS",
"VEF",
"VND",
"VUV",
"WST",
"XAF",
"XAG",
"XAU",
"XBT",
"XCD",
"XDR",
"XOF",
"XPF",
"YER",
"ZAR",
"ZMK",
"ZMW",
"ZWL"
],
"Coinbase": [
"AED",
"AFN",
@ -384,6 +547,7 @@
"AZN",
"BAM",
"BBD",
"BCH",
"BDT",
"BGN",
"BHD",
@ -403,6 +567,7 @@
"CHF",
"CLF",
"CLP",
"CNH",
"CNY",
"COP",
"CRC",
@ -542,9 +707,6 @@
"ZMW",
"ZWL"
],
"Coinsecure": [
"INR"
],
"Foxbit": [
"BRL"
],
@ -559,7 +721,10 @@
"AED",
"ARS",
"AUD",
"BAM",
"BDT",
"BHD",
"BOB",
"BRL",
"BYN",
"CAD",
@ -572,6 +737,7 @@
"DKK",
"DOP",
"EGP",
"ETH",
"EUR",
"GBP",
"GHS",
@ -579,20 +745,21 @@
"HRK",
"HUF",
"IDR",
"ILS",
"INR",
"IRR",
"ISK",
"JOD",
"JPY",
"KES",
"KRW",
"KZT",
"LKR",
"MAD",
"MMK",
"MXN",
"MYR",
"NGN",
"NOK",
"NZD",
"OMR",
"PAB",
"PEN",
"PHP",
@ -602,20 +769,23 @@
"RON",
"RSD",
"RUB",
"RWF",
"SAR",
"SEK",
"SGD",
"THB",
"TRY",
"TWD",
"TTD",
"TZS",
"UAH",
"UGX",
"USD",
"UYU",
"VEF",
"VND",
"XAF",
"ZAR"
"XAR",
"ZAR",
"ZMW"
],
"MercadoBitcoin": [
"BRL"
@ -623,9 +793,6 @@
"NegocieCoins": [
"BRL"
],
"Winkdex": [
"USD"
],
"WEX": [
"EUR",
"RUB",

15
lib/exchange_rate.py

@ -33,7 +33,7 @@ class ExchangeBase(PrintError):
def get_json(self, site, get_string):
# APIs must have https
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()
def get_csv(self, site, get_string):
@ -199,18 +199,19 @@ class Coinbase(ExchangeBase):
class CoinDesk(ExchangeBase):
def get_rates(self, ccy):
def get_currencies(self):
dicts = self.get_json('api.coindesk.com',
'/v1/bpi/supported-currencies.json')
return [d['currency'] for d in dicts]
def get_rates(self, ccy):
json = self.get_json('api.coindesk.com',
'/v1/bpi/currentprice/%s.json' % ccy)
ccys = [d['currency'] for d in dicts]
result = dict.fromkeys(ccys)
result[ccy] = Decimal(json['bpi'][ccy]['rate_float'])
result = {ccy: Decimal(json['bpi'][ccy]['rate_float'])}
return result
def history_starts(self):
return { 'USD': '2012-11-30' }
return { 'USD': '2012-11-30', 'EUR': '2013-09-01' }
def history_ccys(self):
return self.history_starts().keys()
@ -346,7 +347,9 @@ def get_exchanges_and_currencies():
exchange = klass(None, None)
try:
d[name] = exchange.get_currencies()
print(name, "ok")
except:
print(name, "error")
continue
with open(path, 'w') as f:
f.write(json.dumps(d, indent=4, sort_keys=True))

Loading…
Cancel
Save