-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.py
77 lines (59 loc) · 2.74 KB
/
cli.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import click
from importlib import import_module
from datetime import datetime, timedelta
from reinforce_trader.research.datalake_client import DatalakeClient
DL_CLIENT = DatalakeClient(datalake_dir='./data')
# Setting the date range (last month)
DEFAULT_END_DATE = datetime.today()
@click.group()
def cli():
"""
CLI application to manage data.
This application provides a set of commands for data management. You can perform
operations like adding and updating data sources. For help on specific commands,
run them with the '-h' or '--help' flag.
"""
pass
@cli.group()
def datalake():
"""
Datalake operations group.
This group includes commands related to Datalake operations. You can add new data sources
or update existing ones. For specific operations, use 'add' or 'update' commands
with this group. For more information on these commands, use '-h' or '--help'.
"""
pass
@datalake.command()
@click.option('--name', required=True, help='The name of the data source to update')
@click.option('--start-date', required=False, default=None, help='The starting date of new data. Default to be the date of trailling half year from the ending date')
@click.option('--end-date', required=False, default=None, help='The ending date of the new data. Defualt to be today')
def update(name, start_date, end_date):
"""
Update an existing data source.
This command allows you to update an existing data source specified by its name.
"""
data_source = import_module(f'reinforce_trader.research.data_sources.{name}_data_source')
if end_date is None:
end_date = datetime.today()
if start_date is None:
# use trailling half year as the default start_date
start_date = end_date - timedelta(days=30*6)
data_source.update_data(DL_CLIENT, start_date, end_date)
@datalake.command()
@click.option('--name', required=True, help='The name of the data source to add')
@click.option('--start-date', required=False, default=None, help='The starting date of new data. Default to be the date of trailling half year from the ending date')
@click.option('--end-date', required=False, default=None, help='The ending date of the new data. Defualt to be today')
def add(name, start_date, end_date):
"""
Add a new data source.
This command allows you to add a new data source with a specified name.
"""
data_source = import_module(f'reinforce_trader.research.data_sources.{name}_data_source')
if end_date is None:
end_date = datetime.today()
if start_date is None:
# use trailling 10 year as the default start_date
start_date = end_date - timedelta(days=10*365)
data_source.add_data(DL_CLIENT, start_date, end_date)
if __name__ == '__main__':
cli()