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

Commit b476a9d

Browse files
Merge pull request #1 from ThetaData-API/3.1
3.1
2 parents bc757ea + 4dbc64a commit b476a9d

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

dev/test.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pandas as pd
2+
from datetime import date
3+
from thetadata import ThetaClient, OptionReqType, OptionRight, DateRange
4+
5+
6+
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(timeout=180)
10+
11+
# Connect to the Terminal
12+
with client.connect():
13+
14+
# Make the request
15+
data = client.get_hist_option(
16+
req=OptionReqType.EOD,
17+
root="AAPL",
18+
exp=date(2022, 8, 12),
19+
strike=160,
20+
right=OptionRight.CALL,
21+
date_range=DateRange(date(2022, 8, 3), date(2022, 8, 3)),
22+
progress_bar=True,
23+
)
24+
25+
return data
26+
27+
28+
if __name__ == "__main__":
29+
data = end_of_day()
30+
print(data)

thetadata/client.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Module that contains Theta Client class."""
2-
from typing import Optional, Callable
2+
from typing import Optional
33
from contextlib import contextmanager
4-
from functools import wraps
5-
from datetime import datetime, date
4+
65
import socket
6+
7+
from pandas import DataFrame
78
from tqdm import tqdm
89
import pandas as pd
910

10-
from . import exceptions
1111
from .enums import *
1212
from .parsing import (
1313
Header,
@@ -101,6 +101,7 @@ def get_hist_option(
101101
strike: float,
102102
right: OptionRight,
103103
date_range: DateRange,
104+
interval_size: int = 0,
104105
progress_bar: bool = False,
105106
) -> pd.DataFrame:
106107
"""
@@ -112,6 +113,7 @@ def get_hist_option(
112113
:param strike: The strike price in USD, rounded to 1/10th of a cent.
113114
:param right: The right of an option.
114115
:param date_range: The dates to fetch.
116+
:param interval_size: The interval size in milliseconds. Applicable only to OHLC & QUOTE requests.
115117
:param progress_bar: Print a progress bar displaying download progress.
116118
117119
:return: The requested data as a pandas DataFrame.
@@ -125,7 +127,7 @@ def get_hist_option(
125127
end_fmt = _format_date(date_range.end)
126128

127129
# send request
128-
hist_msg = f"MSG_CODE={MessageType.HIST.value}&START_DATE={start_fmt}&END_DATE={end_fmt}&root={root}&exp={exp_fmt}&strike={strike}&right={right.value}&sec={SecType.OPTION.value}&req={req.value}\n"
130+
hist_msg = f"MSG_CODE={MessageType.HIST.value}&START_DATE={start_fmt}&END_DATE={end_fmt}&root={root}&exp={exp_fmt}&strike={strike}&right={right.value}&sec={SecType.OPTION.value}&req={req.value}&IVL={interval_size}\n"
129131
self._server.sendall(hist_msg.encode("utf-8"))
130132

131133
# parse response header

thetadata/parsing.py

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def _post_process(cls, df: DataFrame) -> None:
208208

209209
if DataType.PRICE_TYPE in df.columns:
210210
# replace price type column with price multipliers
211+
211212
df[DataType.PRICE_TYPE] = _to_price_mul(df[DataType.PRICE_TYPE])
212213

213214
# multiply prices by price multipliers

0 commit comments

Comments
 (0)