Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rjra2611 committed Jan 22, 2024
1 parent df72f1e commit dc7e217
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/commands/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ def create_fake_environment(name: str, live_mode: bool) -> None:
path.write_text(config, encoding="utf-8")


def create_fake_binance_environment(name: str, live_mode: bool) -> None:
path = Path.cwd() / "lean.json"
config = path.read_text(encoding="utf-8")
config = config.replace("{", f"""
{{
"binance-use-testnet": "live",
"binance-exchange-name": "binance",
"binance-api-secret": "abc",
"binance-api-key": "abc",
"organization-id": "abc",
"environments": {{
"{name}": {{
"live-mode": {str(live_mode).lower()},
"live-mode-brokerage": "QuantConnect.BinanceBrokerage.BinanceCoinFuturesBrokerage",
"data-queue-handler": [ "QuantConnect.BinanceBrokerage.BinanceCoinFuturesBrokerage" ],
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BrokerageTransactionHandler",
"history-provider": [ "BrokerageHistoryProvider", "SubscriptionDataReaderHistoryProvider" ]
}}
}},
""")

path.write_text(config, encoding="utf-8")

def test_live_calls_lean_runner_with_correct_algorithm_file() -> None:
# TODO: currently it is not using the live-paper envrionment
Expand Down Expand Up @@ -258,6 +286,20 @@ def test_live_aborts_when_lean_config_is_missing_properties(target: str, replace

lean_runner.run_lean.assert_not_called()

def test_live_sets_dependent_configurations_from_modules_json_based_on_environment() -> None:
create_fake_lean_cli_directory()
create_fake_binance_environment("live-binance", True)
lean_runner = container.lean_runner

config_path = Path.cwd() / "lean.json"
config = config_path.read_text(encoding="utf-8")
config_path.write_text(config.replace("binance-exchange-name", "different-config"), encoding="utf-8")

result = CliRunner().invoke(lean, ["live", "Python Project", "--environment", "live-binance"])

assert result.exit_code == 0

lean_runner.run_lean.assert_called()

terminal_link_required_options = {
"terminal-link-connection-type": "SAPI",
Expand Down

0 comments on commit dc7e217

Please sign in to comment.