mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-03 06:17:29 +08:00
BLD: conditionally fetching single or multi tickers for performance reasons
This commit is contained in:
@@ -997,16 +997,36 @@ class CCXT(Exchange):
|
||||
list[dict[str, float]
|
||||
|
||||
"""
|
||||
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
|
||||
if len(assets) == 1:
|
||||
symbol = self.get_symbol(assets[0])
|
||||
try:
|
||||
log.debug('fetching single ticker: {}'.format(symbol))
|
||||
results = dict()
|
||||
results[symbol] = self.api.fetch_ticker(symbol=symbol)
|
||||
|
||||
except (ExchangeError, NetworkError) as e:
|
||||
log.warn(
|
||||
'unable to fetch ticker {} / {}: {}'.format(
|
||||
self.name, symbol, e
|
||||
)
|
||||
)
|
||||
)
|
||||
raise ExchangeRequestError(error=e)
|
||||
raise ExchangeRequestError(error=e)
|
||||
|
||||
elif len(assets) > 1:
|
||||
symbols = self.get_symbols(assets)
|
||||
try:
|
||||
log.debug('fetching multiple tickers: {}'.format(symbols))
|
||||
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)
|
||||
else:
|
||||
raise ValueError('Cannot request tickers with not assets.')
|
||||
|
||||
tickers = dict()
|
||||
for asset in assets:
|
||||
|
||||
@@ -701,7 +701,7 @@ class Exchange:
|
||||
)
|
||||
|
||||
positions_value = 0.0
|
||||
if positions is not None:
|
||||
if positions:
|
||||
assets = set([position.asset for position in positions])
|
||||
tickers = self.tickers(assets)
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class TestCCXT(BaseExchangeTestCase):
|
||||
self.exchange.get_asset('zrx_eth'),
|
||||
]
|
||||
tickers = self.exchange.tickers(assets)
|
||||
assert len(tickers) == 1
|
||||
assert len(tickers) == 2
|
||||
pass
|
||||
|
||||
def test_my_trades(self):
|
||||
|
||||
Reference in New Issue
Block a user