Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit 297fb3d

Browse files
committed
at_time fix
1 parent 9e1d2a9 commit 297fb3d

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

docs/end_of_day.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44

55

66
def end_of_day() -> pd.DataFrame:
7-
"""Request end-of-day data between 7/18/2022 and 7/22/2022."""
8-
# Create a ThetaClient
9-
client = ThetaClient()
107

11-
# Connect to the Terminal
12-
with client.connect():
8+
client = ThetaClient() # No credentials required for free access
139

10+
with client.connect(): # Make any requests for data inside this block. Requests made outside this block won't run.
1411
# Make the request
1512
data = client.get_hist_option(
1613
req=OptionReqType.EOD,
1714
root="AAPL",
18-
exp=date(2022, 8, 12),
19-
strike=140,
15+
exp=date(2022, 11, 25),
16+
strike=150,
2017
right=OptionRight.CALL,
21-
date_range=DateRange(date(2022, 7, 18), date(2022, 7, 22)),
18+
date_range=DateRange(date(2022, 10, 15), date(2022, 11, 15))
2219
)
23-
24-
return data
20+
# We are out of the client.connect() block, so we can no longer make requests.
21+
print(data)
2522

2623

2724
if __name__ == "__main__":

thetadata/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def get_opt_at_time(
258258

259259
def get_stk_at_time(
260260
self,
261-
req: OptionReqType,
261+
req: StockReqType,
262262
root: str,
263263
date_range: DateRange,
264264
ms_of_day: int = 0,
@@ -280,7 +280,7 @@ def get_stk_at_time(
280280
end_fmt = _format_date(date_range.end)
281281

282282
# send request
283-
hist_msg = f"MSG_CODE={MessageType.AT_TIME.value}&START_DATE={start_fmt}&END_DATE={end_fmt}&root={root}&sec={SecType.OPTION.value}&req={req.value}&IVL={ms_of_day}\n"
283+
hist_msg = f"MSG_CODE={MessageType.AT_TIME.value}&START_DATE={start_fmt}&END_DATE={end_fmt}&root={root}&sec={SecType.STOCK.value}&req={req.value}&IVL={ms_of_day}\n"
284284
self._server.sendall(hist_msg.encode("utf-8"))
285285

286286
# parse response header

0 commit comments

Comments
 (0)