From 6f60066510682e4835a0f37578cdef2ca7a75131 Mon Sep 17 00:00:00 2001 From: Martin Molinero Date: Thu, 2 May 2024 19:06:55 -0300 Subject: [PATCH] More fixes and improvements --- README.md | 4 +-- lean/commands/data/download.py | 39 +++++++++++++++------------- tests/commands/data/test_download.py | 20 +++++++------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index acb08d97..7c3935a0 100644 --- a/README.md +++ b/README.md @@ -880,14 +880,14 @@ Options: --dataset TEXT The name of the dataset to download non-interactively --overwrite Overwrite existing local data -y, --yes Automatically confirm payment confirmation prompts - --data-type [Trade|Quote|OpenInterest] + --data-type [Trade|Quote|Bulk|OpenInterest] Specify the type of historical data --resolution [Tick|Second|Minute|Hour|Daily] Specify the resolution of the historical data --security-type [Equity|Index|Forex|Cfd|Future|Crypto|CryptoFuture|Option|IndexOption|Commodity|FutureOption] Specify the security type of the historical data --market TEXT Specify the market name for tickers (e.g., 'USA', 'NYMEX', 'Binance') - --tickers TEXT Specify comma separated list of tickers to use for historical data request. + --ticker TEXT Specify comma separated list of tickers to use for historical data request. --start-date TEXT Specify the start date for the historical data request in the format yyyyMMdd. --end-date TEXT Specify the end date for the historical data request in the format yyyyMMdd. (defaults to today) diff --git a/lean/commands/data/download.py b/lean/commands/data/download.py index 3e82c327..d00f67cc 100644 --- a/lean/commands/data/download.py +++ b/lean/commands/data/download.py @@ -513,13 +513,13 @@ def _configure_date_option(date_value: str, option_id: str, option_label: str) - help="Specify the security type of the historical data") @option("--market", type=str, help="Specify the market name for tickers (e.g., 'USA', 'NYMEX', 'Binance')") -@option("--tickers", +@option("--ticker", type=str, help="Specify comma separated list of tickers to use for historical data request.") -@option("--start-date", +@option("--start", type=str, help="Specify the start date for the historical data request in the format yyyyMMdd.") -@option("--end-date", +@option("--end", type=str, help="Specify the end date for the historical data request in the format yyyyMMdd. (defaults to today)") @option("--image", @@ -544,9 +544,9 @@ def download(ctx: Context, resolution: Optional[str], security_type: Optional[str], market: Optional[str], - tickers: Optional[str], - start_date: Optional[str], - end_date: Optional[str], + ticker: Optional[str], + start: Optional[str], + end: Optional[str], image: Optional[str], update: bool, no_update: bool, @@ -576,6 +576,9 @@ def download(ctx: Context, """ organization = _get_organization() + if dataset: + data_provider_historical = 'QuantConnect' + if data_provider_historical is None: data_provider_historical = _get_historical_data_provider() @@ -627,17 +630,17 @@ def download(ctx: Context, market = _get_user_input_or_prompt(market, data_provider_support_markets, data_provider_historical, "Select a Market") - if not tickers: - tickers = ','.join(DatasetTextOption(id="id", - label="Enter comma separated list of tickers to use for historical data request.", - description="description", - transform=DatasetTextOptionTransform.Lowercase, - multiple=True).configure_interactive().value) + if not ticker: + ticker = ','.join(DatasetTextOption(id="id", + label="Enter comma separated list of tickers to use for historical data request.", + description="description", + transform=DatasetTextOptionTransform.Lowercase, + multiple=True).configure_interactive().value) - start_date = _configure_date_option(start_date, "start", "Please enter a Start Date in the format") - end_date = _configure_date_option(end_date, "end", "Please enter a End Date in the format") + start = _configure_date_option(start, "start", "Please enter a Start Date in the format") + end = _configure_date_option(end, "end", "Please enter a End Date in the format") - if start_date.value >= end_date.value: + if start.value >= end.value: raise ValueError("Historical start date cannot be greater than or equal to historical end date.") logger = container.logger @@ -675,12 +678,12 @@ def download(ctx: Context, dll_arguments = ["dotnet", "QuantConnect.DownloaderDataProvider.Launcher.dll", "--data-type", data_type, - "--start-date", start_date.value.strftime("%Y%m%d"), - "--end-date", end_date.value.strftime("%Y%m%d"), + "--start-date", start.value.strftime("%Y%m%d"), + "--end-date", end.value.strftime("%Y%m%d"), "--security-type", security_type, "--market", market, "--resolution", resolution, - "--tickers", tickers] + "--tickers", ticker] run_options["commands"].append(' '.join(dll_arguments)) diff --git a/tests/commands/data/test_download.py b/tests/commands/data/test_download.py index a5c1e6b5..feca0bb7 100644 --- a/tests/commands/data/test_download.py +++ b/tests/commands/data/test_download.py @@ -123,9 +123,9 @@ def _create_lean_data_download(data_provider_name: str, "--data-type", data_type, "--resolution", resolution, "--security-type", security_type, - "--tickers", ','.join(tickers), - "--start-date", start_date, - "--end-date", end_date, + "--ticker", ','.join(tickers), + "--start", start_date, + "--end", end_date, ] if market: run_parameters.extend(["--market", market]) @@ -135,7 +135,7 @@ def _create_lean_data_download(data_provider_name: str, return CliRunner().invoke(lean, run_parameters) -@pytest.mark.parametrize("data_provider,market,is_crypto,security_type,tickers,data_provider_parameters", +@pytest.mark.parametrize("data_provider,market,is_crypto,security_type,ticker,data_provider_parameters", [("Polygon", "NYSE", False, "Equity", ["AAPL"], ["--polygon-api-key", "123"]), ("Binance", "Binance", True, "CryptoFuture", ["BTCUSDT"], ["--binance-exchange-name", "BinanceUS", "--binanceus-api-key", "123", @@ -145,9 +145,9 @@ def _create_lean_data_download(data_provider_name: str, ("Interactive Brokers", "USA", False, "Index", ["INTL", "NVDA"], ["--ib-user-name", "123", "--ib-account", "Individual", "--ib-password", "123"])]) def test_download_data_non_interactive(data_provider: str, market: str, is_crypto: bool, security_type: str, - tickers: List[str], data_provider_parameters: List[str]): + ticker: List[str], data_provider_parameters: List[str]): run_data_download = _create_lean_data_download( - data_provider, "Trade", "Minute", security_type, tickers, "20240101", "20240202", + data_provider, "Trade", "Minute", security_type, ticker, "20240101", "20240202", _get_data_provider_config(is_crypto), market, data_provider_parameters) assert run_data_download.exit_code == 0 @@ -174,11 +174,11 @@ def test_download_data_non_interactive_wrong_security_type(data_provider: str, w assert wrong_security_type in error_msg -@pytest.mark.parametrize("data_provider,start_date,end_date", +@pytest.mark.parametrize("data_provider,start,end", [("Polygon", "20240101", "20230202"), ("Polygon", "2024-01-01", "2023-02-02")]) -def test_download_data_non_interactive_wrong_start_end_date(data_provider: str, start_date: str, end_date: str): - run_data_download = _create_lean_data_download(data_provider, "Trade", "Hour", "Equity", ["AAPL"], start_date, - end_date, _get_data_provider_config(), "USA", +def test_download_data_non_interactive_wrong_start_end_date(data_provider: str, start: str, end: str): + run_data_download = _create_lean_data_download(data_provider, "Trade", "Hour", "Equity", ["AAPL"], start, + end, _get_data_provider_config(), "USA", extra_run_command=["--polygon-api-key", "123"]) assert run_data_download.exit_code == 1