Skip to content

A Thetadata Options Standard Subscription is required to use this endpoint.

Quote Stream

Behavior

This stream returns every US Option NBBO quote reported on the OPRA feed for the specified contract. The Theta Terminal will continue to receive these messages unless it is terminated or you unsubscribe from the full trade stream.

Subscribe to Trade 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 trades was successful. This ID does not have any representation of contracts or unqiue streams. It only represents a way of tracking streaming requests made. 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 10ths of a cent. This means the $4800 strike price is represented as 4800000 as seen below.

Payload

json
{
    "msg_type": "STREAM",
    "sec_type": "OPTION",
    "req_type": "QUOTE",
    "add": true,
    "id": 0,
    "contract": {
        "root": "SPXW",
        "expiration": 20240315,
        "strike": 4800000,
        "right": "C"
    }
}

Sample Code

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

Python
import asyncio
import websockets

# This code has only been tested on Python 3.11. Other versions might require adjustments.
async def stream_trades():
    async with websockets.connect('ws://127.0.0.1:25520/v1/events') as websocket:
        req = {}
        req['msg_type'] = 'STREAM'
        req['sec_type'] = 'OPTION'
        req['req_type'] = 'QUOTE'
        req['add'] = True
        req['id'] = 0
        req['contract'] = {}
        req['contract']['root'] = "SPXW"
        req['contract']['expiration'] = "20240315"
        req['contract']['strike'] = "4800000"
        req['contract']['right'] = "C"
        await websocket.send(req.__str__())
        while True:
            response = await websocket.recv()
            print(response)


asyncio.get_event_loop().run_until_complete(stream_trades())
Java
COMING SOON! Want to contribute sample 
code for your programming language? Reach out to support.
Cpp
COMING SOON! Want to contribute sample 
code for your programming language? Reach out to support.
JavaScript
COMING SOON! Want to contribute sample 
code for your programming language? Reach out to support.
Go
COMING SOON! Want to contribute sample 
code for your programming language? Reach out to support.

Unsubscribe from the Quote Stream

Changing the add field in the payload from true to false will end the quote stream subscription.

json
{
    "msg_type": "STREAM",
    "sec_type": "OPTION",
    "req_type": "QUOTE",
    "add": false,
    "id": 1,
    "contract": {
        "root": "SPXW",
        "expiration": 20240315,
        "strike": 4800000,
        "right": "C"
    }
}

Sample output

  • The right field in the contract object will be set to C for a call and P for a put.

  • The condition and exchange values correspond to their respective Enums.

  • The strike price is in 1/10ths of a cent. This means that a $140 strike price is represented as 140000.

json
{
    "header": {
        "status": "CONNECTED",
        "type": "QUOTE"
    },
    "contract": {
        "security_type": "OPTION",
        "root": "SPXW",
        "expiration": 20240315,
        "strike": 4800000,
        "right": "C"
    },
    "quote": {
        "ms_of_day": 26622025,
        "bid_size": 7,
        "bid_exchange": 5,
        "bid": 110.20,
        "bid_condition": 50,
        "ask_size": 7,
        "ask_exchange": 5,
        "ask": 110.50,
        "ask_condition": 50,
        "date": 20231219
    }
}