QuantConnect / lean-cli

CLI for running the LEAN engine locally and in the cloud
https://www.lean.io/cli
Apache License 2.0
189 stars 101 forks source link

Optional Downloader Data Provider #424

Closed Romazes closed 4 months ago

Romazes commented 4 months ago

Description

We stumbled upon impossible to subscribe on data provider live and historical in the same time.

The code is subscribed on data-provider-live well.

Result

Nowadays, we can use 2 command in the same time without exception. The fix is downloaded packages and create dependency references. Additionaly we have opportunity to combine our live and historical providers in different way, look at example bellow ⬇ we use live provider iexcloud.io and historical polygon.io

 lean live deploy --brokerage "Paper Trading" --data-provider-live IEX --data-provider-historical Polygon ProjectAlgorithmName

If --data-provider-live doesn't have historical oportunity

For istance:

 lean live deploy --brokerage Bybit --data-provider-live Bybit ProjectAlgorithmName

The Bybit doesn't have historical option like provider that's mean it will use Local provider by default:

Like this
 lean live deploy --brokerage Bybit --data-provider-live Bybit --data-provider-historical Local ProjectAlgorithmName 

Feature (user friendly)

If user subscribe on --data-provider-live without --data-provider-historical then the code is using the smae data-provider-historical like live if it is exsist.

For instance:

 lean live deploy --brokerage "Paper Trading" --data-provider-live IEX ProjectAlgorithmName

The --data-provider-historical IEX uses this part implicitly for users.

lean live deploy --brokerage "Paper Trading" --data-provider-live IEX --data-provider-historical IEX ProjectAlgorithmName

Testing

Test Algorithm:

public class IEXAlgo : QCAlgorithm
{
    public override void Initialize()
    {
        SetStartDate(2024, 1, 1); // Set Start Date
        SetEndDate(2024, 2, 1); // Set Start Date
        SetCash(100_000);             //Set Strategy Cash
        var plug = AddEquity("AAPL", Resolution.Daily, extendedMarketHours: false);
        Log("---------- BEFORE HISTORY ----------");
        var histories = History(plug.Symbol, 10, Resolution.Daily);
        foreach(var history in histories)
        {
            Log($"Time: {history.Time}, Data History: {history}");
        }
        Log("---------- AFTER HISTORY ----------");
    }

     public override void OnData(Slice slice)
    {
        if (slice == null) return;

        Log($"Time: {slice.Time}");
        Log($"data.Bars: {string.Join(",", slice.Bars)}");
        Log($"data.QuoteBars: {string.Join(",", slice.QuoteBars)}");
    }
}

First command: