Skip to content

Commit

Permalink
Address remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky committed Jul 15, 2024
1 parent 7dcc5b5 commit 28a6368
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lean/commands/live/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ def deploy(project: Path,
cash_balance_option, holdings_option, last_cash, last_holdings = get_last_portfolio_cash_holdings(container.api_client, brokerage_instance,
project_config.get("cloud-id", None), project)

# We cannot create the output directory before calling get_last_portfolio_holdings, since then the most recently
# deployment would be always the local one (it has the current time in its name), and we would never be able to
# use the cash and holdings from a cloud deployment (see live_utils._get_last_portfolio() method)
if not output.exists():
output.mkdir(parents=True)

if environment is None and brokerage is None: # condition for using interactive panel
if cash_balance_option != LiveInitialStateInput.NotSupported:
live_cash_balance = _configure_initial_cash_interactively(logger, cash_balance_option, last_cash)
Expand Down Expand Up @@ -338,9 +344,6 @@ def deploy(project: Path,
else:
lean_config[key] = value

if not output.exists():
output.mkdir(parents=True)

output_config_manager = container.output_config_manager
lean_config["algorithm-id"] = f"L-{output_config_manager.get_live_deployment_id(output, given_algorithm_id)}"

Expand Down
4 changes: 2 additions & 2 deletions lean/components/util/live_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def configure_initial_holdings(logger: Logger, holdings_option: LiveInitialState
return _configure_initial_holdings_interactively(logger, holdings_option, previous_holdings)


def get_latest_result_json_file(output_directory: Path, is_previous_state_file: bool = False) -> Optional[Path]:
def get_latest_result_json_file(output_directory: Path, is_live_trading: bool = False) -> Optional[Path]:
from lean.container import container

output_config_manager = container.output_config_manager
Expand All @@ -222,7 +222,7 @@ def get_latest_result_json_file(output_directory: Path, is_previous_state_file:
return None

prefix = ""
if is_previous_state_file:
if is_live_trading:
prefix = "L-"

result_file = output_directory / f"{prefix}{output_id}.json"
Expand Down

0 comments on commit 28a6368

Please sign in to comment.