mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-01 20:21:50 +08:00
BLD: using an iterable to yield exchanges instead of populating a list
This commit is contained in:
@@ -22,7 +22,7 @@ import ccxt
|
||||
log = Logger('ccxt_utils', level=LOG_LEVEL)
|
||||
|
||||
|
||||
def find_exchange_configs(features=None, history=None, is_authenticated=False,
|
||||
def scan_exchange_configs(features=None, history=None, is_authenticated=False,
|
||||
path=None):
|
||||
"""
|
||||
Finding exchanges from their config files
|
||||
@@ -36,7 +36,6 @@ def find_exchange_configs(features=None, history=None, is_authenticated=False,
|
||||
-------
|
||||
|
||||
"""
|
||||
exchange_config = []
|
||||
for exchange_name in ccxt.exchanges:
|
||||
config = get_exchange_config(exchange_name, path)
|
||||
if not config or 'error' in config:
|
||||
@@ -68,17 +67,7 @@ def find_exchange_configs(features=None, history=None, is_authenticated=False,
|
||||
|
||||
# TODO: filter by history
|
||||
if has_features:
|
||||
try:
|
||||
exchange_config.append(config)
|
||||
|
||||
except Exception as e:
|
||||
log.warn(
|
||||
'unable to initialize exchange {}: {}'.format(
|
||||
exchange_name, e
|
||||
)
|
||||
)
|
||||
|
||||
return exchange_config
|
||||
yield config
|
||||
|
||||
|
||||
def get_exchange_config(exchange_name, path=None, environ=None,
|
||||
|
||||
@@ -4,7 +4,7 @@ from catalyst.constants import LOG_LEVEL
|
||||
from catalyst.exchange.ccxt.ccxt_exchange import CCXT
|
||||
from catalyst.exchange.exchange import Exchange
|
||||
from catalyst.exchange.exchange_errors import ExchangeAuthEmpty
|
||||
from catalyst.exchange.utils.ccxt_utils import find_exchange_configs
|
||||
from catalyst.exchange.utils.ccxt_utils import scan_exchange_configs
|
||||
from catalyst.exchange.utils.exchange_utils import get_exchange_auth, \
|
||||
get_exchange_folder
|
||||
from logbook import Logger
|
||||
@@ -72,20 +72,33 @@ def find_exchanges(features=None, history=None, skip_blacklist=True, path=None,
|
||||
list[Exchange]
|
||||
|
||||
"""
|
||||
exchange_configs = find_exchange_configs(
|
||||
features, history, is_authenticated, path
|
||||
|
||||
return list(
|
||||
scan_exchanges(
|
||||
features,
|
||||
history,
|
||||
skip_blacklist,
|
||||
path,
|
||||
is_authenticated,
|
||||
base_currency
|
||||
)
|
||||
)
|
||||
exchanges = []
|
||||
for config in exchange_configs:
|
||||
|
||||
|
||||
def scan_exchanges(features=None, history=None, skip_blacklist=True, path=None,
|
||||
is_authenticated=False, base_currency=None):
|
||||
for config in scan_exchange_configs(
|
||||
features=features,
|
||||
history=history,
|
||||
is_authenticated=is_authenticated,
|
||||
path=path,
|
||||
):
|
||||
if skip_blacklist and (config is None or 'error' in config):
|
||||
continue
|
||||
|
||||
exchange = get_exchange(
|
||||
yield get_exchange(
|
||||
exchange_name=config['id'],
|
||||
skip_init=True,
|
||||
base_currency=base_currency,
|
||||
config=config,
|
||||
)
|
||||
exchanges.append(exchange)
|
||||
|
||||
return exchanges
|
||||
|
||||
Reference in New Issue
Block a user