Skip to main content

Tradier REST + Streaming API client

Project description

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)

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(client.account_number, 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)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradier_api_client-0.1.1.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tradier_api_client-0.1.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file tradier_api_client-0.1.1.tar.gz.

File metadata

  • Download URL: tradier_api_client-0.1.1.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for tradier_api_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 718904c4b0b9a62680ebbc87804bfcb06c9cc54b3c5bc1a62b2c32e729616cef
MD5 651d2788ae7af3c23fa475cbd491a97e
BLAKE2b-256 c03b34b43578bb1dbc1f72fe0c4c651ce169427626e61dfe876b1908fe0e6e62

See more details on using hashes here.

File details

Details for the file tradier_api_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tradier_api_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 762422c12b1b81e9021d862dd1c10b25a348a34223734f5140b59f4d860455df
MD5 bbd5168b03b7bbc317f1cd2b14731b84
BLAKE2b-256 835fda81bcf9c7c22b4ea84ce350c5240a2c98151f1542d6ae82b966a4153c12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page