10
10
11
11
Save output to a file:
12
12
python main.py stocks historical eod-report AAPL 20240101 20240131 --output-file aapl_eod.csv
13
+
14
+ Stocks Snapshot Data:
15
+ Get real-time quotes:
16
+ python main.py stocks snapshot quotes AAPL
17
+
18
+ Get real-time OHLC:
19
+ python main.py stocks snapshot ohlc NVDA
20
+
21
+ Get real-time trades:
22
+ python main.py stocks snapshot trades TSLA
13
23
"""
14
24
15
25
import typer
23
33
sys .path .append (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
24
34
25
35
from src .stocks_historical import ThetaDataStocksHistorical
26
- from typing import Optional
36
+ from src .stocks import ThetaDataStocksSnapshot
37
+ from typing import Optional , List
27
38
28
39
app = typer .Typer ()
29
40
stocks_app = typer .Typer ()
41
+ historical_app = typer .Typer ()
42
+ snapshot_app = typer .Typer ()
30
43
options_app = typer .Typer ()
31
44
app .add_typer (stocks_app , name = "stocks" )
45
+ stocks_app .add_typer (historical_app , name = "historical" )
46
+ stocks_app .add_typer (snapshot_app , name = "snapshot" )
32
47
app .add_typer (options_app , name = "options" )
33
48
34
49
historical_data = ThetaDataStocksHistorical (enable_logging = True , use_df = True )
50
+ snapshot_data = ThetaDataStocksSnapshot (enable_logging = True , use_df = True )
35
51
36
52
37
53
def save_output (result : pd .DataFrame | dict | None , output_file : Optional [str ]):
@@ -61,7 +77,8 @@ def wrapper(*args, **kwargs):
61
77
return wrapper
62
78
63
79
64
- @stocks_app .command (name = "eod-report" )
80
+ # Historical commands
81
+ @historical_app .command (name = "eod-report" )
65
82
@with_spinner
66
83
def eod_report (
67
84
symbol : str , start_date : str , end_date : str , output_file : Optional [str ] = None
@@ -71,45 +88,45 @@ def eod_report(
71
88
save_output (result , output_file )
72
89
73
90
74
- @stocks_app .command (name = "quotes" )
91
+ @historical_app .command (name = "quotes" )
75
92
@with_spinner
76
- def quotes (
93
+ def historical_quotes (
77
94
symbol : str ,
78
95
start_date : str ,
79
96
end_date : str ,
80
97
interval : str = "900000" ,
81
98
output_file : Optional [str ] = None ,
82
99
):
83
- """Get quotes for a given symbol and date range."""
100
+ """Get historical quotes for a given symbol and date range."""
84
101
result = historical_data .get_quotes (symbol , start_date , end_date , interval )
85
102
save_output (result , output_file )
86
103
87
104
88
- @stocks_app .command (name = "ohlc" )
105
+ @historical_app .command (name = "ohlc" )
89
106
@with_spinner
90
- def ohlc (
107
+ def historical_ohlc (
91
108
symbol : str ,
92
109
start_date : str ,
93
110
end_date : str ,
94
111
interval : str = "900000" ,
95
112
output_file : Optional [str ] = None ,
96
113
):
97
- """Get OHLC data for a given symbol and date range."""
114
+ """Get historical OHLC data for a given symbol and date range."""
98
115
result = historical_data .get_ohlc (symbol , start_date , end_date , interval )
99
116
save_output (result , output_file )
100
117
101
118
102
- @stocks_app .command (name = "trades" )
119
+ @historical_app .command (name = "trades" )
103
120
@with_spinner
104
- def trades (
121
+ def historical_trades (
105
122
symbol : str , start_date : str , end_date : str , output_file : Optional [str ] = None
106
123
):
107
124
"""Get historical trade data for a given symbol and date range."""
108
125
result = historical_data .get_trades (symbol , start_date , end_date )
109
126
save_output (result , output_file )
110
127
111
128
112
- @stocks_app .command (name = "trade-quote" )
129
+ @historical_app .command (name = "trade-quote" )
113
130
@with_spinner
114
131
def trade_quote (
115
132
symbol : str , start_date : str , end_date : str , output_file : Optional [str ] = None
@@ -119,7 +136,7 @@ def trade_quote(
119
136
save_output (result , output_file )
120
137
121
138
122
- @stocks_app .command (name = "splits" )
139
+ @historical_app .command (name = "splits" )
123
140
@with_spinner
124
141
def splits (
125
142
symbol : str , start_date : str , end_date : str , output_file : Optional [str ] = None
@@ -129,7 +146,7 @@ def splits(
129
146
save_output (result , output_file )
130
147
131
148
132
- @stocks_app .command (name = "dividends" )
149
+ @historical_app .command (name = "dividends" )
133
150
@with_spinner
134
151
def dividends (
135
152
symbol : str , start_date : str , end_date : str , output_file : Optional [str ] = None
@@ -139,5 +156,50 @@ def dividends(
139
156
save_output (result , output_file )
140
157
141
158
159
+ # Snapshot commands
160
+ @snapshot_app .command (name = "quotes" )
161
+ @with_spinner
162
+ def snapshot_quotes (
163
+ symbol : str , venue : Optional [str ] = None , output_file : Optional [str ] = None
164
+ ):
165
+ """Get real-time quotes for a given symbol."""
166
+ result = snapshot_data .get_quotes (symbol , venue )
167
+ save_output (result , output_file )
168
+
169
+
170
+ @snapshot_app .command (name = "bulk-quotes" )
171
+ @with_spinner
172
+ def bulk_quotes (
173
+ symbols : List [str ], venue : Optional [str ] = None , output_file : Optional [str ] = None
174
+ ):
175
+ """Get real-time quotes for multiple symbols."""
176
+ result = snapshot_data .get_bulk_quotes (symbols , venue )
177
+ save_output (result , output_file )
178
+
179
+
180
+ @snapshot_app .command (name = "ohlc" )
181
+ @with_spinner
182
+ def snapshot_ohlc (symbol : str , output_file : Optional [str ] = None ):
183
+ """Get real-time OHLC data for a given symbol."""
184
+ result = snapshot_data .get_ohlc (symbol )
185
+ save_output (result , output_file )
186
+
187
+
188
+ @snapshot_app .command (name = "bulk-ohlc" )
189
+ @with_spinner
190
+ def bulk_ohlc (symbols : List [str ], output_file : Optional [str ] = None ):
191
+ """Get real-time OHLC data for multiple symbols."""
192
+ result = snapshot_data .get_bulk_ohlc (symbols )
193
+ save_output (result , output_file )
194
+
195
+
196
+ @snapshot_app .command (name = "trades" )
197
+ @with_spinner
198
+ def snapshot_trades (symbol : str , output_file : Optional [str ] = None ):
199
+ """Get real-time trade data for a given symbol."""
200
+ result = snapshot_data .get_trades (symbol )
201
+ save_output (result , output_file )
202
+
203
+
142
204
if __name__ == "__main__" :
143
205
app ()
0 commit comments