Guide
How to Connect to the TradeZero API with Python
Set up TradeZero API keys in Python, select the correct account, inspect positions and routes, and check access to Alphanume's pre-market dataset.
The first useful test is simple: can Python read the account you intended to use? Do that before writing any order code. This guide connects the downloadable starter to TradeZero and checks the Alphanume data that will drive its candidate list.
Download the Python starter, Windows wrapper, and offline tests. Extract it before running commands. The ZIP includes setup instructions and the complete source.
This example requires an Alphanume API key with access to Pre-Market Drop Risk. TradeZero handles the account and execution; Alphanume supplies the ranked candidates. TradeZero's API can use other data, but this starter is built around Alphanume. See dataset access and plans.
1. Get the right keys
Follow TradeZero's authentication instructions to enable API Trading and create credentials for the intended environment. The request headers are TZ-API-KEY-ID and TZ-API-SECRET-KEY. Paper and live use the same host; the key pair determines the environment.
In the Windows user environment variable editor, save TZ_API_KEY_ID, TZ_API_SECRET_KEY and ALPHANUME_API_KEY. The exit guide also needs MASSIVE_API_KEY. Open a new terminal after saving them. The starter reads environment variables directly; placing keys in an .env file alone will not configure it.
Keep the variable names in your instructions, but keep their values out of source files, screenshots and AI prompts. This also keeps the scheduled command readable: it can name a script without embedding credentials.
2. Install Python dependencies
Use Python 3.11 or newer. Extract the ZIP into a permanent folder. From PowerShell in that folder:
py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
.\.venv\Scripts\python.exe -m unittest discover -s tests -v
A virtual environment is a folder containing the Python packages for this project. Calling its Python executable directly avoids mixing these packages with another project. The included tests use fictional responses and never contact a brokerage.
3. Read the account, positions and routes
Save this as check_connection.py beside client.py, then run it with the virtual environment's Python. These methods all use GET requests, which read information.
from client import TradeZero
tz = TradeZero()
account = tz.connect(expected="Paper")
print("Account type:", account["accountType"])
print("Position count:", len(tz.positions()))
for route in tz.routes():
print(route["routeName"], route["orderTypes"], route["timesInForce"])
The helper first requests GET /v1/api/accounts. It selects a single account, or the one matching TZ_ACCOUNT_ID if you set that variable. It then reads /positions and /routes under the selected account path. A route is the destination used to handle an order.
The account reference identifies account as the API account identifier and accountType as the environment indicator. Do not substitute a portal username. The starter treats Paper as paper and requires an explicit Live expectation for other reported account types.
4. Confirm Alphanume access
.\.venv\Scripts\python.exe starter.py check
This combines the brokerage reads with a request for today's top-five Alphanume ranks. A signal count of zero can be valid before publication or on a day without matching rows. An authorization error is different: check the key and its dataset entitlement.
For read-only checks using live credentials, append --expect Live. That changes which environment the program expects; it does not enable orders. Order writes require --submit, and new paid locates require a second flag.
If the first request fails
- Missing variable: save the user variable and open a fresh terminal under that same user.
- Environment mismatch: check the key pair and intended environment. Do not change the expected environment just to silence an error.
- Several accounts: inspect your account list privately and set
TZ_ACCOUNT_ID. - HTTP error: verify API access, credentials and account identity. The starter deliberately omits headers and raw account paths from its error output.
Common questions
Does check place a test trade?
No. It reads the account, routes, positions and Alphanume signal rows. It does not submit or cancel orders, quote locates or accept fees.
Can paper test everything?
No. Paper can help test the order lifecycle, but it does not supply real locate inventory or establish live opening-auction behavior.
Do I need Massive just to connect?
No. The connection and entry preview use TradeZero and Alphanume. Massive credentials and fresh quotes are needed for the demonstrated exit workflow.
Next: learn the locate lifecycle, or return to the series overview.
API documentation checked September 27, 2026. Route availability and account access can change. Examples describe the included starter; they do not establish trading performance.