Backtesting
Debugging
Python and PyCharm
Local debugging for Python in PyCharm requires PyCharm's remote debugging functionality, which is only available in PyCharm Professional. After making sure you are running the Professional edition, follow these steps to start local debugging for Python in PyCharm:
- Follow the How to set up local autocomplete for Python in PyCharm tutorial.
- Open the directory containing the main.py file in a new PyCharm window. It is important that you open the project directory itself, not your organization workspace.
- Start debugging using the run configuration (this configuration is created when you create a new project with the CLI).
- Open a terminal in your organization workspace and run
lean backtest "<projectName>" --debug pycharm
.$ lean backtest "My Project" --debug pycharm 20210322 18:58:23.355 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) 20210322 18:58:23.360 TRACE:: Engine.Main(): Started 6:58 PM
- Terminate the debugger in PyCharm once LEAN has exited.
After finishing Python debugging with PyCharm, you will see a message saying "Connection to Python debugger failed". You can safely ignore this message.
Python and VS Code
Follow these steps to start local debugging for Python in VS Code:
- Follow the How to set up local autocomplete for Python in VS Code tutorial.
- Open the directory containing the main.py file in a new VS Code window. It is important that you open the project directory itself, not your organization workspace.
- Open a terminal in your organization workspace, run
lean backtest "<projectName>" --debug debugpy
, and then wait until the CLI tells you to attach to the debugger.$ lean backtest "My Project" --debug debugpy 20240507 20:35:54.970 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) 20240507 20:35:55.272 TRACE:: Engine.Main(): Started 8:35 PM 20240507 20:36:01.104 TRACE:: DebuggerHelper.Initialize(): debugpy waiting for attach at port 5678...
- In VS Code, open the Run tab and run the configuration called (this configuration is created when you create a new project with the CLI).
C# and Visual Studio
Follow these steps to start local debugging for C# in Visual Studio:
- Follow the How to set up local autocomplete for C# in Visual Studio tutorial.
- Open the project containing the Main.cs file in a new Visual Studio window. It is important that you open the project directory itself, not your organization workspace.
- Open a terminal in your organization workspace, run
lean backtest "<projectName>" --debug vsdbg
, and wait until the CLI tells you to attach to the debugger.$ lean backtest "My Project" --debug vsdbg 20210423 13:50:54.634 TRACE:: DebuggerHelper.Initialize(): waiting for debugger to attach...
- In Visual Studio, open the process selector using .
- Select as the connection type.
- Select as connection target.
- Double-click on the process named .
- Tick the checkbox in front of Managed (.NET Core for Unix) and click to start debugging.
After finishing C# debugging with Visual Studio you will see a message saying "The debug adapter exited unexpectedly.". You can safely ignore this message.
C# and Rider
Follow these steps to start local debugging for C# in Rider:
- Follow the How to set up local autocomplete for C# in Rider tutorial.
- Open the project containing the Main.cs file in a new Rider window. It is important that you open the project directory itself, not your organization workspace.
- Open a terminal in your organization workspace, run
lean backtest "<projectName>" --debug rider
, and wait until the CLI tells you to attach to the debugger.$ lean backtest "My Project" --debug rider 20210423 13:50:54.634 TRACE:: DebuggerHelper.Initialize(): waiting for debugger to attach...
- In Rider, select .
- In the pop-up that opens, select the target named .
- Wait for Rider to connect and select the process named Remote debugger tools are not loaded to the remote host. Click to load first. when a selector pops up to start debugging. You may have to select
C# and VS Code
Follow these steps to start local debugging for C# in VS Code:
- Follow the How to set up local autocomplete for C# in VS Code tutorial.
- Open the directory containing the Main.cs file in a new VS Code window. It is important that you open the project directory itself, not your organization workspace.
- Open a terminal in your organization workspace, run
lean backtest "<projectName>" --debug vsdbg
, and wait until the CLI tells you to attach to the debugger.$ lean backtest "My Project" --debug vsdbg 20210423 13:50:54.634 TRACE:: DebuggerHelper.Initialize(): waiting for debugger to attach...
- In VS Code, open the Run tab and run the configuration called (this configuration is created when you create a new project with the CLI).
After finishing C# debugging with VS Code you will see a message saying "The pipe program 'docker' exited unexpectedly with code 137.". You can safely ignore this message.