Browse Source

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
sqlite_db
SomberNight 6 years ago
parent
commit
d6c2a0af94
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 53
      electrum/currencies.json
  2. 26
      electrum/exchange_rate.py

53
electrum/currencies.json

@ -109,6 +109,7 @@
"NZD", "NZD",
"OMR", "OMR",
"PAB", "PAB",
"PAX",
"PEN", "PEN",
"PGK", "PGK",
"PHP", "PHP",
@ -149,6 +150,7 @@
"UYU", "UYU",
"UZS", "UZS",
"VEF", "VEF",
"VES",
"VND", "VND",
"VUV", "VUV",
"WST", "WST",
@ -164,7 +166,8 @@
"ZWL" "ZWL"
], ],
"BitStamp": [ "BitStamp": [
"USD" "USD",
"EUR"
], ],
"Bitbank": [ "Bitbank": [
"JPY" "JPY"
@ -320,7 +323,7 @@
"USD", "USD",
"UYU", "UYU",
"UZS", "UZS",
"VEF", "VES",
"VND", "VND",
"VUV", "VUV",
"WST", "WST",
@ -338,15 +341,18 @@
"ZMW", "ZMW",
"ZWL" "ZWL"
], ],
"Bitcointoyou": [
"BRL"
],
"BitcoinVenezuela": [ "BitcoinVenezuela": [
"ARS", "ARS",
"ETH",
"EUR", "EUR",
"LTC",
"USD", "USD",
"VEF" "VEF",
], "XMR"
],
"Bitcointoyou": [
"BRL"
],
"Bitmarket": [ "Bitmarket": [
"PLN" "PLN"
], ],
@ -561,6 +567,7 @@
"AWG", "AWG",
"AZN", "AZN",
"BAM", "BAM",
"BAT",
"BBD", "BBD",
"BCH", "BCH",
"BDT", "BDT",
@ -572,6 +579,8 @@
"BOB", "BOB",
"BRL", "BRL",
"BSD", "BSD",
"BSV",
"BTC",
"BTN", "BTN",
"BWP", "BWP",
"BYN", "BYN",
@ -597,6 +606,7 @@
"EGP", "EGP",
"ERN", "ERN",
"ETB", "ETB",
"ETC",
"ETH", "ETH",
"EUR", "EUR",
"FJD", "FJD",
@ -718,13 +728,12 @@
"XPT", "XPT",
"YER", "YER",
"ZAR", "ZAR",
"ZEC",
"ZMK", "ZMK",
"ZMW", "ZMW",
"ZRX",
"ZWL" "ZWL"
], ],
"Foxbit": [
"BRL"
],
"Kraken": [ "Kraken": [
"CAD", "CAD",
"EUR", "EUR",
@ -736,8 +745,9 @@
"AED", "AED",
"ARS", "ARS",
"AUD", "AUD",
"BAM",
"BDT", "BDT",
"BHD", "BGN",
"BOB", "BOB",
"BRL", "BRL",
"BWP", "BWP",
@ -757,7 +767,9 @@
"GBP", "GBP",
"GEL", "GEL",
"GHS", "GHS",
"GTQ",
"HKD", "HKD",
"HNL",
"HRK", "HRK",
"HUF", "HUF",
"IDR", "IDR",
@ -777,33 +789,36 @@
"NGN", "NGN",
"NOK", "NOK",
"NZD", "NZD",
"OMR",
"PAB", "PAB",
"PEN", "PEN",
"PHP", "PHP",
"PKR", "PKR",
"PLN", "PLN",
"PYG", "QAR",
"RON", "RON",
"RSD", "RSD",
"RUB", "RUB",
"RWF",
"SAR", "SAR",
"SEK", "SEK",
"SGD", "SGD",
"SZL", "SZL",
"THB", "THB",
"TRY", "TRY",
"TTD",
"TWD", "TWD",
"TZS", "TZS",
"UAH", "UAH",
"UGX", "UGX",
"USD", "USD",
"UYU", "UYU",
"VEF", "VES",
"VND", "VND",
"XAF", "XAF",
"XMR",
"XRP", "XRP",
"ZAR", "ZAR"
"ZMW"
], ],
"MercadoBitcoin": [ "MercadoBitcoin": [
"BRL" "BRL"
@ -814,10 +829,8 @@
"TheRockTrading": [ "TheRockTrading": [
"EUR" "EUR"
], ],
"WEX": [ "Zaif": [
"EUR", "JPY"
"RUB",
"USD"
], ],
"itBit": [] "itBit": []
} }

26
electrum/exchange_rate.py

@ -72,6 +72,7 @@ class ExchangeBase(PrintError):
self.print_error("received fx quotes") self.print_error("received fx quotes")
except BaseException as e: except BaseException as e:
self.print_error("failed fx quotes:", repr(e)) self.print_error("failed fx quotes:", repr(e))
# traceback.print_exc()
self.quotes = {} self.quotes = {}
self.on_quotes() self.on_quotes()
@ -99,7 +100,7 @@ class ExchangeBase(PrintError):
h = await self.request_history(ccy) h = await self.request_history(ccy)
self.print_error("received fx history for", ccy) self.print_error("received fx history for", ccy)
except BaseException as e: except BaseException as e:
self.print_error("failed fx history:", e) self.print_error("failed fx history:", repr(e))
#traceback.print_exc() #traceback.print_exc()
return return
filename = os.path.join(cache_dir, self.name() + '_' + ccy) filename = os.path.join(cache_dir, self.name() + '_' + ccy)
@ -124,6 +125,12 @@ class ExchangeBase(PrintError):
def historical_rate(self, ccy, d_t): def historical_rate(self, ccy, d_t):
return self.history.get(ccy, {}).get(d_t.strftime('%Y-%m-%d'), 'NaN') 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): async def get_currencies(self):
rates = await self.get_rates('') rates = await self.get_rates('')
return sorted([str(a) for (a, b) in rates.items() if b is not None and len(a)==3]) 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']) for r in json if r != 'timestamp'])
def history_ccys(self): def history_ccys(self):
return ['AUD', 'BRL', 'CAD', 'CHF', 'CNY', 'EUR', 'GBP', 'IDR', 'ILS', # BitcoinAverage seems to have historical data for all ccys it supports
'MXN', 'NOK', 'NZD', 'PLN', 'RON', 'RUB', 'SEK', 'SGD', 'USD', return CURRENCIES[self.name()]
'ZAR']
async def request_history(self, ccy): async def request_history(self, ccy):
history = await self.get_csv('apiv2.bitcoinaverage.com', 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") json = await self.get_json('bitcointoyou.com', "/API/ticker.aspx")
return {'BRL': Decimal(json['ticker']['last'])} return {'BRL': Decimal(json['ticker']['last'])}
def history_ccys(self):
return ['BRL']
class BitcoinVenezuela(ExchangeBase): class BitcoinVenezuela(ExchangeBase):
@ -211,9 +214,14 @@ class Bitso(ExchangeBase):
class BitStamp(ExchangeBase): class BitStamp(ExchangeBase):
async def get_currencies(self):
return ['USD', 'EUR']
async def get_rates(self, ccy): async def get_rates(self, ccy):
json = await self.get_json('www.bitstamp.net', '/api/ticker/') if ccy in CURRENCIES[self.name()]:
return {'USD': Decimal(json['last'])} json = await self.get_json('www.bitstamp.net', f'/api/v2/ticker/btc{ccy.lower()}/')
return {ccy: Decimal(json['last'])}
return {}
class Bitvalor(ExchangeBase): class Bitvalor(ExchangeBase):

Loading…
Cancel
Save