Skip to content

Commit 2cccead

Browse files
Merge pull request #123 from rjra2611/feature-add-lean-live-commands
Feature add lean live commands
2 parents 2cf48ef + 1a12b78 commit 2cccead

29 files changed

+1264
-34
lines changed

README.md

Lines changed: 229 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ A locally-focused workflow (local development, local execution) with the CLI may
7272
- [`lean build`](#lean-build)
7373
- [`lean cloud backtest`](#lean-cloud-backtest)
7474
- [`lean cloud live`](#lean-cloud-live)
75+
- [`lean cloud live deploy`](#lean-cloud-live-deploy)
76+
- [`lean cloud live liquidate`](#lean-cloud-live-liquidate)
77+
- [`lean cloud live stop`](#lean-cloud-live-stop)
7578
- [`lean cloud optimize`](#lean-cloud-optimize)
7679
- [`lean cloud pull`](#lean-cloud-pull)
7780
- [`lean cloud push`](#lean-cloud-push)
@@ -87,6 +90,13 @@ A locally-focused workflow (local development, local execution) with the CLI may
8790
- [`lean library add`](#lean-library-add)
8891
- [`lean library remove`](#lean-library-remove)
8992
- [`lean live`](#lean-live)
93+
- [`lean live add-security`](#lean-live-add-security)
94+
- [`lean live cancel-order`](#lean-live-cancel-order)
95+
- [`lean live deploy`](#lean-live-deploy)
96+
- [`lean live liquidate`](#lean-live-liquidate)
97+
- [`lean live stop`](#lean-live-stop)
98+
- [`lean live submit-order`](#lean-live-submit-order)
99+
- [`lean live update-order`](#lean-live-update-order)
90100
- [`lean login`](#lean-login)
91101
- [`lean logout`](#lean-logout)
92102
- [`lean logs`](#lean-logs)
@@ -195,10 +205,30 @@ _See code: [lean/commands/cloud/backtest.py](lean/commands/cloud/backtest.py)_
195205

196206
### `lean cloud live`
197207

208+
Interact with the QuantConnect cloud live deployments.
209+
210+
```
211+
Usage: lean cloud live [OPTIONS] COMMAND [ARGS]...
212+
213+
Interact with the QuantConnect cloud live deployments.
214+
215+
Options:
216+
--help Show this message and exit.
217+
218+
Commands:
219+
deploy Start live trading for a project in the cloud.
220+
liquidate Stops live trading and liquidates existing positions for a certain project.
221+
stop Stops live trading for a certain project without liquidating existing positions.
222+
```
223+
224+
_See code: [lean/commands/cloud/live.py](lean/commands/cloud/live.py)_
225+
226+
### `lean cloud live deploy`
227+
198228
Start live trading for a project in the cloud.
199229

200230
```
201-
Usage: lean cloud live [OPTIONS] PROJECT
231+
Usage: lean cloud live deploy [OPTIONS] PROJECT
202232
203233
Start live trading for a project in the cloud.
204234
@@ -242,19 +272,21 @@ Options:
242272
--binanceus-api-secret TEXT Your Binance API secret
243273
--zerodha-api-key TEXT Your Kite Connect API key
244274
--zerodha-access-token TEXT Your Kite Connect access token
245-
--zerodha-product-type [MIS|CNC|NRML]
275+
--zerodha-product-type [mis|cnc|nrml]
246276
MIS if you are targeting intraday products, CNC if you are targeting delivery
247277
products, NRML if you are targeting carry forward products
248-
--zerodha-trading-segment [EQUITY|COMMODITY]
278+
--zerodha-trading-segment [equity|commodity]
249279
EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading
250280
commodities on MCX
281+
--zerodha-history-subscription [true|false]
282+
Whether you have a history API subscription for Zerodha
251283
--samco-client-id TEXT Your Samco account Client ID
252284
--samco-client-password TEXT Your Samco account password
253285
--samco-year-of-birth TEXT Your year of birth (YYYY) registered with Samco
254-
--samco-product-type [MIS|CNC|NRML]
286+
--samco-product-type [mis|cnc|nrml]
255287
MIS if you are targeting intraday products, CNC if you are targeting delivery
256288
products, NRML if you are targeting carry forward products
257-
--samco-trading-segment [EQUITY|COMMODITY]
289+
--samco-trading-segment [equity|commodity]
258290
EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading
259291
commodities on MCX
260292
--kraken-api-key TEXT Your Kraken API key
@@ -285,7 +317,39 @@ Options:
285317
--help Show this message and exit.
286318
```
287319

288-
_See code: [lean/commands/cloud/live.py](lean/commands/cloud/live.py)_
320+
_See code: [lean/commands/cloud/live/deploy.py](lean/commands/cloud/live/deploy.py)_
321+
322+
### `lean cloud live liquidate`
323+
324+
Stops live trading and liquidates existing positions for a certain project.
325+
326+
```
327+
Usage: lean cloud live liquidate [OPTIONS] PROJECT
328+
329+
Stops live trading and liquidates existing positions for a certain project.
330+
331+
Options:
332+
--verbose Enable debug logging
333+
--help Show this message and exit.
334+
```
335+
336+
_See code: [lean/commands/cloud/live/liquidate.py](lean/commands/cloud/live/liquidate.py)_
337+
338+
### `lean cloud live stop`
339+
340+
Stops live trading for a certain project without liquidating existing positions.
341+
342+
```
343+
Usage: lean cloud live stop [OPTIONS] PROJECT
344+
345+
Stops live trading for a certain project without liquidating existing positions.
346+
347+
Options:
348+
--verbose Enable debug logging
349+
--help Show this message and exit.
350+
```
351+
352+
_See code: [lean/commands/cloud/live/stop.py](lean/commands/cloud/live/stop.py)_
289353

290354
### `lean cloud optimize`
291355

@@ -659,10 +723,78 @@ _See code: [lean/commands/library/remove.py](lean/commands/library/remove.py)_
659723

660724
### `lean live`
661725

726+
Interact with the local machine.
727+
728+
```
729+
Usage: lean live [OPTIONS] COMMAND [ARGS]...
730+
731+
Interact with the local machine.
732+
733+
Options:
734+
--help Show this message and exit.
735+
736+
Commands:
737+
add-security Represents a command to add a security to the algorithm.
738+
cancel-order Represents a command to cancel a specific order by id.
739+
deploy Start live trading a project locally using Docker.
740+
liquidate Liquidate the given symbol from the latest deployment of the given project.
741+
stop Stop an already running local live trading project.
742+
submit-order Represents a command to submit an order to the algorithm.
743+
update-order Represents a command to update a specific order by id.
744+
```
745+
746+
_See code: [lean/commands/live.py](lean/commands/live.py)_
747+
748+
### `lean live add-security`
749+
750+
Represents a command to add a security to the algorithm.
751+
752+
```
753+
Usage: lean live add-security [OPTIONS] PROJECT
754+
755+
Represents a command to add a security to the algorithm.
756+
757+
Options:
758+
--ticker TEXT The ticker of the symbol to add [required]
759+
--market TEXT The market of the symbol to add [required]
760+
--security-type TEXT The security type of the symbol to add [required]
761+
--resolution TEXT The resolution of the symbol to add
762+
--fill-data-forward The fill forward behavior, true to fill forward, false otherwise - defaults to true
763+
--leverage DECIMAL The leverage for the security, defaults to 2 for equity, 50 for forex, and 1 for everything
764+
else
765+
--extended-market-hours The extended market hours flag, true to allow pre/post market data, false for only in market
766+
data
767+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
768+
--verbose Enable debug logging
769+
--help Show this message and exit.
770+
```
771+
772+
_See code: [lean/commands/live/add_security.py](lean/commands/live/add_security.py)_
773+
774+
### `lean live cancel-order`
775+
776+
Represents a command to cancel a specific order by id.
777+
778+
```
779+
Usage: lean live cancel-order [OPTIONS] PROJECT
780+
781+
Represents a command to cancel a specific order by id.
782+
783+
Options:
784+
--order-id INTEGER The order id to be cancelled [required]
785+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
786+
--verbose Enable debug logging
787+
--help Show this message and exit.
788+
```
789+
790+
_See code: [lean/commands/live/cancel_order.py](lean/commands/live/cancel_order.py)_
791+
792+
### `lean live deploy`
793+
662794
Start live trading a project locally using Docker.
663795

664796
```
665-
Usage: lean live [OPTIONS] PROJECT
797+
Usage: lean live deploy [OPTIONS] PROJECT
666798
667799
Start live trading a project locally using Docker.
668800
@@ -730,22 +862,22 @@ Options:
730862
--zerodha-organization TEXT The name or id of the organization with the zerodha module subscription
731863
--zerodha-api-key TEXT Your Kite Connect API key
732864
--zerodha-access-token TEXT Your Kite Connect access token
733-
--zerodha-product-type [MIS|CNC|NRML]
865+
--zerodha-product-type [mis|cnc|nrml]
734866
MIS if you are targeting intraday products, CNC if you are targeting delivery
735867
products, NRML if you are targeting carry forward products
736-
--zerodha-trading-segment [EQUITY|COMMODITY]
868+
--zerodha-trading-segment [equity|commodity]
737869
EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading
738870
commodities on MCX
739-
--zerodha-history-subscription BOOLEAN
871+
--zerodha-history-subscription [true|false]
740872
Whether you have a history API subscription for Zerodha
741873
--samco-organization TEXT The name or id of the organization with the samco module subscription
742874
--samco-client-id TEXT Your Samco account Client ID
743875
--samco-client-password TEXT Your Samco account password
744876
--samco-year-of-birth TEXT Your year of birth (YYYY) registered with Samco
745-
--samco-product-type [MIS|CNC|NRML]
877+
--samco-product-type [mis|cnc|nrml]
746878
MIS if you are targeting intraday products, CNC if you are targeting delivery
747879
products, NRML if you are targeting carry forward products
748-
--samco-trading-segment [EQUITY|COMMODITY]
880+
--samco-trading-segment [equity|commodity]
749881
EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading
750882
commodities on MCX
751883
--terminal-link-organization TEXT
@@ -827,7 +959,91 @@ Options:
827959
--help Show this message and exit.
828960
```
829961

830-
_See code: [lean/commands/live.py](lean/commands/live.py)_
962+
_See code: [lean/commands/live/deploy.py](lean/commands/live/deploy.py)_
963+
964+
### `lean live liquidate`
965+
966+
Liquidate the given symbol from the latest deployment of the given project.
967+
968+
```
969+
Usage: lean live liquidate [OPTIONS] PROJECT
970+
971+
Liquidate the given symbol from the latest deployment of the given project.
972+
973+
Options:
974+
--ticker TEXT The ticker of the symbol to liquidate
975+
--market TEXT The market of the symbol to liquidate
976+
--security-type TEXT The security type of the symbol to liquidate
977+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
978+
--verbose Enable debug logging
979+
--help Show this message and exit.
980+
```
981+
982+
_See code: [lean/commands/live/liquidate.py](lean/commands/live/liquidate.py)_
983+
984+
### `lean live stop`
985+
986+
Stop an already running local live trading project.
987+
988+
```
989+
Usage: lean live stop [OPTIONS] PROJECT
990+
991+
Stop an already running local live trading project.
992+
993+
Options:
994+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
995+
--verbose Enable debug logging
996+
--help Show this message and exit.
997+
```
998+
999+
_See code: [lean/commands/live/stop.py](lean/commands/live/stop.py)_
1000+
1001+
### `lean live submit-order`
1002+
1003+
Represents a command to submit an order to the algorithm.
1004+
1005+
```
1006+
Usage: lean live submit-order [OPTIONS] PROJECT
1007+
1008+
Represents a command to submit an order to the algorithm.
1009+
1010+
Options:
1011+
--ticker TEXT The ticker of the symbol to be submitted [required]
1012+
--market TEXT The market of the symbol to be submitted [required]
1013+
--security-type TEXT The security type of the symbol to be submitted [required]
1014+
--order-type TEXT The order type to be submitted [required]
1015+
--quantity DECIMAL The number of units to be ordered (directional) [required]
1016+
--limit-price DECIMAL The limit price of the order be submitted
1017+
--stop-price DECIMAL The stop price of the order to be submitted
1018+
--tag TEXT The tag to be attached to the order
1019+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
1020+
--verbose Enable debug logging
1021+
--help Show this message and exit.
1022+
```
1023+
1024+
_See code: [lean/commands/live/submit_order.py](lean/commands/live/submit_order.py)_
1025+
1026+
### `lean live update-order`
1027+
1028+
Represents a command to update a specific order by id.
1029+
1030+
```
1031+
Usage: lean live update-order [OPTIONS] PROJECT
1032+
1033+
Represents a command to update a specific order by id.
1034+
1035+
Options:
1036+
--order-id INTEGER The order id to be updated [required]
1037+
--quantity DECIMAL The number of units to be updated (directional)
1038+
--limit-price DECIMAL The limit price of the order to be updated
1039+
--stop-price DECIMAL The stop price of the order to be updated
1040+
--tag TEXT The tag to be attached to the order
1041+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
1042+
--verbose Enable debug logging
1043+
--help Show this message and exit.
1044+
```
1045+
1046+
_See code: [lean/commands/live/update_order.py](lean/commands/live/update_order.py)_
8311047

8321048
### `lean login`
8331049

lean/commands/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from lean.commands.data import data
2323
from lean.commands.init import init
2424
from lean.commands.library import library
25-
from lean.commands.live import live
25+
from lean.commands.live.live import live
2626
from lean.commands.login import login
2727
from lean.commands.logout import logout
2828
from lean.commands.logs import logs
@@ -45,7 +45,7 @@ def lean() -> None:
4545
lean.add_command(cloud)
4646
lean.add_command(data)
4747
lean.add_command(library)
48-
48+
lean.add_command(live)
4949
lean.add_command(login)
5050
lean.add_command(logout)
5151
lean.add_command(whoami)
@@ -55,6 +55,5 @@ def lean() -> None:
5555
lean.add_command(optimize)
5656
lean.add_command(research)
5757
lean.add_command(report)
58-
lean.add_command(live)
5958
lean.add_command(build)
6059
lean.add_command(logs)

lean/commands/cloud/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import click
1515

1616
from lean.commands.cloud.backtest import backtest
17-
from lean.commands.cloud.live import live
17+
from lean.commands.cloud.live.live import live
1818
from lean.commands.cloud.optimize import optimize
1919
from lean.commands.cloud.pull import pull
2020
from lean.commands.cloud.push import push
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
2+
# Lean CLI v1.0. Copyright 2021 QuantConnect Corporation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
from lean.commands.cloud.live.live import live
15+
from lean.commands.cloud.live.deploy import deploy
16+
from lean.commands.cloud.live.stop import stop
17+
from lean.commands.cloud.live.liquidate import liquidate
18+
19+
20+
live.add_command(deploy)
21+
live.add_command(stop)
22+
live.add_command(liquidate)

0 commit comments

Comments
 (0)