mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 08:51:32 +00:00
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
This commit is contained in:
parent
4b3a285871
commit
d6c2a0af94
2 changed files with 51 additions and 30 deletions
|
@ -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"
|
||||
],
|
||||
"BitcoinVenezuela": [
|
||||
"ARS",
|
||||
"ETH",
|
||||
"EUR",
|
||||
"LTC",
|
||||
"USD",
|
||||
"VEF",
|
||||
"XMR"
|
||||
],
|
||||
"Bitcointoyou": [
|
||||
"BRL"
|
||||
],
|
||||
"BitcoinVenezuela": [
|
||||
"ARS",
|
||||
"EUR",
|
||||
"USD",
|
||||
"VEF"
|
||||
],
|
||||
"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": []
|
||||
}
|
||||
}
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue