Skip to content

Commit f99344c

Browse files
authored
Feature Implement Object Store Commands (#356)
* initial implementation * object store readme updates * cleanup * add tests * self review * fix alignment * fix style and cleanup * add alias for get command * add local object store commands * update readme and tests * fix readme * address review * fix tests * fix tests
1 parent e17aab8 commit f99344c

File tree

22 files changed

+812
-3
lines changed

22 files changed

+812
-3
lines changed

README.md

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ A locally-focused workflow (local development, local execution) with the CLI may
7575
- [`lean cloud live deploy`](#lean-cloud-live-deploy)
7676
- [`lean cloud live liquidate`](#lean-cloud-live-liquidate)
7777
- [`lean cloud live stop`](#lean-cloud-live-stop)
78+
- [`lean cloud object-store delete`](#lean-cloud-object-store-delete)
79+
- [`lean cloud object-store get`](#lean-cloud-object-store-get)
80+
- [`lean cloud object-store list`](#lean-cloud-object-store-list)
81+
- [`lean cloud object-store ls`](#lean-cloud-object-store-ls)
82+
- [`lean cloud object-store set`](#lean-cloud-object-store-set)
7883
- [`lean cloud optimize`](#lean-cloud-optimize)
7984
- [`lean cloud pull`](#lean-cloud-pull)
8085
- [`lean cloud push`](#lean-cloud-push)
@@ -101,6 +106,11 @@ A locally-focused workflow (local development, local execution) with the CLI may
101106
- [`lean login`](#lean-login)
102107
- [`lean logout`](#lean-logout)
103108
- [`lean logs`](#lean-logs)
109+
- [`lean object-store delete`](#lean-object-store-delete)
110+
- [`lean object-store get`](#lean-object-store-get)
111+
- [`lean object-store list`](#lean-object-store-list)
112+
- [`lean object-store ls`](#lean-object-store-ls)
113+
- [`lean object-store set`](#lean-object-store-set)
104114
- [`lean optimize`](#lean-optimize)
105115
- [`lean project-create`](#lean-project-create)
106116
- [`lean project-delete`](#lean-project-delete)
@@ -374,6 +384,88 @@ Options:
374384

375385
_See code: [lean/commands/cloud/live/stop.py](lean/commands/cloud/live/stop.py)_
376386

387+
### `lean cloud object-store delete`
388+
389+
Delete a value from the organization's cloud object store.
390+
391+
```
392+
Usage: lean cloud object-store delete [OPTIONS] KEY
393+
394+
Delete a value from the organization's cloud object store.
395+
396+
Options:
397+
--verbose Enable debug logging
398+
--help Show this message and exit.
399+
```
400+
401+
_See code: [lean/commands/cloud/object_store/delete.py](lean/commands/cloud/object_store/delete.py)_
402+
403+
### `lean cloud object-store get`
404+
405+
Get a value from the organization's cloud object store.
406+
407+
```
408+
Usage: lean cloud object-store get [OPTIONS] KEY
409+
410+
Get a value from the organization's cloud object store.
411+
412+
Options:
413+
--verbose Enable debug logging
414+
--help Show this message and exit.
415+
```
416+
417+
_See code: [lean/commands/cloud/object_store/get.py](lean/commands/cloud/object_store/get.py)_
418+
419+
### `lean cloud object-store list`
420+
421+
List all values for the given root key in the organization's cloud object store.
422+
423+
```
424+
Usage: lean cloud object-store list [OPTIONS] [KEY]
425+
426+
List all values for the given root key in the organization's cloud object store.
427+
428+
Options:
429+
--verbose Enable debug logging
430+
--help Show this message and exit.
431+
```
432+
433+
_See code: [lean/commands/cloud/object_store/list.py](lean/commands/cloud/object_store/list.py)_
434+
435+
### `lean cloud object-store ls`
436+
437+
Alias for 'list'
438+
439+
```
440+
Usage: lean cloud object-store ls [OPTIONS] [KEY]
441+
442+
List all values for the given root key in the organization's cloud object store.
443+
444+
Options:
445+
--verbose Enable debug logging
446+
--help Show this message and exit.
447+
```
448+
449+
_See code: [lean/commands/cloud/object_store/ls.py](lean/commands/cloud/object_store/ls.py)_
450+
451+
### `lean cloud object-store set`
452+
453+
Sets the data to the given key in the organization's cloud object store.
454+
455+
```
456+
Usage: lean cloud object-store set [OPTIONS] KEY PATH
457+
458+
Sets the data to the given key in the organization's cloud object store.
459+
460+
:param key: The key to set the data to. :param path: Path to the file containing the object data.
461+
462+
Options:
463+
--verbose Enable debug logging
464+
--help Show this message and exit.
465+
```
466+
467+
_See code: [lean/commands/cloud/object_store/set.py](lean/commands/cloud/object_store/set.py)_
468+
377469
### `lean cloud optimize`
378470

379471
Optimize a project in the cloud.
@@ -638,7 +730,7 @@ Usage: lean data generate [OPTIONS]
638730
Options:
639731
--start [yyyyMMdd] Start date for the data to generate in yyyyMMdd format [required]
640732
--end [yyyyMMdd] End date for the data to generate in yyyyMMdd format (defaults to today)
641-
--symbol-count INTEGER RANGE The number of symbols to generate data for [x>=0; required]
733+
--symbol-count INTEGER RANGE The number of symbols to generate data for [x>=0]
642734
--tickers TEXT Comma separated list of tickers to use for generated data
643735
--security-type [Equity|Forex|Cfd|Future|Crypto|Option]
644736
The security type to generate data for (defaults to Equity)
@@ -648,6 +740,31 @@ Options:
648740
The density of the generated data (defaults to Dense)
649741
--include-coarse BOOLEAN Whether coarse universe data should be generated for Equity data (defaults to True)
650742
--market TEXT The market to generate data for (defaults to standard market for the security type)
743+
--quote-trade-ratio FLOAT The ratio of generated quotes to generated trades. Values larger than 1 mean more
744+
quotes than trades. Only used for Option, Future and Crypto (defaults to 1)
745+
--random-seed INTEGER RANGE The random number generator seed. Defaults to None, which means no seed will be used
746+
[x>=0]
747+
--ipo-percentage FLOAT The probability each equity generated will have an IPO event. Note that this is not
748+
the total probability for all symbols generated. Only used for Equity (defaults to
749+
5.0)
750+
--rename-percentage FLOAT The probability each equity generated will have a rename event. Note that this is not
751+
the total probability for all symbols generated. Only used for Equity (defaults to
752+
30.0)
753+
--splits-percentage FLOAT The probability each equity generated will have a stock split event. Note that this is
754+
not the total probability for all symbols generated. Only used for Equity (defaults to
755+
15.0)
756+
--dividends-percentage FLOAT The probability each equity generated will have dividends. Note that this is not the
757+
probability for all symbols genearted. Only used for Equity (defaults to 60.0)
758+
--dividend-every-quarter-percentage FLOAT
759+
The probability each equity generated will have a dividend event every quarter. Note
760+
that this is not the total probability for all symbols generated. Only used for Equity
761+
(defaults to 30.0)
762+
--option-price-engine TEXT The stochastic process, and returns new pricing engine to run calculations for that
763+
option (defaults to BaroneAdesiWhaleyApproximationEngine)
764+
--volatility-model-resolution [Tick|Second|Minute|Hour|Daily]
765+
The volatility model period span (defaults to Daily)
766+
--chain-symbol-count INTEGER RANGE
767+
The size of the option chain (defaults to 10) [x>=0]
651768
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
652769
--update Pull the LEAN engine image before running the generator
653770
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
@@ -1129,6 +1246,86 @@ Options:
11291246

11301247
_See code: [lean/commands/logs.py](lean/commands/logs.py)_
11311248

1249+
### `lean object-store delete`
1250+
1251+
Opens the local storage directory in the file explorer.
1252+
1253+
```
1254+
Usage: lean object-store delete [OPTIONS]
1255+
1256+
Opens the local storage directory in the file explorer.
1257+
1258+
Options:
1259+
--verbose Enable debug logging
1260+
--help Show this message and exit.
1261+
```
1262+
1263+
_See code: [lean/commands/object_store/delete.py](lean/commands/object_store/delete.py)_
1264+
1265+
### `lean object-store get`
1266+
1267+
Opens the local storage directory in the file explorer.
1268+
1269+
```
1270+
Usage: lean object-store get [OPTIONS]
1271+
1272+
Opens the local storage directory in the file explorer.
1273+
1274+
Options:
1275+
--verbose Enable debug logging
1276+
--help Show this message and exit.
1277+
```
1278+
1279+
_See code: [lean/commands/object_store/get.py](lean/commands/object_store/get.py)_
1280+
1281+
### `lean object-store list`
1282+
1283+
Opens the local storage directory in the file explorer.
1284+
1285+
```
1286+
Usage: lean object-store list [OPTIONS]
1287+
1288+
Opens the local storage directory in the file explorer.
1289+
1290+
Options:
1291+
--verbose Enable debug logging
1292+
--help Show this message and exit.
1293+
```
1294+
1295+
_See code: [lean/commands/object_store/list.py](lean/commands/object_store/list.py)_
1296+
1297+
### `lean object-store ls`
1298+
1299+
Alias for 'list'
1300+
1301+
```
1302+
Usage: lean object-store ls [OPTIONS]
1303+
1304+
Opens the local storage directory in the file explorer.
1305+
1306+
Options:
1307+
--verbose Enable debug logging
1308+
--help Show this message and exit.
1309+
```
1310+
1311+
_See code: [lean/commands/object_store/ls.py](lean/commands/object_store/ls.py)_
1312+
1313+
### `lean object-store set`
1314+
1315+
Opens the local storage directory in the file explorer.
1316+
1317+
```
1318+
Usage: lean object-store set [OPTIONS]
1319+
1320+
Opens the local storage directory in the file explorer.
1321+
1322+
Options:
1323+
--verbose Enable debug logging
1324+
--help Show this message and exit.
1325+
```
1326+
1327+
_See code: [lean/commands/object_store/set.py](lean/commands/object_store/set.py)_
1328+
11321329
### `lean optimize`
11331330

11341331
Optimize a project's parameters locally using Docker.

lean/commands/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from lean.commands.research import research
3131
from lean.commands.whoami import whoami
3232
from lean.commands.gui import gui
33+
from lean.commands.object_store import object_store
3334

3435
lean.add_command(config)
3536
lean.add_command(cloud)
@@ -49,3 +50,4 @@
4950
lean.add_command(build)
5051
lean.add_command(logs)
5152
lean.add_command(gui)
53+
lean.add_command(object_store)

lean/commands/cloud/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lean.commands.cloud.pull import pull
2020
from lean.commands.cloud.push import push
2121
from lean.commands.cloud.status import status
22-
22+
from lean.commands.cloud.object_store import object_store
2323

2424
@group()
2525
def cloud() -> None:
@@ -35,3 +35,4 @@ def cloud() -> None:
3535
cloud.add_command(optimize)
3636
cloud.add_command(live)
3737
cloud.add_command(status)
38+
cloud.add_command(object_store)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.object_store.object_store import object_store
15+
from lean.commands.cloud.object_store.get import get
16+
from lean.commands.cloud.object_store.set import set
17+
from lean.commands.cloud.object_store.list import list
18+
from lean.commands.cloud.object_store.delete import delete
19+
20+
object_store.add_command(get)
21+
object_store.add_command(set)
22+
object_store.add_command(list)
23+
object_store.add_command(delete)
24+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 click import command, argument
15+
16+
from lean.click import LeanCommand
17+
from lean.container import container
18+
19+
20+
@command(cls=LeanCommand)
21+
@argument("key", type=str)
22+
def delete(key: str) -> str:
23+
"""
24+
Delete a value from the organization's cloud object store.
25+
26+
"""
27+
organization_id = container.organization_manager.try_get_working_organization_id()
28+
api_client = container.api_client
29+
api_client.object_store.delete(key, organization_id)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 click import command, argument
15+
from lean.click import LeanCommand
16+
from lean.container import container
17+
18+
19+
@command(cls=LeanCommand)
20+
@argument("key", type=str)
21+
def get(key: str) -> str:
22+
"""
23+
Get a value from the organization's cloud object store.
24+
25+
"""
26+
organization_id = container.organization_manager.try_get_working_organization_id()
27+
api_client = container.api_client
28+
logger = container.logger
29+
data = api_client.object_store.get(key, organization_id)
30+
31+
try:
32+
headers = ["size", "modified", "key", "preview"]
33+
display_headers = ["Bytes", "Modified", "Filename", "Preview"]
34+
data_row = []
35+
for header in headers:
36+
if header == "preview":
37+
value = str(data["metadata"].get(header, "N/A"))
38+
data_row.append(_clean_up_preview(value))
39+
else:
40+
value = str(data["metadata"].get(header, ""))
41+
data_row.append(value)
42+
all_rows = [display_headers] + [data_row]
43+
column_widths = [max(len(row[i]) for row in all_rows) for i in range(len(all_rows[0]))]
44+
for row in all_rows:
45+
logger.info(" ".join(value.ljust(width) for value, width in zip(row, column_widths)))
46+
except KeyError as e:
47+
logger.error(f"Key {key} not found.")
48+
except Exception as e:
49+
logger.error(f"Error: {e}")
50+
51+
52+
def _clean_up_preview(preview: str) -> str:
53+
return preview.rstrip()[:10]
54+
55+

0 commit comments

Comments
 (0)