REQUIRED
A Theta Data Stock 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 stock symbol. This value is derived from the real-time bid and ask prices. 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 subscribing to the market value stream for AAPL stock.
Payload
{
"msg_type": "STREAM",
"sec_type": "STOCK",
"req_type": "MARKET_VALUE",
"add": true,
"id": 0,
"contract": {
"root": "AAPL"
}
}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": "STOCK",
"req_type": "MARKET_VALUE",
"add": True,
"id": 0,
"contract": {
"root": "AAPL"
}
}
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": "STOCK",
"req_type": "MARKET_VALUE",
"add": false,
"id": 1,
"contract": {
"root": "AAPL"
}
}Sample output
{
"header": {
"type": "MARKET_VALUE",
"status": "CONNECTED"
},
"contract": {
"security_type": "STOCK",
"root": "AAPL"
},
"market_value": {
"ms_of_day": 38437457,
"date": 20240503,
"market_bid": 184.49,
"market_ask": 184.51,
"market_price": 184.50
}
}