-
Notifications
You must be signed in to change notification settings - Fork 105
/
status.py
61 lines (49 loc) · 2.51 KB
/
status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean CLI v1.0. Copyright 2021 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from click import command, argument
from lean.click import LeanCommand
from lean.container import container
from lean.models.api import QCLiveAlgorithmStatus
from lean.models.cloud import cloud_brokerages
@command(cls=LeanCommand)
@argument("project", type=str)
def status(project: str) -> None:
"""Show the live trading status of a project in the cloud.
PROJECT must be the name or the id of the project to show the status for.
"""
logger = container.logger
api_client = container.api_client
cloud_project_manager = container.cloud_project_manager
cloud_project = cloud_project_manager.get_cloud_project(project, False)
live_algorithm = api_client.live.get_project_by_id(cloud_project.projectId)
logger.info(f"Project id: {cloud_project.projectId}")
logger.info(f"Project name: {cloud_project.name}")
logger.info(f"Project url: {cloud_project.get_url()}")
if live_algorithm is None:
logger.info("Live status: Not deployed")
return
live_status = {
QCLiveAlgorithmStatus.DeployError: "Deploy error",
QCLiveAlgorithmStatus.InQueue: "In queue",
QCLiveAlgorithmStatus.RuntimeError: "Runtime error",
QCLiveAlgorithmStatus.LoggingIn: "Logging in"
}.get(live_algorithm.status, live_algorithm.status.value)
brokerage_name = next((b.get_name() for b in cloud_brokerages if b.get_id() == live_algorithm.brokerage),
live_algorithm.brokerage)
logger.info(f"Live status: {live_status}")
logger.info(f"Live id: {live_algorithm.deployId}")
logger.info(f"Live url: {live_algorithm.get_url()}")
logger.info(f"Brokerage: {brokerage_name}")
logger.info(f"Launched: {live_algorithm.launched.strftime('%Y-%m-%d %H:%M:%S')} UTC")
if live_algorithm.stopped is not None:
logger.info(f"Stopped: {live_algorithm.stopped.strftime('%Y-%m-%d %H:%M:%S')} UTC")