Skip to content

REQUIRED

A Theta Data Index Standard Subscription is required to use this endpoint. Theta Terminal version 202605141 or later is required.

Market Value Stream

Behavior

This stream provides the real-time calculated market value for a specified index. The Theta Terminal will continue to send these messages unless it is terminated or you unsubscribe from the stream.

NOTE

Unlike the stock and option market value streams, the index stream only provides the market_price and does not include market_bid or market_ask fields.

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 for the SPX index.

Payload

json
{
  "msg_type": "STREAM",
  "sec_type": "INDEX",
  "req_type": "MARKET_VALUE",
  "add": true,
  "id": 0,
  "contract": {
    "root": "SPX"
  }
}

Sample Code

REQUIRED

The Theta Terminal must be running for this code to work.

Python
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": "INDEX",
            "req_type": "MARKET_VALUE",
            "add": True,
            "id": 0,
            "contract": {
                "root": "SPX"
            }
        }
        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.

json
{
  "msg_type": "STREAM",
  "sec_type": "INDEX",
  "req_type": "MARKET_VALUE",
  "add": false,
  "id": 1,
  "contract": {
    "root": "SPX"
  }
}

Sample output

json
{
  "header": {
    "type": "MARKET_VALUE",
    "status": "CONNECTED"
  },
  "contract": {
    "security_type": "INDEX",
    "root": "SPX"
  },
  "market_value": {
    "ms_of_day": 51952000,
    "date": 20240809,
    "market_price": 5333.39
  }
}