Fully Thread-Safe · Streaming Ready
Built for TradeStation APIs
tradestation-python-client is an unofficial Python client for interacting with the TradeStation APIs.
Install the package from PyPI:
pip install tradestation-python-clientImport it in your project:
from tradestation_python_client import TradeStationClient, TokenManagerThis repository also includes a full development environment, but the primary distribution is a PyPI-installable client.
tradestation-python-client is an unofficial Python client for interacting with the TradeStation REST and Streaming APIs.
It is not affiliated with or endorsed by TradeStation Technologies, Inc.
- By default, it connects to the SIM (sandbox) environment.
- To use LIVE trading:
TokenManager(use_sim=False)This client provides:
- OAuth2 token handling with automatic refresh and thread safety
- REST endpoints (Brokerage & Market Data)
- Real-time streaming support
- Parallel historical data fetching
- Clean, modern Python interface
| Module | Description |
|---|---|
auth.py |
OAuth2 token management with thread-safe refresh |
base_client.py |
HTTP layer with retries, timeouts, and error handling |
client.py |
Main high-level interface for all services |
endpoints/broker.py |
Orders, balances, positions, accounts |
endpoints/mkt_data.py |
Historical + intraday market data |
endpoints/ts_stream.py |
Real-time streaming (bars, quotes, orders, etc.) |
Run the test suite:
pytest -vIncludes tests for:
- Token refresh
- Thread safety
- Streaming message parsing
- HTTP error handling
For contributors or advanced users, the repository provides a fully reproducible development environment.
- Docker Desktop
- Visual Studio Code
- Dev Containers extension
git clone https://github.com/santarsierilorenzo/tradestation-python-client
cd tradestation-python-clientCtrl + Shift + P → Dev Containers: Rebuild Without Cache and Reopen
Create a .env file:
TS_CLIENT_ID=your_client_id
TS_CLIENT_SECRET=your_client_secret
TS_REFRESH_TOKEN=your_refresh_tokenpython -m examples.get_market_data_examplefrom tradestation_python_client import TradeStationClient, TokenManager
token_manager = TokenManager(use_sim=True)
ts = TradeStationClient(token_manager=token_manager)data = ts.market_data.get_bars_between(
symbol="AAPL",
first_date="2025-01-01",
last_date="2025-02-01",
unit="Minute",
interval=5,
max_workers=10
)ts.market_data_stream.stream_bars(
symbol="AAPL",
interval=1,
unit="Minute",
on_message=lambda msg: print(msg)
)MIT © 2025 — Developed with ❤️ by Lorenzo Santarsieri