diff --git a/catalyst/__main__.py b/catalyst/__main__.py index def7838e..2c531e15 100644 --- a/catalyst/__main__.py +++ b/catalyst/__main__.py @@ -285,6 +285,7 @@ def run(ctx, analyze_live=None, live_graph=False, simulate_orders=True, + auth_aliases=None, stats_output=None, ) @@ -413,6 +414,15 @@ def catalyst_magic(line, cell=None): help='Simulating orders enable the paper trading mode. No orders will be ' 'sent to the exchange unless set to false.', ) +@click.option( + '--auth-aliases', + default=None, + help='Authentication file aliases for the specified exchanges. By default,' + 'each exchange uses the "auth.json" file in the exchange folder. ' + 'Specifying an "auth2" alias would use "auth2.json". It should be ' + 'specified like this: "[exchange_name],[alias],..." For example, ' + '"binance,auth2" or "binance,auth2,bittrex,auth2".', +) @click.pass_context def live(ctx, algofile, @@ -427,6 +437,7 @@ def live(ctx, base_currency, end, live_graph, + auth_aliases, simulate_orders): """Trade live with the given algorithm. """ @@ -480,6 +491,7 @@ def live(ctx, live_graph=live_graph, analyze_live=None, simulate_orders=simulate_orders, + auth_aliases=auth_aliases, stats_output=None, ) diff --git a/catalyst/utils/run_algo.py b/catalyst/utils/run_algo.py index 9285114a..a327e8a5 100644 --- a/catalyst/utils/run_algo.py +++ b/catalyst/utils/run_algo.py @@ -8,6 +8,8 @@ from time import sleep import click import pandas as pd +from six import string_types + from catalyst.data.bundles import load from catalyst.data.data_portal import DataPortal from catalyst.exchange.exchange_pricing_loader import ExchangePricingLoader, \ @@ -97,6 +99,7 @@ def _run(handle_data, This is shared between the cli and :func:`catalyst.run_algo`. """ + # TODO: refactor for more granularity if algotext is not None: if local_namespace: ip = get_ipython() # noqa @@ -163,6 +166,17 @@ def _run(handle_data, if exchange_name is None: raise ValueError('Please specify at least one exchange.') + if isinstance(auth_aliases, string_types): + aliases = auth_aliases.split(',') + if len(aliases) < 2 or len(aliases) % 2 != 0: + raise ValueError( + 'the `auth_aliases` parameter must contain an even list ' + 'of comma-delimited values. For example, ' + '"binance,auth2" or "binance,auth2,bittrex,auth2".' + ) + + auth_aliases = dict(zip(aliases[::2], aliases[1::2])) + exchange_list = [x.strip().lower() for x in exchange.split(',')] exchanges = dict() for name in exchange_list: