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

Commit 7939721

Browse files
committed
Docs improvements
1 parent ccc21e6 commit 7939721

File tree

7 files changed

+110
-15
lines changed

7 files changed

+110
-15
lines changed

docs/connection_msgs.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ def streaming():
1313

1414
# User generated method that gets called each time a message from the stream arrives.
1515
def callback(msg: StreamMsg):
16-
if msg.type == StreamMsgType.DISCONNECTED or msg.type == StreamMsgType.RECONNECTED:
17-
print(msg.type.__str__()) # Handle disconnect / reconnect.
16+
if msg.type == StreamMsgType.DISCONNECTED:
17+
print('Lost connection to Theta Data servers')
18+
if msg.type == StreamMsgType.STREAM_DEAD:
19+
print('Lost connection to Theta Terminal, which is likely due the terminal being forcibly closed')
20+
if msg.type == StreamMsgType.RECONNECTED:
21+
print('The terminal has reconnected to Theta Data. You need to resubscribe to all streams.')
1822

1923

2024
if __name__ == "__main__":

docs/options/quote_streaming.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from datetime import date
2+
3+
from thetadata import ThetaClient, OptionRight, StreamMsg, StreamMsgType, StreamResponseType
4+
5+
6+
def streaming():
7+
# Credentials now required because streaming is only available to ThetaData Standard & Pro subscribers.
8+
client = ThetaClient(username="MyThetaDataEmail", passwd="MyThetaDataPassword")
9+
10+
client.connect_stream(callback) # You can stop streaming by calling client.close_stream
11+
# This contract is likely expired! Replace it with a contract that isn't expired
12+
req_id = client.req_quote_stream_opt("AAPL", date(2023, 7, 21), 170, OptionRight.CALL)
13+
14+
# Verify that the request to stream was successful.
15+
response = client.verify(req_id)
16+
if response == StreamResponseType.SUBSCRIBED:
17+
print('The request to stream option quotes was successful.')
18+
elif response == StreamResponseType.INVALID_PERMS:
19+
print('Invalid permissions to stream option quotes. Theta Data Options Standard or Pro account required.')
20+
elif response == StreamResponseType.MAX_STREAMS_REACHED:
21+
print('You have reached your limit for the amount of option contracts you can stream quotes for.')
22+
else:
23+
print('Unexpected stream response: ' + str(response))
24+
25+
26+
# User generated method that gets called each time a message from the stream arrives.
27+
def callback(msg: StreamMsg):
28+
msg.type = msg.type
29+
30+
if msg.type == StreamMsgType.QUOTE:
31+
print('---------------------------------------------------------------------------')
32+
print('con: ' + msg.contract.to_string())
33+
print('quote: ' + msg.quote.to_string())
34+
35+
36+
if __name__ == "__main__":
37+
streaming()

docs/options/trade_streaming.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
from datetime import date
22

3-
from thetadata import ThetaClient, OptionRight, StreamMsg, StreamMsgType
3+
from thetadata import ThetaClient, OptionRight, StreamMsg, StreamMsgType, StreamResponseType
44

55

66
def streaming():
7-
# Credentials now required because get_last is only available to ThetaData Standard & Pro subscribers.
7+
# Credentials now required because streaming is only available to ThetaData Standard & Pro subscribers.
88
client = ThetaClient(username="MyThetaDataEmail", passwd="MyThetaDataPassword")
99

1010
client.connect_stream(callback) # You can stop streaming by calling client.close_stream
1111
# This contract is likely expired! Replace it with a contract that isn't expired
12-
client.req_trade_stream_opt("NVDA", date(2023, 1, 13), 150, OptionRight.CALL)
12+
req_id = client.req_trade_stream_opt("NVDA", date(2023, 1, 13), 150, OptionRight.CALL)
13+
14+
# Verify that the request to stream was successful.
15+
response = client.verify(req_id)
16+
if response == StreamResponseType.SUBSCRIBED:
17+
print('The request to stream option trades was successful.')
18+
elif response == StreamResponseType.INVALID_PERMS:
19+
print('Invalid permissions to stream option trades. Theta Data Options Standard or Pro account required.')
20+
elif response == StreamResponseType.MAX_STREAMS_REACHED:
21+
print('You have reached your limit for the amount of option contracts you can stream trades for.')
22+
else:
23+
print('Unexpected stream response: ' + str(response))
1324

1425

1526
# User generated method that gets called each time a message from the stream arrives.

docs/options/trade_streaming_full.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
from thetadata import ThetaClient, StreamMsg, StreamMsgType
1+
from thetadata import ThetaClient, StreamMsg, StreamMsgType, StreamResponseType
22

33

44
def streaming():
5-
# Credentials now required because get_last is only available to ThetaData Standard & Pro subscribers.
5+
# Credentials now required because streaming is only available to ThetaData Standard & Pro subscribers.
66
client = ThetaClient(username="MyThetaDataEmail", passwd="MyThetaDataPassword")
77

88
client.connect_stream(callback) # You can stop streaming by calling client.close_stream
9-
client.req_full_trade_stream_opt() # requests every option trade
9+
req_id = client.req_full_trade_stream_opt() # Requests every option trade (async).
10+
11+
# Verify that the request to stream was successful.
12+
response = client.verify(req_id)
13+
if response == StreamResponseType.SUBSCRIBED:
14+
print('Request to stream full trades successful.')
15+
elif response == StreamResponseType.INVALID_PERMS:
16+
print('Invalid permissions to stream full trades. Theta Data Options Pro account required.')
17+
else:
18+
print('Unexpected stream response: ' + str(response))
1019

1120

1221
# User generated method that gets called each time a message from the stream arrives.

docs/tutorials.md

+38-4
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,42 @@ can be used to determine the purpose of the message.
253253

254254
#### Limitations
255255

256-
The Pro tier has the ability to request a trade stream for every option contract in
257-
existence and is able to have up to 15K quote streams. The Standard tier is only allowed
258-
5K quote streams and 10K trade streams. Other tiers do not have access to streaming at this time.
256+
The Pro tier has the ability to request a trade stream for every option contract in existence and is able to
257+
request up to 20K quote streams. The Standard tier can request 10K quote streams and 20K trade streams.
258+
Other tiers do not have access to streaming at this time.
259+
260+
### Option Quotes
261+
262+
Below requests to receive continuous updates for quote for an AAPL option contract. Notice
263+
that these options are probably expired, so you may need to change the expiration date.
264+
265+
=== "trade_streaming.py"
266+
267+
```python
268+
--8<-- "docs/options/quote_streaming.py"
269+
```
270+
271+
=== "Output"
272+
273+
```bash
274+
> python trade_streaming.py
275+
---------------------------------------------------------------------------
276+
con: root: AAPL isOption: True exp: 2023-07-21 strike: 170.0 isCall: True
277+
quote: ms_of_day: 57061764 bid_size: 202 bid_exchange: EDGX bid_price: 6.35 bid_condition: NATIONAL_BBO ask_size: 742 ask_exchange: C2OX ask_price: 6.45 ask_condition: NATIONAL_BBO date: 2023-04-21
278+
---------------------------------------------------------------------------
279+
con: root: AAPL isOption: True exp: 2023-07-21 strike: 170.0 isCall: True
280+
quote: ms_of_day: 57061816 bid_size: 202 bid_exchange: EDGX bid_price: 6.35 bid_condition: NATIONAL_BBO ask_size: 742 ask_exchange: C2OX ask_price: 6.45 ask_condition: NATIONAL_BBO date: 2023-04-21
281+
---------------------------------------------------------------------------
282+
con: root: AAPL isOption: True exp: 2023-07-21 strike: 170.0 isCall: True
283+
quote: ms_of_day: 57061974 bid_size: 202 bid_exchange: EDGX bid_price: 6.35 bid_condition: NATIONAL_BBO ask_size: 742 ask_exchange: C2OX ask_price: 6.45 ask_condition: NATIONAL_BBO date: 2023-04-21
284+
---------------------------------------------------------------------------
285+
con: root: AAPL isOption: True exp: 2023-07-21 strike: 170.0 isCall: True
286+
quote: ms_of_day: 57061974 bid_size: 254 bid_exchange: C2OX bid_price: 6.35 bid_condition: NATIONAL_BBO ask_size: 742 ask_exchange: C2OX ask_price: 6.45 ask_condition: NATIONAL_BBO date: 2023-04-21
287+
---------------------------------------------------------------------------
288+
con: root: AAPL isOption: True exp: 2023-07-21 strike: 170.0 isCall: True
289+
quote: ms_of_day: 57062025 bid_size: 322 bid_exchange: C2OX bid_price: 6.35 bid_condition: NATIONAL_BBO ask_size: 742 ask_exchange: C2OX ask_price: 6.45 ask_condition: NATIONAL_BBO date: 2023-04-21
290+
---------------------------------------------------------------------------
291+
```
259292

260293
### Option Trades
261294

@@ -328,7 +361,8 @@ available to PRO subscribers.
328361
### Every Open Interest
329362

330363
Below requests to receive continuous updates for every option open interest. This method is only
331-
available to PRO subscribers.
364+
available to PRO subscribers. Open Interest is generally reported at 06:30 ET. It is generally not updated during
365+
the trading day.
332366

333367
=== "open_interest_streaming.py"
334368

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "thetadata"
7-
version = "0.9.5"
7+
version = "0.9.6"
88
authors = [
99
{ name="Bailey Danseglio", email="[email protected]" },
1010
{ name="Adler Weber", email="[email protected]" },
1111
]
1212
description = "Python API for Thetadata"
1313
readme = "README.md"
1414
license = { file="LICENSE" }
15-
requires-python = ">=3.9"
15+
requires-python = ">=3.7"
1616
classifiers = [
1717
"Programming Language :: Python :: 3",
1818
"License :: OSI Approved :: MIT License",

thetadata/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .terminal import check_download, launch_terminal
2828

2929
_NOT_CONNECTED_MSG = "You must establish a connection first."
30-
_VERSION = '0.9.5'
30+
_VERSION = '0.9.6'
3131
URL_BASE = "http://127.0.0.1:25510/"
3232

3333

0 commit comments

Comments
 (0)