Refactor load_market out of validate_pairs
This commit is contained in:
parent
687dc78dbd
commit
0a29096794
@ -98,6 +98,7 @@ class Exchange(object):
|
|||||||
|
|
||||||
logger.info('Using Exchange "%s"', self.name)
|
logger.info('Using Exchange "%s"', self.name)
|
||||||
|
|
||||||
|
self.markets = self._load_markets()
|
||||||
# Check if all pairs are available
|
# Check if all pairs are available
|
||||||
self.validate_pairs(config['exchange']['pair_whitelist'])
|
self.validate_pairs(config['exchange']['pair_whitelist'])
|
||||||
|
|
||||||
@ -167,6 +168,16 @@ class Exchange(object):
|
|||||||
logger.warning('Could not load async markets. Reason: %s', e)
|
logger.warning('Could not load async markets. Reason: %s', e)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _load_markets(self) -> List[str]:
|
||||||
|
""" Initialize markets both sync and async """
|
||||||
|
try:
|
||||||
|
markets = self._api.load_markets()
|
||||||
|
self._load_async_markets()
|
||||||
|
return markets
|
||||||
|
except ccxt.BaseError as e:
|
||||||
|
logger.warning('Unable to initialize markets. Reason: %s', e)
|
||||||
|
return []
|
||||||
|
|
||||||
def validate_pairs(self, pairs: List[str]) -> None:
|
def validate_pairs(self, pairs: List[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Checks if all given pairs are tradable on the current exchange.
|
Checks if all given pairs are tradable on the current exchange.
|
||||||
@ -175,11 +186,8 @@ class Exchange(object):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
if not self.markets:
|
||||||
markets = self._api.load_markets()
|
logger.warning('Unable to validate pairs (assuming they are correct).')
|
||||||
self._load_async_markets()
|
|
||||||
except ccxt.BaseError as e:
|
|
||||||
logger.warning('Unable to validate pairs (assuming they are correct). Reason: %s', e)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
stake_cur = self._conf['stake_currency']
|
stake_cur = self._conf['stake_currency']
|
||||||
@ -189,7 +197,7 @@ class Exchange(object):
|
|||||||
if not pair.endswith(stake_cur):
|
if not pair.endswith(stake_cur):
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f'Pair {pair} not compatible with stake_currency: {stake_cur}')
|
f'Pair {pair} not compatible with stake_currency: {stake_cur}')
|
||||||
if pair not in markets:
|
if pair not in self.markets:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f'Pair {pair} is not available at {self.name}')
|
f'Pair {pair} is not available at {self.name}')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user