Setup
The Theta Terminal is required to use Thetadata's WebSockets. The Theta Terminal uses a highly compressed protocol to ensure minimal bandwidth consumption and low latency data transmission. Please follow the getting started article to get the Theta Terminal running.
A Thetadata subscription is required to access data. Streaming requests won't return any data if you do not have permissions to stream the data.
Prerequisites
- Familiarity with Websockets in the programming language of your choice. Sample code for some language may be provided.
- Requests and event messages are in JSON. The ability to parse that data is required.
- The Theta Terminal must be running.
Dev FPSS for Development
While you're developing, it is possible that the market may be closed. This means that there aren't any new trades or quotes are generated by the exchanges. You will not be able to test streaming effectively unless the market is open or you are using our dev server. We recommend switching to our dev environment for development since there are always messages being sent to the Theta Terminal. The dev server does an infinite loop replay of a single day of data. The replaying of the data is done as fast as possible, meaning there are more messages per second being sent to the Theta Terminal than there would be by streaming on the production server.
The dev FPSS server replays data from a random trading day in the past. Some contracts might be expired or not exist yet that you attempt to stream.
Switch to Dev FPSS
Set the following value in your config file:
Dev
FPSS_REGION=FPSS_DEV_HOSTS
Production
FPSS_REGION=FPSS_NJ_HOSTS
Theta Terminal v1.6.0 or higher is required to access the development server.
Mechanics
Theta Terminal connects to FPSS to receive streamable messages. All stream messages will be sent to the endpoint below:
ws://127.0.0.1:25520/v1/events
You must also connect to this same endpoint to send streaming requests. You cannot have multiple connections to this endpoint. There should be a single connection to this endpoint in which you receive all messages send by Theta Data. It is up to the user to distribute these messages to other threads or processes. There are plans to add terminal-side splitting of messages over different endpoints in the near future.
Stream Messages
Header
Each message received will contain a header object that describes the type of message and the the connectivity status of the Theta Terminal to FPSS.
{
"header": {
"status": "CONNECTED",
"type": "QUOTE",
...
Status Messages
A status messages is sent over the connection every second to keep the connection alive.
{
"header": {
"status": "CONNECTED",
"type": "STATUS"
}
}
Contract
Stream messages that are of type QUOTE
and TRADE
will contain a contract object. For options, the strike price is in 1/10ths of a cent. This means that a $140 strike price is represented as 140000
.
{
"header": {
"status": "CONNECTED",
"type": "QUOTE"
},
"contract": {
"security_type": "OPTION",
"root": "TTWO",
"expiration": 20231103,
"strike": 140000,
"right": "C"
},
...