REQUIRED
A Theta Data Options Standard Subscription is required to use this endpoint. Theta Terminal version 202605141 or later is required.
Market Value Stream
Behavior
This stream provides a calculated theoretical market value for a specified option contract. This value is derived from the real-time bid and ask prices of the option. The Theta Terminal will continue to send these messages unless it is terminated or you unsubscribe from the stream.
Subscribe to Market Value Stream
The id field should be increased for each new stream request made. This ID is returned in a later message to verify that the request to stream was successful. Failure to increment the ID for each request will prevent the terminal from automatically resubscribing to streams you previously requested.
Contract Parameter
The contract in the payload example below is the $4800 SPXW Call option expiring on 2024-03-15. Strike prices are formatted in 10th of a cent. This means the $4800 strike price is represented as 4800000 as seen below.
Payload
{
"msg_type": "STREAM",
"sec_type": "OPTION",
"req_type": "MARKET_VALUE",
"add": true,
"id": 0,
"contract": {
"root": "SPXW",
"expiration": 20240315,
"strike": 4800000,
"right": "C"
}
}Sample Code
REQUIRED
The Theta Terminal must be running for this code to work.
import asyncio
import websockets
import json
# This code has only been tested on Python 3.11. Other versions might require adjustments.
async def stream_market_value():
async with websockets.connect('ws://127.0.0.1:25520/v1/events') as websocket:
req = {
"msg_type": "STREAM",
"sec_type": "OPTION",
"req_type": "MARKET_VALUE",
"add": True,
"id": 0,
"contract": {
"root": "SPXW",
"expiration": 20240315,
"strike": 4800000,
"right": "C"
}
}
await websocket.send(json.dumps(req))
while True:
response = await websocket.recv()
print(response)
asyncio.get_event_loop().run_until_complete(stream_market_value())Unsubscribe from the Market Value Stream
Changing the add field in the payload from true to false will end the stream subscription.
{
"msg_type": "STREAM",
"sec_type": "OPTION",
"req_type": "MARKET_VALUE",
"add": false,
"id": 1,
"contract": {
"root": "SPXW",
"expiration": 20240315,
"strike": 4800000,
"right": "C"
}
}Sample output
- The
rightfield in thecontractobject will be set toCfor a call andPfor a put. - The strike price is in 1/10th of a cent. This means that a $4800 strike price is represented as
4800000.
{
"header": {
"type": "MARKET_VALUE",
"status": "CONNECTED"
},
"contract": {
"security_type": "OPTION",
"root": "SPXW",
"expiration": 20240315,
"strike": 4800000,
"right": "C"
},
"market_value": {
"ms_of_day": 26622025,
"date": 20231219,
"market_bid": 110.19,
"market_ask": 110.51,
"market_price": 110.35
}
}