A Python Client library for the TradeStation API.
- Overview
- What's in the API
- Requirements
- API Key & Credentials
- Installation
- Usage
- Features
- Documentation & Resources
- Support These Projects
The unofficial Python API client library for TradeStation allows individuals with TradeStation accounts to manage trades, pull historical and real-time data, manage their accounts, create and modify orders all using the Python programming language.
To learn more about the TradeStation API, please refer to the official documentation.
- Authentication - access tokens, refresh tokens, request authentication.
- Accounts & Trading
- Symbols
- Index
- Orders
- Paper Trading
- Quotes
- Transaction History
The following requirements must be met to use this API:
- A TradeStation account, you'll need your account password and account number to use the API.
- A TradeStation Developer API Key
- A Redirect URI, sometimes called Redirect URL
- Python 3.8 or later.
Each TradeStation API request requires a TradeStation Developer API Key, a consumer ID, an account password, an account number, and a redirect URI. API Keys, consumer IDs, and redirect URIs are generated from the TradeStation developer portal. To set up and create your TradeStation developer account, please refer to the official documentation.
Additionally, to authenticate yourself using this library, you will need to provide your account number and password for your main TradeStation account.
Important: Your account number, an account password, consumer ID, and API key should be kept secret.
pip install -e .
This example demonstrates how to login to the API and demonstrates sending a request using the quotes
, and stream_bars_start_date
endpoint, using your API key.
# Import the client
from ts.client import TradeStationClient
# Create the Client.
ts_client = TradeStationClient(
username="USERNAME",
client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
redirect_uri="REDIRECT_URI",
paper_trading="PAPER_TRADING"
)
# Get quotes for Oil Futures.
ts_client.quotes(symbols=['@CL'])
# Stream quotes for Amazon.
ts_client.stream_quotes_changes(symbols=['AMZN'])
# Stream bars for a certain date.
ts_client.stream_bars_start_date(
symbol='AMZN',
interval=5,
unit='Minute',
start_date='02-25-2020',
session='USEQPreAndPost'
)
Automatically will handle the authentication workflow for new users, returning users, and users with expired tokens (refresh token or access token).
For certain requests, in a limited fashion, it will help validate your request when possible. For example, when using the get_bars
endpoint, it will automatically validate that the market you're requesting data from is one of the valid options.
Patreon: Help support this project and future projects by donating to my Patreon Page. I'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require me to pay monthly fees.
YouTube: If you'd like to watch more of my content, feel free to visit my YouTube channel Sigma Coding.
Hire Me: If you have a project, you think I can help you with feel free to reach out at coding.sigma@gmail.com