Add 'get_tickers' function to exchange and use it for dynamic whitelists
This commit is contained in:
parent
5fc8250ee4
commit
0c8ecf2b1f
@ -226,6 +226,23 @@ def get_balances() -> dict:
|
|||||||
raise OperationalException(e)
|
raise OperationalException(e)
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
|
def get_tickers() -> Dict:
|
||||||
|
try:
|
||||||
|
return _API.fetch_tickers()
|
||||||
|
except ccxt.NetworkError as e:
|
||||||
|
raise NetworkException(
|
||||||
|
'Could not load tickers due to networking error. Message: {}'.format(e)
|
||||||
|
)
|
||||||
|
except ccxt.BaseError as e:
|
||||||
|
raise OperationalException(e)
|
||||||
|
except ccxt.NotSupported as e:
|
||||||
|
raise OperationalException(
|
||||||
|
'Exchange {} does not support fetching tickers in batch.'
|
||||||
|
'Message: {}'.format(_API.name, e)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: remove refresh argument, keeping it to keep track of where it was intended to be used
|
# TODO: remove refresh argument, keeping it to keep track of where it was intended to be used
|
||||||
@retrier
|
@retrier
|
||||||
def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
|
def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
|
||||||
|
@ -185,18 +185,27 @@ class FreqtradeBot(object):
|
|||||||
return state_changed
|
return state_changed
|
||||||
|
|
||||||
@cached(TTLCache(maxsize=1, ttl=1800))
|
@cached(TTLCache(maxsize=1, ttl=1800))
|
||||||
def _gen_pair_whitelist(self, base_currency: str, key: str = 'BaseVolume') -> List[str]:
|
def _gen_pair_whitelist(self, base_currency: str, key: str = 'quoteVolume') -> List[str]:
|
||||||
"""
|
"""
|
||||||
Updates the whitelist with with a dynamically generated list
|
Updates the whitelist with with a dynamically generated list
|
||||||
:param base_currency: base currency as str
|
:param base_currency: base currency as str
|
||||||
:param key: sort key (defaults to 'BaseVolume')
|
:param key: sort key (defaults to 'quoteVolume')
|
||||||
:return: List of pairs
|
:return: List of pairs
|
||||||
"""
|
"""
|
||||||
pairs = sorted(
|
|
||||||
[s['symbol'] for s in exchange.get_markets() if s['quote'] == base_currency],
|
|
||||||
reverse=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
if not exchange.exchange_has('fetchTickers'):
|
||||||
|
raise OperationalException(
|
||||||
|
'Exchange does not support dynamic whitelist.'
|
||||||
|
'Please edit your config and restart the bot'
|
||||||
|
)
|
||||||
|
|
||||||
|
tickers = exchange.get_tickers()
|
||||||
|
# check length so that we make sure that '/' is actually in the string
|
||||||
|
tickers = [v for k, v in tickers.items()
|
||||||
|
if len(k.split('/')) == 2 and k.split('/')[1] == base_currency]
|
||||||
|
|
||||||
|
sorted_tickers = sorted(tickers, reverse=True, key=lambda t: t[key])
|
||||||
|
pairs = [s['symbol'] for s in sorted_tickers]
|
||||||
return pairs
|
return pairs
|
||||||
|
|
||||||
def _refresh_whitelist(self, whitelist: List[str]) -> List[str]:
|
def _refresh_whitelist(self, whitelist: List[str]) -> List[str]:
|
||||||
@ -349,7 +358,7 @@ class FreqtradeBot(object):
|
|||||||
if trade.open_order_id:
|
if trade.open_order_id:
|
||||||
# Update trade with order values
|
# Update trade with order values
|
||||||
self.logger.info('Found open order for %s', trade)
|
self.logger.info('Found open order for %s', trade)
|
||||||
trade.update(exchange.get_order(trade.open_order_id))
|
trade.update(exchange.get_order(trade.open_order_id, trade.pair))
|
||||||
|
|
||||||
if trade.is_open and trade.open_order_id is None:
|
if trade.is_open and trade.open_order_id is None:
|
||||||
# Check if we can sell our current pair
|
# Check if we can sell our current pair
|
||||||
|
Loading…
Reference in New Issue
Block a user