Staging Environment
What is the Staging Environment
The staging environment gives you a separate connection to the ThetaData system, independent from your main production connection.
Why Use the Staging Environment
It allows two real-time data streams to run simultaneously — useful when you need two independent connections at once.
For example:
- One process connects to the production system to receive live market data.
- Another connects to the staging environment (via
mdds_type = "STAGE") to receive a second live stream.
This lets you:
- Compare two real-time streams side by side.
- Run multiple workflows or tools simultaneously without interference.
How to Run Two Connections at Once
Prerequisites: You'll need Java installed and a terminal (Command Prompt on Windows, Terminal on Mac/Linux) to run the commands below.
Step 1: Create two separate configs
Each ThetaTerminal instance needs its own config file. The config tells it which environment to connect to and which port to listen on. A port is just a number that acts like a door — your code uses it to talk to the right instance. Since you're running two instances, each needs a unique port.
Create both files in the same folder as ThetaTerminal3.jar.
Create a file named config-prod.toml:
port = 25503
[env]
mdds_type = "PROD"Create a file named config-staging.toml:
port = 25504
[env]
mdds_type = "STAGE"Step 2: Launch Both Terminals
Open a terminal window and run:
java -jar ThetaTerminal3.jar --config config-prod.tomlOpen a second terminal window and run:
java -jar ThetaTerminal3.jar --config config-staging.tomlNote: The terminal remembers the last-used config as the default for subsequent runs.
Step 3: Use Both Connections Simultaneously
With both instances running, you send requests to port 25503 for production and port 25504 for staging. Here are two examples showing how to do that.
Using curl (terminal in linux):
curl is a command-line tool for making HTTP requests. This example hits both endpoints at once:
curl 'http://127.0.0.1:25503/v3/option/snapshot/ohlc?symbol=SPXW&expiration=*&format=json' \
'http://127.0.0.1:25504/v3/option/snapshot/ohlc?symbol=SPXW&expiration=*&format=json'Using Python:
This example opens a streaming connection to both instances and reads the response line by line. Install the required library first with pip install httpx or, alternatively, on Ubuntu, run sudo apt-get install python3-httpx.
import httpx
import csv
import io
# Point each URL at the correct port for each instance
BASE_URL_PROD = "http://127.0.0.1:25503/v3"
BASE_URL_STAGE = "http://127.0.0.1:25504/v3"
url_prod = BASE_URL_PROD + '/stock/list/symbols'
url_stage = BASE_URL_STAGE + '/stock/list/symbols'
# Open both streams at the same time, then read from each
with httpx.stream("GET", url_prod, timeout=60) as response_prod, \
httpx.stream("GET", url_stage, timeout=60) as response_stage:
response_prod.raise_for_status() # raises an error if the request failed
for line in response_prod.iter_lines():
for row in csv.reader(io.StringIO(line)):
print(row)
response_stage.raise_for_status()
for line in response_stage.iter_lines():
for row in csv.reader(io.StringIO(line)):
print(row)