Python package for interacting with TradeStation APIs.
Project description
tradestation-python-client
Fully Thread-Safe · Streaming Ready
Built for TradeStation APIs
tradestation-python-client is an unofficial Python client for interacting with the TradeStation REST and Streaming APIs.
📦 Installation (PyPI Package)
Install the package from PyPI:
pip install tradestation-python-client
Import it in your project:
from tradestation_python_client import TradeStationClient, TokenManager
This repository also includes a full development environment, but the primary distribution is a PyPI-installable client.
⚠️ Disclaimer
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)
🧩 Overview
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
🔧 Core Modules
| 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.) |
🧪 Testing
Run the test suite:
pytest -v
Includes tests for:
- Token refresh
- Thread safety
- Streaming message parsing
- HTTP error handling
🧰 Development Environment (DevContainer + Docker)
For contributors or advanced users, the repository provides a fully reproducible development environment.
Prerequisites
- Docker Desktop
- Visual Studio Code
- Dev Containers extension
Setup
1️⃣ Clone the repository
git clone https://github.com/santarsierilorenzo/tradestation-python-client
cd tradestation-python-client
2️⃣ Open inside DevContainer
Ctrl + Shift + P → Dev Containers: Rebuild Without Cache and Reopen
3️⃣ Configure environment variables
Create a .env file:
TS_CLIENT_ID=your_client_id
TS_CLIENT_SECRET=your_client_secret
TS_REFRESH_TOKEN=your_refresh_token
4️⃣ Run an example
python -m examples.get_market_data_example
⚙️ Usage Examples
Basic Initialization
from tradestation_python_client import TradeStationClient, TokenManager
token_manager = TokenManager(use_sim=True)
ts = TradeStationClient(token_manager=token_manager)
Parallel Historical Data Fetching
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
)
Real-Time Streaming
ts.market_data_stream.stream_bars(
symbol="AAPL",
interval=1,
unit="Minute",
on_message=lambda msg: print(msg)
)
🪪 License
MIT © 2025 — Developed with ❤️ by Lorenzo Santarsieri
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tradestation_python_client-0.1.1.tar.gz.
File metadata
- Download URL: tradestation_python_client-0.1.1.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10a3d955d0ed3de7e4253f255b2d4e79a04771688b8ce4baae3e4b51c8e78a25
|
|
| MD5 |
8ea5925e90e2a40f89803523970ad2ff
|
|
| BLAKE2b-256 |
2bc088888549c2f12dafa61bb6b95e101bf651f583086e0711fbfb80cd5ea5f0
|
File details
Details for the file tradestation_python_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tradestation_python_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f963bde453f87c6ec787da783170eb84bc85eff5ee3ceec3475e0257eab72360
|
|
| MD5 |
d5d715f69ba60b99b8c4422b0ffd0056
|
|
| BLAKE2b-256 |
1d8be6d8773e62a253cfb31cfe1c4ea3cd63c67041f469719daed5d59e6cac47
|