• Stars
    star
    9,477
  • Rank 3,761 (Top 0.08 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)

alt tag

Build Status     Regression Tests     LEAN Forum     Discord Chat

Lean Home | Documentation | Download Zip | Docker Hub | Nuget


Introduction

Lean Engine is an open-source algorithmic trading engine built for easy strategy research, backtesting, and live trading. We integrate with common data providers and brokerages so you can quickly deploy algorithmic trading strategies.

The core of the LEAN Engine is written in C#, but it operates seamlessly on Linux, Mac, and Windows operating systems. It supports algorithms written in Python 3.11 or C#. Lean drives the web-based algorithmic trading platform QuantConnect.

Proudly Sponsored By


bitfinex


Want your company logo here? [Sponsor LEAN](https://github.com/sponsors/QuantConnect) to be part of radically open algorithmic-trading innovation.

QuantConnect is Hiring!

Join the team and solve some of the most difficult challenges in quantitative finance. We'd like to hear from you if you are passionate about algorithmic trading. We always have a space for excellent C# engineers. When applying, make sure to mention you came through GitHub:

System Overview

alt tag

The Engine is broken into many modular pieces that can be extended without touching other files. The modules are configured in config.json as set "environments." You can control LEAN to operate in the mode required through these environments.

The most important plugins are:

  • Result Processing (IResultHandler)

    Handle all messages from the algorithmic trading engine. Decide what should be sent and where the messages should go. The result processing system can send messages to a local GUI or the web interface.

  • Datafeed Sourcing (IDataFeed)

    Connect and download the data required for the algorithmic trading engine. For backtesting, this provider sources files from the disk; for live trading, it connects to a stream and generates the data objects.

  • Transaction Processing (ITransactionHandler)

    Process new order requests, either using the fill models provided by the algorithm or with an actual brokerage. Send the processed orders back to the algorithm's portfolio to be filled.

  • Realtime Event Management (IRealtimeHandler)

    Generate real-time events - such as the end-of-day events. Trigger callbacks to real-time event handlers. For backtesting, this is mocked up to work on simulated time.

  • Algorithm State Setup (ISetupHandler)

    Configure the algorithm cash, portfolio, and data requested. Initialize all state parameters required.

These are all configurable from the config.json file in the Launcher Project.

Developing with Visual Studio Code Dev Containers

The Dev Containers extension lets you use a Docker container as a full-featured development environment. The extension starts (or attaches to) a development container running the quantconnect/research:latest image.

A full explanation of developing Lean with Visual Studio Code Dev Containers can be found in the VS Code Integration project.

Developing with Lean CLI

QuantConnect recommends using Lean CLI for local algorithm development. This is because it is 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 can also run algorithms on your local machine with your data through our official docker images.

Reference QuantConnects documentation on Lean CLI here

Installation Instructions

This section will cover how to install lean locally for you to use in your environment. Refer to the following readme files for a detailed guide regarding using your local IDE with Lean:

To install locally, download the zip file with the latest master and unzip it to your favorite location. Alternatively, install Git and clone the repo:

git clone https://github.com/QuantConnect/Lean.git
cd Lean

macOS

Visual Studio will automatically start to restore the Nuget packages. If not, in the menu bar, click Project > Restore NuGet Packages.

  • In the menu bar, click Run > Start Debugging.

Alternatively, run the compiled dll file. First, in the menu bar, click Build > Build All, then:

cd Lean/Launcher/bin/Debug
dotnet QuantConnect.Lean.Launcher.dll

Linux (Debian, Ubuntu)

  • Install dotnet 6:
  • Compile Lean Solution:
dotnet build QuantConnect.Lean.sln
  • Run Lean:
cd Launcher/bin/Debug
dotnet QuantConnect.Lean.Launcher.dll

Windows

  • Install Visual Studio
  • Open QuantConnect.Lean.sln in Visual Studio
  • Build the solution by clicking Build Menu -> Build Solution (this should trigger the NuGet package restore)
  • Press F5 to run

Python Support

A full explanation of the Python installation process can be found in the Algorithm.Python project.

Local-Cloud Hybrid Development.

Seamlessly develop locally in your favorite development environment, with full autocomplete and debugging support to quickly and easily identify problems with your strategy. Please see the CLI Home for more information.

Issues and Feature Requests

Please submit bugs and feature requests as an issue to the Lean Repository. Before submitting an issue, please read the instructions to ensure it is not duplicated.

Mailing List

The mailing list for the project can be found on LEAN Forum. Please use this to ask for assistance with your installation and setup questions.

Contributors and Pull Requests

Contributions are warmly welcomed, but we ask you to read the existing code to see how it is formatted and commented on and ensure contributions match the existing style. All code submissions must include accompanying tests. Please see the contributor guidelines. All accepted pull requests will get a $50 cloud credit on QuantConnect. Once your pull request has been merged, write to us at [email protected] with a link to your PR to claim your free live trading. QC <3 Open Source.

A huge thank you to all our contributors!

Acknowledgements

The open sourcing of QuantConnect would not have been possible without the support of the Pioneers. The Pioneers formed the core 100 early adopters of QuantConnect who subscribed and allowed us to launch the project into open source.

Ryan H, Pravin B, Jimmie B, Nick C, Sam C, Mattias S, Michael H, Mark M, Madhan, Paul R, Nik M, Scott Y, BinaryExecutor.com, Tadas T, Matt B, Binumon P, Zyron, Mike O, TC, Luigi, Lester Z, Andreas H, Eugene K, Hugo P, Robert N, Christofer O, Ramesh L, Nicholas S, Jonathan E, Marc R, Raghav N, Marcus, Hakan D, Sergey M, Peter McE, Jim M, INTJCapital.com, Richard E, Dominik, John L, H. Orlandella, Stephen L, Risto K, E.Subasi, Peter W, Hui Z, Ross F, Archibald112, MooMooForex.com, Jae S, Eric S, Marco D, Jerome B, James B. Crocker, David Lypka, Edward T, Charlie Guse, Thomas D, Jordan I, Mark S, Bengt K, Marc D, Al C, Jan W, Ero C, Eranmn, Mitchell S, Helmuth V, Michael M, Jeremy P, PVS78, Ross D, Sergey K, John Grover, Fahiz Y, George L.Z., Craig E, Sean S, Brad G, Dennis H, Camila C, Egor U, David T, Cameron W, Napoleon Hernandez, Keeshen A, Daniel E, Daniel H, M.Patterson, Asen K, Virgil J, Balazs Trader, Stan L, Con L, Will D, Scott K, Barry K, Pawel D, S Ray, Richard C, Peter L, Thomas L., Wang H, Oliver Lee, Christian L..

More Repositories

1

Tutorials

Jupyter notebook tutorials from QuantConnect website for Python, Finance and LEAN.
Jupyter Notebook
519
star
2

Research

Open sourced research notebooks by the QuantConnect team.
Jupyter Notebook
492
star
3

lean-cli

CLI for running the LEAN engine locally and in the cloud
Python
194
star
4

Documentation

QuantConnect Wiki Style Documentation Behind QuantConnect
HTML
171
star
5

IBAutomater

Automates IB Gateway start, stopping and restarting.
Java
103
star
6

Lean.Brokerages.InteractiveBrokers

InteractiveBrokers Brokerage Plugin
C#
30
star
7

quantconnect-cli

CLI aimed at making local development of QuantConnect algorithms easier
TypeScript
29
star
8

LeanReportCreator

Create beautiful HTML/PDF reports for sharing your LEAN backtest and live trading results.
HTML
27
star
9

FXCM

Cross platform implementation of FXCM Java Trading API in .NET for connecting with FXCM. Uses IKVM to port the Java library to a .NET DLL.
C#
15
star
10

Lean.Brokerages.TDAmeritrade

TD Ameritrade Brokerage Plugin
C#
14
star
11

quantconnect-stubs-generator

Automatically generate Python type stubs for QuantConnect's Lean
C#
13
star
12

Lean.Brokerages.Zerodha

Zerodha Brokerage Plugin
C#
13
star
13

AlphaStreams

Alpha Streams Public SDK.
Jupyter Notebook
10
star
14

Lean.Brokerages.OANDA

OANDA Brokerage Implementation
C#
6
star
15

Lean.DataSource.SDK

C#
6
star
16

Lean.Brokerages.Template

Lean Brokerages Template
C#
6
star
17

Lean.Brokerages.TradingTechnologies

Trading Technologies Brokerage Plugin
C#
6
star
18

Lean.DataSource.QuiverQuantCongressTrading

Quiver Quantitative Congress Trading Data Alternative Data
C#
5
star
19

Lean.DataSource.ThetaData

Integration with ThetaData for Options History and Live Streaming
C#
5
star
20

Lean.Brokerages.Binance

Binance Brokerage Plugin
C#
4
star
21

Lean.Brokerages.TerminalLink

Connect the QuantConnect/LEAN backtesting engine with the Bloomberg Desktop API.
C#
4
star
22

Lean.Brokerages.ByBit

ByBit Brokerage Integration to LEAN
C#
4
star
23

Lean.Reference

Formatted LEAN Class/API Reference by Doxygen
CSS
4
star
24

Lean.DataSource.QuiverQuantWallStreetBets

Example production implementation for our data marketplace Quiver Quantitative Wall Street Bets dataset.
C#
3
star
25

Lean.DataSource.ExtractAlphaTrueBeats

ExtractAlpha True Beats Implementation
C#
3
star
26

Lean.Brokerages.Tradier

Tradier Brokerage Implementation
C#
3
star
27

Lean.DataSource.CoinGecko

Coin Gecko Lean Alternative Data
C#
3
star
28

Lean.DataSource.Tiingo

C#
3
star
29

Lean.Brokerages.Atreyu

Atreyu Lean brokerage implementation
C#
3
star
30

Lean.DataSource.NasdaqDataLink

Nasdaq Data Link dataset
C#
3
star
31

Lean.DataSource.SEC

C#
3
star
32

Lean.DataSource.Polygon

LEAN Polygon Data Source
C#
3
star
33

Lean.Brokerages.Alpaca

Alpaca Brokerage Implementation
C#
2
star
34

Lean.DataSource.DerivativeUniverseGenerator

C#
2
star
35

Lean.DataSource.InteractiveBrokersShortStock

LEAN Interactive Brokers Short Stock Availability Data Source
C#
2
star
36

Lean.Brokerages.Exante

Exante Brokerage Plugin
C#
2
star
37

Lean.DataSource.CBOE

C#
2
star
38

Lean.DataSource.QuiverQuantWikipedia

Example production implementation for our data marketplace for Quiver Quantitative Wikipedia Dataset
C#
2
star
39

Lean.Brokerages.Coinbase

Coinbase Pro brokerage template
C#
2
star
40

Lean.Brokerages.Wolverine

Wolverine Execution and Routing
C#
2
star
41

Lean.Brokerages.TradeStation

TradeStation Brokerage Plugin
C#
2
star
42

Lean.DataSource.HuggingFace

HuggingFace caching for the QuantConnect Community
Python
2
star
43

Lean.DataSource.FactSet

Implementation to the public FactSet Data API.
C#
2
star
44

Lean.DataSource.QuiverQuantEventsBeta

C#
1
star
45

Lean.Brokerages.Bitfinex

Bitfinex Brokerage Plugin
C#
1
star
46

Lean.Brokerages.Kraken

Kraken Brokerage Plugin
C#
1
star
47

Lean.DataSource.FRED

Example production implementation of our data marketplace for FRED.
C#
1
star
48

Lean.DataSource.USEnergy

Example production implementation of our data marketplace for Energy Information Agency.
C#
1
star
49

Lean.DataSource.Regalytics

C#
1
star
50

Lean.DataSource.CryptoCoarseFundamentalUniverse

Crypto Coarse Fundamental Universe Alternative Data
C#
1
star
51

Lean.DataSource.USTreasury

Example production implementation of our data marketplace for US Treasury Yield Curves
C#
1
star
52

Lean.DataSource.AlphaVantage

LEAN Alpha Vantage Data Source
C#
1
star
53

Lean.DataSource.SmartInsiderIntentionsTransactions

C#
1
star
54

Lean.Brokerages.FTX

FTX Brokerage Plugin
C#
1
star
55

Lean.DataSource.QuiverQuantTwitterFollowers

Quiver Quant Twitter Followers
C#
1
star
56

Lean.DataSource.VIXCentral

Example production implementation of our data marketplace for VixCentral.
C#
1
star
57

Lean.DataSource.BrainSentiment

C#
1
star
58

Lean.DataSource.BenzingaNews

C#
1
star
59

Lean.DataSource.IQFeed

LEAN IQFeed Data Source
C#
1
star
60

Lean.DataSource.BybitFundingRate

ByBit Margin Perp Funding Rates
C#
1
star