Skip to content

Latest commit

 

History

History
127 lines (72 loc) · 5.57 KB

readme.md

File metadata and controls

127 lines (72 loc) · 5.57 KB

Local Development & Docker Integration with Visual Studio Code

This document contains information regarding ways to use Visual Studio Code to work with the Lean engine, this includes a couple options that make lean easy to develop on any machine:

  • Using Lean CLI -> A great tool for working with your algorithms locally, while still being able to deploy to the cloud and have access to Lean data. It is also able to run algorithms locally through our official docker images **Recommended for algorithm development.

  • Locally installing all dependencies to run Lean with Visual Studio Code on your OS.


Setup

Option 1: Lean CLI

To use Lean CLI follow the instructions for installation and tutorial for usage in our documentation


Option 2: Install Dependencies Locally

  1. Install .Net 5 for the project

  2. (Optional) Get Python 3.6.8 for running Python algorithms

    • Follow Python instructions here for your platform
  3. Get Visual Studio Code

    • Get the Extension C# for C# Debugging
    • Get the Extension Python for Python Debugging
  4. Get Lean into VS Code

Your environment is prepared and ready to run lean


How to use Lean

This section will cover configuring, building, launching and debugging lean. This is only applicable to option 2 from above. This does not apply to Lean CLI, please refer to CLI documentation


Configuration

We need to be sure that our Lean configuration at .\Launcher\config.json is properly set.

Your configuration file should look something like this for the following languages:

Python:

"algorithm-type-name": "**AlgorithmName**",

"algorithm-language": "Python",

"algorithm-location": "../../../Algorithm.Python/**AlgorithmName**.py",

C#:

"algorithm-type-name": "**AlgorithmName**",

"algorithm-language": "CSharp",

"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",

Building

Before running Lean, we must build the project. Currently the VS Code task will automatically build before launching. But find more information below about how to trigger building manually.

In VS Code run build task (Ctrl+Shift+B or "Terminal" dropdown); there are a few options:

  • Build - basic build task, just builds Lean once
  • Rebuild - rebuild task, completely rebuilds the project. Use if having issues with debugging symbols being loaded for your algorithms.
  • Autobuilder - Starts a script that builds then waits for files to change and rebuilds appropriately
  • Clean - deletes out all project build files

Launching Lean

Now that lean is configured and built we can launch Lean. Under "Run & Debug" use the launch option "Launch". This will start Lean with C# debugging. Any breakpoints in Lean C# will be triggered.


Debugging Python

Python algorithms require a little extra work in order to be able to debug them. Follow the steps below to get Python debugging working.


Modifying the Configuration

First in order to debug a Python algorithm in VS Code we must make the following change to our configuration (Launcher\config.json) under the comment debugging configuration:

"debugging": true,
"debugging-method": "PTVSD",

In setting this we are telling Lean to expect a debugger connection using ‘Python Tools for Visual Studio Debugger’. Once this is set Lean will stop upon initialization and await a connection to the debugger via port 5678.


Using VS Code Launch Options to Connect

Now that Lean is configured for the python debugger we can make use of the programmed launch options to connect to Lean during runtime.

Start Lean using the "Launch" option covered above. Once Lean starts you should see the messages in figure 2 If the message is displayed, use the launch option “Attach to Python”. Then press run, VS Code will now enter and debug any breakpoints you have set in your python algorithm.


Figure 2: Python Debugger Messages

20200715 17:12:06.546 Trace:: PythonInitializer.Initialize(): ended
20200715 17:12:06.547 Trace:: DebuggerHelper.Initialize(): python initialization done
20200715 17:12:06.547 Trace:: DebuggerHelper.Initialize(): starting...
20200715 17:12:06.548 Trace:: DebuggerHelper.Initialize(): waiting for debugger to attach at localhost:5678...

Common Issues

Here we will cover some common issues with setting this up. This section will expand as we get user feedback!
  • Autocomplete and reference finding with omnisharp can sometimes bug, if this occurs use the command palette to restart omnisharp. (Ctrl+Shift+P "OmniSharp: Restart OmniSharp")
  • Any error messages about building in VSCode that point to comments in JSON. Either select ignore or follow steps described here to remove the errors entirely.