From cf44ba6d41255e8efe1dc540ba10479c7dc945eb Mon Sep 17 00:00:00 2001 From: ttt733 Date: Wed, 21 Nov 2018 14:59:31 -0600 Subject: [PATCH 1/5] added configurable logger level and changed default to INFO --- pylivetrader/__main__.py | 10 +++++++++- pylivetrader/algorithm.py | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pylivetrader/__main__.py b/pylivetrader/__main__.py index 1366a0a..bba334b 100644 --- a/pylivetrader/__main__.py +++ b/pylivetrader/__main__.py @@ -74,6 +74,12 @@ def algo_parameters(f): type=bool, show_default=True, help='True to continue running in general exception'), + click.option( + '-l', '--log-level', + type=click.Choice({'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}), + default='info', + show_default=True, + help='The minimum level of log to be written.'), click.argument('algofile', nargs=-1), ] for opt in opts: @@ -89,7 +95,8 @@ def process_algo_params( backend_config, data_frequency, statefile, - retry): + retry, + log_level): if len(algofile) > 0: algofile = algofile[0] elif file: @@ -116,6 +123,7 @@ def process_algo_params( data_frequency=data_frequency, algoname=extract_filename(algofile), statefile=statefile, + log_level=log_level, **functions, ) ctx.algorithm = algorithm diff --git a/pylivetrader/algorithm.py b/pylivetrader/algorithm.py index 96632ae..a4979d0 100644 --- a/pylivetrader/algorithm.py +++ b/pylivetrader/algorithm.py @@ -83,7 +83,7 @@ ) from pylivetrader.statestore import StateStore -from logbook import Logger +from logbook import Logger, lookup_level log = Logger('Algorithm') @@ -104,7 +104,9 @@ def __init__(self, *args, **kwargs): initialize: initialize function handle_data: handle_data function before_trading_start: before_trading_start function + log_level: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' ''' + log.level = lookup_level(kwargs.pop('log_level')) self._recorded_vars = {} self.data_frequency = kwargs.pop('data_frequency', 'minute') From 279f3092e2ef2c97f4436ea1760ce904fbd790e1 Mon Sep 17 00:00:00 2001 From: ttt733 Date: Wed, 21 Nov 2018 15:00:32 -0600 Subject: [PATCH 2/5] fixed default log level --- pylivetrader/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylivetrader/__main__.py b/pylivetrader/__main__.py index bba334b..32290f4 100644 --- a/pylivetrader/__main__.py +++ b/pylivetrader/__main__.py @@ -77,7 +77,7 @@ def algo_parameters(f): click.option( '-l', '--log-level', type=click.Choice({'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}), - default='info', + default='INFO', show_default=True, help='The minimum level of log to be written.'), click.argument('algofile', nargs=-1), From d714fda6d7132429ea1428e253543f82289f6678 Mon Sep 17 00:00:00 2001 From: ttt733 Date: Wed, 21 Nov 2018 15:06:27 -0600 Subject: [PATCH 3/5] fixing flake8 line length issue --- pylivetrader/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pylivetrader/__main__.py b/pylivetrader/__main__.py index 32290f4..caefcf4 100644 --- a/pylivetrader/__main__.py +++ b/pylivetrader/__main__.py @@ -76,7 +76,9 @@ def algo_parameters(f): help='True to continue running in general exception'), click.option( '-l', '--log-level', - type=click.Choice({'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'}), + type=click.Choice( + {'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'} + ), default='INFO', show_default=True, help='The minimum level of log to be written.'), From c5aaffe2ec2b6e9fa6abb681e347175c03d61f20 Mon Sep 17 00:00:00 2001 From: ttt733 Date: Wed, 21 Nov 2018 15:09:42 -0600 Subject: [PATCH 4/5] added default log level to satify unit tests --- pylivetrader/algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylivetrader/algorithm.py b/pylivetrader/algorithm.py index a4979d0..14b75ee 100644 --- a/pylivetrader/algorithm.py +++ b/pylivetrader/algorithm.py @@ -106,7 +106,7 @@ def __init__(self, *args, **kwargs): before_trading_start: before_trading_start function log_level: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' ''' - log.level = lookup_level(kwargs.pop('log_level')) + log.level = lookup_level(kwargs.pop('log_level', 'INFO')) self._recorded_vars = {} self.data_frequency = kwargs.pop('data_frequency', 'minute') From 43857b8955d0fffb62ea094fd6bf1e2f40efe0a6 Mon Sep 17 00:00:00 2001 From: ttt733 Date: Wed, 21 Nov 2018 20:54:21 -0600 Subject: [PATCH 5/5] Revert "Added readme for Graham example" This reverts commit 9c73bd37f253e5c305ff619df005f19906fd6834. --- examples/graham-fundamentals/README.md | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 examples/graham-fundamentals/README.md diff --git a/examples/graham-fundamentals/README.md b/examples/graham-fundamentals/README.md deleted file mode 100644 index 5e32f31..0000000 --- a/examples/graham-fundamentals/README.md +++ /dev/null @@ -1,8 +0,0 @@ -This is an example algorithm that shows how you can translate some of the principles Benjamin Graham laid out in his book, The Intelligent Investor, into a script that trades in a live environment. - -To connect pylivetrader to your existing Alpaca live or paper account, you can see the full instructions[here].(https: // github.com/alpacahq/pylivetrader/tree/master/examples) - -Once your API keys and URL endpoint have been configured, this algorithm can be run with this command: -``` -pylivetrader run GrahamFundamentals.py -```