Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky committed Jul 12, 2024
1 parent f768854 commit 2fca260
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
4 changes: 0 additions & 4 deletions lean/commands/cloud/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ def status(project: str) -> None:

if live_algorithm.stopped is not None:
logger.info(f"Stopped: {live_algorithm.stopped.strftime('%Y-%m-%d %H:%M:%S')} UTC")

if live_algorithm.error != "":
logger.info("Error:")
logger.info(live_algorithm.error)
3 changes: 2 additions & 1 deletion lean/components/api/live_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def get_project_by_id(self,
response = self._api.get("live/read", parameters)

if response:
return QCFullLiveAlgorithm(data=response)
response["projectId"] = project_id
return QCFullLiveAlgorithm(**response)

return None

Expand Down
1 change: 0 additions & 1 deletion lean/components/util/live_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def _get_last_portfolio(api_client: APIClient, project_id: str, project_name: Pa
from os import listdir, path
from json import loads
from datetime import datetime
from lean.container import container

cloud_last_time = utc.localize(datetime.min)
if project_id:
Expand Down
2 changes: 0 additions & 2 deletions lean/models/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ class QCFullLiveAlgorithm(QCMinimalLiveAlgorithm):
launched: datetime
stopped: Optional[datetime]
brokerage: str
subscription: str
error: str


class QCEmailNotificationMethod(WrappedBaseModel):
Expand Down
30 changes: 25 additions & 5 deletions tests/commands/cloud/live/test_cloud_live_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def test_cloud_live_deploy() -> None:

api_client = mock.Mock()
api_client.nodes.get_all.return_value = create_qc_nodes()
api_client.get.return_value = {'portfolio': {"cash": {}}, 'live': []}
api_client.get.return_value = {
"status": "stopped",
"stopped": "2024-07-10 19:12:20",
"success": True,
"portfolio": {"holdings": {}, "cash": {}, "success": True}}
container.api_client = api_client

cloud_project_manager = mock.Mock()
Expand Down Expand Up @@ -98,7 +102,11 @@ def test_cloud_live_deploy_with_ib_using_hybrid_datafeed() -> None:

api_client = mock.Mock()
api_client.nodes.get_all.return_value = create_qc_nodes()
api_client.get.return_value = {'portfolio': {"cash": {}}, 'live': []}
api_client.get.return_value = {
"status": "stopped",
"stopped": "2024-07-10 19:12:20",
"success": True,
"portfolio": {"holdings": {}, "cash": {}, "success": True}}
container.api_client = api_client

cloud_project_manager = mock.Mock()
Expand Down Expand Up @@ -155,7 +163,11 @@ def test_cloud_live_deploy_with_notifications(notice_method: str, configs: str)

api_client = mock.Mock()
api_client.nodes.get_all.return_value = create_qc_nodes()
api_client.get.return_value = {'portfolio': {"cash": {}}, 'live': []}
api_client.get.return_value = {
"status": "stopped",
"stopped": "2024-07-10 19:12:20",
"success": True,
"portfolio": {"holdings": {}, "cash": {}, "success": True}}
container.api_client = api_client

cloud_project_manager = mock.Mock()
Expand Down Expand Up @@ -238,7 +250,11 @@ def test_cloud_live_deploy_with_live_cash_balance(brokerage: str, cash: str) ->

api_client = mock.Mock()
api_client.nodes.get_all.return_value = create_qc_nodes()
api_client.get.return_value = {'live': [], 'portfolio': {}}
api_client.get.return_value = {
"status": "stopped",
"stopped": "2024-07-10 19:12:20",
"success": True,
"portfolio": {}}
container.api_client = api_client

cloud_runner = mock.Mock()
Expand Down Expand Up @@ -315,7 +331,11 @@ def test_cloud_live_deploy_with_live_holdings(brokerage: str, holdings: str) ->

api_client = mock.Mock()
api_client.nodes.get_all.return_value = create_qc_nodes()
api_client.get.return_value = {'live': [], 'portfolio': {}}
api_client.get.return_value = {
"status": "stopped",
"stopped": "2024-07-10 19:12:20",
"success": True,
"portfolio": {}}
container.api_client = api_client

cloud_runner = mock.Mock()
Expand Down
6 changes: 3 additions & 3 deletions tests/commands/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,14 @@ def test_live_deploy_with_different_brokerage_and_different_live_data_provider_a

is_exists = []
if brokerage_product_id is None and data_provider_historical_name != "Local":
assert len(api_client.method_calls) == 3
assert len(api_client.method_calls) == 2
for m_c, id in zip(api_client.method_calls, [data_provider_live_product_id, data_provider_historical_id]):
if id in m_c[1]:
is_exists.append(True)
assert is_exists
assert len(is_exists) == 2
elif brokerage_product_id is None and data_provider_historical_name == "Local":
assert len(api_client.method_calls) == 2
assert len(api_client.method_calls) == 1
if data_provider_live_product_id in api_client.method_calls[0][1]:
is_exists.append(True)
assert is_exists
Expand Down Expand Up @@ -1243,7 +1243,7 @@ def test_live_non_interactive_deploy_paper_brokerage_different_live_data_provide
api_client = mock.MagicMock()
create_lean_option(brokerage_name, data_provider_live_name, None, api_client)

assert len(api_client.method_calls) == 2
assert len(api_client.method_calls) == 1
for m_c in api_client.method_calls:
if data_provider_live_product_id in m_c[1]:
is_exist = True
Expand Down

0 comments on commit 2fca260

Please sign in to comment.