Skip to content

Commit

Permalink
Install modules on backtest and research
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Dec 21, 2023
1 parent a4e12c0 commit ba67ee1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lean/commands/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from lean.models.api import QCMinimalOrganization
from lean.models.utils import DebuggingMethod
from lean.models.logger import Option
from lean.models.data_providers import QuantConnectDataProvider, all_data_providers
from lean.models.data_providers import QuantConnectDataProvider, all_data_providers, DataProvider
from lean.components.util.json_modules_handler import build_and_configure_modules, get_and_build_module
from lean.models.click_options import options_from_json, get_configs_for_options

Expand Down Expand Up @@ -365,8 +365,11 @@ def backtest(project: Path,
if download_data:
data_provider = QuantConnectDataProvider.get_name()

organization_id = container.organization_manager.try_get_working_organization_id()

if data_provider is not None:
[data_provider_configurer] = [get_and_build_module(data_provider, all_data_providers, kwargs, logger)]
data_provider_configurer: DataProvider = get_and_build_module(data_provider, all_data_providers, kwargs, logger)
data_provider_configurer.ensure_module_installed(organization_id)
data_provider_configurer.configure(lean_config, "backtesting")

lean_config_manager.configure_data_purchase_limit(lean_config, data_purchase_limit)
Expand Down Expand Up @@ -404,7 +407,7 @@ def backtest(project: Path,
lean_config["python-venv"] = f'{"/" if python_venv[0] != "/" else ""}{python_venv}'

# Configure addon modules
build_and_configure_modules(addon_module, container.organization_manager.try_get_working_organization_id(), lean_config, logger, "backtesting")
build_and_configure_modules(addon_module, organization_id, lean_config, logger, "backtesting")

lean_runner = container.lean_runner
lean_runner.run_lean(lean_config,
Expand Down
5 changes: 3 additions & 2 deletions lean/commands/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from lean.components.docker.lean_runner import LeanRunner
from lean.constants import DEFAULT_RESEARCH_IMAGE, LEAN_ROOT_PATH
from lean.container import container
from lean.models.data_providers import QuantConnectDataProvider, all_data_providers
from lean.models.data_providers import QuantConnectDataProvider, all_data_providers, DataProvider
from lean.components.util.name_extraction import convert_to_class_name
from lean.components.util.json_modules_handler import get_and_build_module
from lean.models.click_options import options_from_json, get_configs_for_options
Expand Down Expand Up @@ -113,7 +113,8 @@ def research(project: Path,
data_provider = QuantConnectDataProvider.get_name()

if data_provider is not None:
[data_provider_configurer] = [get_and_build_module(data_provider, all_data_providers, kwargs, logger)]
data_provider_configurer: DataProvider = get_and_build_module(data_provider, all_data_providers, kwargs, logger)
data_provider_configurer.ensure_module_installed(container.organization_manager.try_get_working_organization_id())
data_provider_configurer.configure(lean_config, "backtesting")

lean_config_manager.configure_data_purchase_limit(lean_config, data_purchase_limit)
Expand Down
3 changes: 2 additions & 1 deletion lean/components/util/json_modules_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def build_and_configure_modules(modules: List[AddonModule], organization_id: str
logger.error(f"Addon module '{given_module}' failed to configure: {e}")
return lean_config

def get_and_build_module(target_module_name: str, module_list: List[JsonModule], properties: Dict[str, Any], logger: Logger):

def get_and_build_module(target_module_name: str, module_list: List[JsonModule], properties: Dict[str, Any], logger: Logger) -> JsonModule:
[target_module] = [module for module in module_list if module.get_name() == target_module_name]
# update essential properties from brokerage to datafeed
# needs to be updated before fetching required properties
Expand Down

0 comments on commit ba67ee1

Please sign in to comment.