Skip to main content

tradier_api_client

Python client for the Tradier Brokerage API (REST) plus optional streaming helpers.

This repo is intended to give you a lightweight, script-friendly way to call Tradier endpoints (quotes, options, orders, account data) using a single RestClient.

Note: Some examples below are adapted from tests/real_data.py which is intended for local use with a real API key. Don’t commit keys.


Installation

From source (editable):

python -m pip install -U pip
python -m pip install -e .

Regular install (from the cloned repo):

python -m pip install .

Authentication

Set your Tradier API key in an environment variable.

Windows (cmd.exe)

set API_KEY=your_key_here

macOS/Linux

export API_KEY=your_key_here

Quick start

Create a RestClient

The tests create a client like this:

import os
from tradier_api_client import RestClient

client = RestClient(
    base_url="https://sandbox.tradier.com/v1",  # use https://api.tradier.com/v1 for production
    api_key=os.environ.get("API_KEY"),
    verbose=True,
)

print("Account:", client.account_number)

Common REST examples

1) Quotes

quotes = client.get_quotes(["AAPL", "MSFT"])
print(quotes)

2) Historical quotes

history = client.get_historical_quotes("AAPL", start="1979-01-01")
print(history)

3) Option expirations + option chains

expirations_resp = client.get_option_expirations("AAPL")
expirations = expirations_resp.get("expirations", {}).get("date", [])
print(expirations)

if expirations:
    chain = client.get_option_chains("AAPL", expirations[0])
    print(chain)

4) Options helper workflow (OCC symbols)

The repo includes an OptionsWrapper and helper utilities used by tests/real_data.py.

from tradier_api_client.rest.extensions.options import (
    OptionsWrapper,
    parse_occ,
    filter_options_occ,
    filter_for_tradable_options_strike_plus_bid,
)

ow = OptionsWrapper(client)
occ_symbols = ow.get_call_options_occ_symbols_list("AAPL")

# Parse OCC symbols into structured info
parsed = parse_occ(occ_symbols)

# Filter by expiration window and strike constraints (example)
filtered_occ = filter_options_occ(options=occ_symbols, exp_end="2027-08-30", exp_start="2027-01-01")

# Quote options and filter for tradable candidates
quotes = client.get_quotes(filtered_occ)
tradable = filter_for_tradable_options_strike_plus_bid(
    quotes=quotes,
    occ_symbols=filtered_occ,
    target_price=5.5,
)
print(tradable)

5) Account endpoints (example: gain/loss)

gain_loss = client.get_gain_loss(client.account_number)
print(gain_loss)

6) Watchlists

# List all watchlists
watchlists = client.get_watchlists()
print(watchlists)

# Create a watchlist
created = client.create_watchlist("Tech Leaders", symbols=["AAPL", "MSFT", "NVDA"])
print(created)

# Get one watchlist
watchlist = client.get_watchlist("tech-leaders")
print(watchlist)

# Replace the watchlist contents
updated = client.update_watchlist("tech-leaders", "Tech Leaders", symbols=["AAPL", "MSFT", "META"])
print(updated)

# Add symbols
added = client.add_symbols_to_watchlist("tech-leaders", ["AMD", "AVGO"])
print(added)

# Remove one symbol
removed = client.remove_symbol_from_watchlist("tech-leaders", "META")
print(removed)

# Delete the watchlist
deleted = client.delete_watchlist("tech-leaders")
print(deleted)

Orders

The order helpers live under tradier_api_client.rest.extensions.orders.

Equity limit buy (example)

from tradier_api_client.rest.extensions.orders import equity_limit

order_request = equity_limit(
    symbol="AAPL",
    side="buy",
    quantity=1,
    price=150,
    duration="gtc",
)

resp = client.place_order(order_request)
print(resp)

Read / cancel orders

orders = client.get_orders(client.account_number)
print(orders)

# If you have an order id:
# order = client.get_order(client.account_number, "12345678")
# print(order)

# cancel_resp = client.cancel_order(client.account_number, "12345678")
# print(cancel_resp)


Streaming (optional)

If you want real-time market data, use StreamingClient (websocket streaming). This is optional; the REST client works without it.

The StreamingClient constructor takes in the main API key that you also use REST calls. Additional API keys and account numbers are meant for advanced and serious trading.

The StreamingClient instance for market data streaming takes a list of symbols and event types in the start_listening call.

Authentication

StreamingClient uses the same API_KEY environment variable shown above.

Basic example: connect and print events

import os
import time



from tradier_api_client import RestClient
from tradier_api_client.streaming import StreamingClient  # adjust if your module path differs

def on_message(msg: dict) -> None:
    # msg is the decoded JSON payload from the websocket
    print(msg)

client = StreamingClient(main_api_key=os.environ.get("API_KEY"),
                         base_url="https://sandbox.tradier.com/v1",
                         stream_base_url="wss://sandbox-ws.tradier.com/v1",
                         main_account_id=os.environ.get("ACCOUNT_ID"),
                         events_callback=on_message, stream_type="account")
client.start_listening()
time.sleep(60)  # listen for 60 seconds
client.stop()

Running tests (local repo)

This project includes tests/integration scripts under tests/.

  • Some scripts (like tests/real_data.py) may call live/sandbox endpoints and require API_KEY.
  • The tests/ folder is not intended to be installed with the client distribution.

To run tests locally:

python -m pip install -U pytest
pytest -q

Notes / troubleshooting

  • Sandbox vs production: use https://sandbox.tradier.com/v1 for paper testing and https://api.tradier.com/v1 for production.
  • If you see authentication errors, confirm API_KEY is set in the environment used by your Python interpreter.

Metadata

Release files for tradier-api-client 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tradier-api-client 0.10.0
File Size Uploaded Provenance Actions
tradier_api_client-0.10.0.tar.gz 41.8 kB Without provenance Details for tradier_api_client-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tradier-api-client 0.10.0
File Interpreter ABI Platform Actions
tradier_api_client-0.10.0-py3-none-any.whl Python 3 none any Details for tradier_api_client-0.10.0-py3-none-any.whl

Total release size: 85.7 kB

Release files / tradier_api_client-0.10.0.tar.gz

Download URL tradier_api_client-0.10.0.tar.gz
Size 41.8 kB
Tags Source
SHA-256 checksum
How to use checksums
df86f5c43609458c60e954579d8a044489eda919fb5b95ab6db894ee20252238
BLAKE2b-256 checksum
How to use checksums
ed343383d85c2b49268d830e75aeb27a988d39708e7418791a6088897ce716de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / tradier_api_client-0.10.0-py3-none-any.whl

Download URL tradier_api_client-0.10.0-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15c13e9e40331905b1ed29f83ee04ecca14c717bc4ec45b3743a735eaa17a8f0
BLAKE2b-256 checksum
How to use checksums
1b9d216c5a123bcce375d410ad291699fcc303314da1f0dc0e0e25663c7e52c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for tradier-api-client 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page