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

Commit 89bf521

Browse files
Merge pull request #6 from ThetaData-API/3.1
Added get_req method. Allows to send a raw request to the terminal. D…
2 parents 30d1b85 + fc8d289 commit 89bf521

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

dev/dev.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,23 @@ def strikes_crash() -> pd.DataFrame:
5050

5151
def crash() -> pd.DataFrame:
5252
# Create a ThetaClient
53-
client = ThetaClient(username="my_theta_data_email", passwd="my_thetadata_passwd")
53+
client = ThetaClient()
5454

5555
# Connect to the Terminal
5656
with client.connect():
57-
# Make the request
58-
data = client.get_hist_option(
59-
req=OptionReqType.QUOTE,
60-
root="AAPL",
61-
exp=date(2022, 7, 15),
62-
strike=150,
63-
right=OptionRight.CALL,
64-
date_range=DateRange(date(2022, 7, 1), date(2022, 7, 7)),
65-
progress_bar=False,
66-
)
57+
with open("raw.txt") as f:
58+
# Make the request
59+
s = f.readline()
60+
count = 0
6761

62+
while s is not None:
63+
try:
64+
if count == 109:
65+
data = client.get_req(s)
66+
except thetadata.NoData:
67+
x = 0
68+
count += 1
69+
s = f.readline()
6870
return data
6971

7072

thetadata/client.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, port: int = 11000, timeout: Optional[float] = 60,
5959
Thread(target=launch_terminal, args=[username, passwd]).start()
6060
else:
6161
warnings.warn("You must specify a username and passwd to access data!"
62-
" If you have a terminal already running, you can ignore this message")
62+
" If you have a terminal already running, you can ignore this message.")
6363

6464
@contextmanager
6565
def connect(self):
@@ -247,3 +247,22 @@ def get_last_option(
247247
)
248248

249249
return body
250+
251+
def get_req(
252+
self,
253+
req: str,
254+
) -> pd.DataFrame:
255+
assert self._server is not None, _NOT_CONNECTED_MSG
256+
# send request
257+
print(req)
258+
self._server.sendall(req.encode("utf-8"))
259+
260+
# parse response header
261+
header_data = self._server.recv(20)
262+
header: Header = Header.parse(req, header_data)
263+
264+
# parse response body
265+
body_data = self._recv(header.size, progress_bar=False)
266+
body: DataFrame = TickBody.parse(req, header, body_data)
267+
return body
268+

0 commit comments

Comments
 (0)