mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-10 05:21:01 +08:00
BLD: for issue #174, re-implemented the fetch_tickers approach
This commit is contained in:
@@ -997,31 +997,31 @@ class CCXT(Exchange):
|
||||
list[dict[str, float]
|
||||
|
||||
"""
|
||||
tickers = {}
|
||||
symbols = self.get_symbols(assets)
|
||||
try:
|
||||
results = self.api.fetch_tickers(symbols=symbols)
|
||||
except (ExchangeError, NetworkError) as e:
|
||||
log.warn(
|
||||
'unable to fetch tickers {} / {}: {}'.format(
|
||||
self.name, symbols, e
|
||||
)
|
||||
)
|
||||
raise ExchangeRequestError(error=e)
|
||||
|
||||
tickers = dict()
|
||||
for asset in assets:
|
||||
symbol = self.get_symbol(asset)
|
||||
|
||||
# Test the CCXT throttling further to see if we need this
|
||||
self.ask_request()
|
||||
|
||||
# TODO: use fetch_tickers() for efficiency
|
||||
# I tried using fetch_tickers() but noticed some
|
||||
# inconsistencies, see issue:
|
||||
# https://github.com/ccxt/ccxt/issues/870
|
||||
try:
|
||||
ticker = self.api.fetch_ticker(symbol=symbol)
|
||||
except (ExchangeError, NetworkError) as e:
|
||||
log.warn(
|
||||
'unable to fetch ticker {} / {}: {}'.format(
|
||||
self.name, asset.symbol, e
|
||||
)
|
||||
if symbol not in results:
|
||||
msg = 'ticker not found {} / {}'.format(
|
||||
self.name, symbol
|
||||
)
|
||||
log.warn(msg)
|
||||
if on_ticker_error == 'warn':
|
||||
continue
|
||||
|
||||
else:
|
||||
raise ExchangeRequestError(error=e)
|
||||
raise ExchangeRequestError(error=msg)
|
||||
|
||||
ticker = results[symbol]
|
||||
ticker['last_traded'] = from_ms_timestamp(ticker['timestamp'])
|
||||
|
||||
if 'last_price' not in ticker:
|
||||
|
||||
@@ -72,7 +72,8 @@ class TestCCXT(BaseExchangeTestCase):
|
||||
def test_tickers(self):
|
||||
log.info('retrieving tickers')
|
||||
assets = [
|
||||
self.exchange.get_asset('iot_usd'),
|
||||
self.exchange.get_asset('ada_eth'),
|
||||
self.exchange.get_asset('zrx_eth'),
|
||||
]
|
||||
tickers = self.exchange.tickers(assets)
|
||||
assert len(tickers) == 1
|
||||
|
||||
Reference in New Issue
Block a user