nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
2.25k stars 509 forks source link

Format error outputs for BacktestNode exceptions #1388

Open kbs-code opened 1 year ago

kbs-code commented 1 year ago

Feature Request

Code reference: https://github.com/nautechsystems/nautilus_trader/blob/master/nautilus_trader/backtest/node.py

I was trying to run a high-level backtest and saw some output in the terminal. Most of it was formatted fine except for one block of text. Node.py is printing my configs unformatted when I misconfigured something in my backtest. This makes it harder to read error output and debug my backtests. This seems to be coming from lines 129-142 of Node.py:

         for config in self._configs:
            try:
                result = self._run(
                    run_config_id=config.id,
                    engine_config=config.engine,
                    venue_configs=config.venues,
                    data_configs=config.data,
                    batch_size_bytes=config.batch_size_bytes,
                )
                results.append(result)
            except Exception as e:
                # Broad catch all prevents a single backtest run from halting
                # the execution of the other backtests (such as a zero balance exception).
                print(f"Error running {config}: {e}")

I tried formatting the output on my end using various try/except statements, but none improved it.
backtest_error_output

cjdsellers commented 1 year ago

Thanks for the feedback and taking the time to post the issue @kbs-code :pray: