commit d6c2a0af946a7691b226a59aa5e3bcdcd6e31fa7
parent 4b3a285871161916708f31b0d43c25c13a1b5d7d
Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 27 Feb 2019 23:49:25 +0100
exchange_rate: small fixups. BitcoinAverage, BitStamp
- BitcoinAverage seems to have historical rates for all currencies it supports
(as in, if there is spot price, there is also history).
- BitStamp now uses v2 API, also has support for EUR.
- Bitcointoyou does not seem to actually offer histories
(and `request_history` was undefined anyway)
- regenerate currencies.json
Diffstat:
2 files changed, 51 insertions(+), 29 deletions(-)
diff --git a/electrum/currencies.json b/electrum/currencies.json
@@ -109,6 +109,7 @@
"NZD",
"OMR",
"PAB",
+ "PAX",
"PEN",
"PGK",
"PHP",
@@ -149,6 +150,7 @@
"UYU",
"UZS",
"VEF",
+ "VES",
"VND",
"VUV",
"WST",
@@ -164,7 +166,8 @@
"ZWL"
],
"BitStamp": [
- "USD"
+ "USD",
+ "EUR"
],
"Bitbank": [
"JPY"
@@ -320,7 +323,7 @@
"USD",
"UYU",
"UZS",
- "VEF",
+ "VES",
"VND",
"VUV",
"WST",
@@ -338,15 +341,18 @@
"ZMW",
"ZWL"
],
- "Bitcointoyou": [
- "BRL"
- ],
"BitcoinVenezuela": [
"ARS",
+ "ETH",
"EUR",
+ "LTC",
"USD",
- "VEF"
- ],
+ "VEF",
+ "XMR"
+ ],
+ "Bitcointoyou": [
+ "BRL"
+ ],
"Bitmarket": [
"PLN"
],
@@ -561,6 +567,7 @@
"AWG",
"AZN",
"BAM",
+ "BAT",
"BBD",
"BCH",
"BDT",
@@ -572,6 +579,8 @@
"BOB",
"BRL",
"BSD",
+ "BSV",
+ "BTC",
"BTN",
"BWP",
"BYN",
@@ -597,6 +606,7 @@
"EGP",
"ERN",
"ETB",
+ "ETC",
"ETH",
"EUR",
"FJD",
@@ -718,13 +728,12 @@
"XPT",
"YER",
"ZAR",
+ "ZEC",
"ZMK",
"ZMW",
+ "ZRX",
"ZWL"
],
- "Foxbit": [
- "BRL"
- ],
"Kraken": [
"CAD",
"EUR",
@@ -736,8 +745,9 @@
"AED",
"ARS",
"AUD",
+ "BAM",
"BDT",
- "BHD",
+ "BGN",
"BOB",
"BRL",
"BWP",
@@ -757,7 +767,9 @@
"GBP",
"GEL",
"GHS",
+ "GTQ",
"HKD",
+ "HNL",
"HRK",
"HUF",
"IDR",
@@ -777,33 +789,36 @@
"NGN",
"NOK",
"NZD",
+ "OMR",
"PAB",
"PEN",
"PHP",
"PKR",
"PLN",
- "PYG",
+ "QAR",
"RON",
"RSD",
"RUB",
+ "RWF",
"SAR",
"SEK",
"SGD",
"SZL",
"THB",
"TRY",
+ "TTD",
"TWD",
"TZS",
"UAH",
"UGX",
"USD",
"UYU",
- "VEF",
+ "VES",
"VND",
"XAF",
+ "XMR",
"XRP",
- "ZAR",
- "ZMW"
+ "ZAR"
],
"MercadoBitcoin": [
"BRL"
@@ -814,10 +829,8 @@
"TheRockTrading": [
"EUR"
],
- "WEX": [
- "EUR",
- "RUB",
- "USD"
+ "Zaif": [
+ "JPY"
],
"itBit": []
-}
+}+
\ No newline at end of file
diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py
@@ -72,6 +72,7 @@ class ExchangeBase(PrintError):
self.print_error("received fx quotes")
except BaseException as e:
self.print_error("failed fx quotes:", repr(e))
+ # traceback.print_exc()
self.quotes = {}
self.on_quotes()
@@ -99,7 +100,7 @@ class ExchangeBase(PrintError):
h = await self.request_history(ccy)
self.print_error("received fx history for", ccy)
except BaseException as e:
- self.print_error("failed fx history:", e)
+ self.print_error("failed fx history:", repr(e))
#traceback.print_exc()
return
filename = os.path.join(cache_dir, self.name() + '_' + ccy)
@@ -124,6 +125,12 @@ class ExchangeBase(PrintError):
def historical_rate(self, ccy, d_t):
return self.history.get(ccy, {}).get(d_t.strftime('%Y-%m-%d'), 'NaN')
+ async def request_history(self, ccy):
+ raise NotImplementedError() # implemented by subclasses
+
+ async def get_rates(self, ccy):
+ raise NotImplementedError() # implemented by subclasses
+
async def get_currencies(self):
rates = await self.get_rates('')
return sorted([str(a) for (a, b) in rates.items() if b is not None and len(a)==3])
@@ -136,9 +143,8 @@ class BitcoinAverage(ExchangeBase):
for r in json if r != 'timestamp'])
def history_ccys(self):
- return ['AUD', 'BRL', 'CAD', 'CHF', 'CNY', 'EUR', 'GBP', 'IDR', 'ILS',
- 'MXN', 'NOK', 'NZD', 'PLN', 'RON', 'RUB', 'SEK', 'SGD', 'USD',
- 'ZAR']
+ # BitcoinAverage seems to have historical data for all ccys it supports
+ return CURRENCIES[self.name()]
async def request_history(self, ccy):
history = await self.get_csv('apiv2.bitcoinaverage.com',
@@ -153,9 +159,6 @@ class Bitcointoyou(ExchangeBase):
json = await self.get_json('bitcointoyou.com', "/API/ticker.aspx")
return {'BRL': Decimal(json['ticker']['last'])}
- def history_ccys(self):
- return ['BRL']
-
class BitcoinVenezuela(ExchangeBase):
@@ -211,9 +214,14 @@ class Bitso(ExchangeBase):
class BitStamp(ExchangeBase):
+ async def get_currencies(self):
+ return ['USD', 'EUR']
+
async def get_rates(self, ccy):
- json = await self.get_json('www.bitstamp.net', '/api/ticker/')
- return {'USD': Decimal(json['last'])}
+ if ccy in CURRENCIES[self.name()]:
+ json = await self.get_json('www.bitstamp.net', f'/api/v2/ticker/btc{ccy.lower()}/')
+ return {ccy: Decimal(json['last'])}
+ return {}
class Bitvalor(ExchangeBase):