| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This directory contains quick-start examples that demonstrate the basic usage of the TradeStation API Python wrapper.
CLIENT_ID=your_client_id REFRESH_TOKEN=your_refresh_token ENVIRONMENT=Simulation # or 'Live' for production
poetry installpoetry run python examples/QuickStart/quick_start.pyThis example:
poetry run python examples/QuickStart/multi_symbol_quotes.pyThis example:
poetry run python examples/QuickStart/stream_quotes.pyThis example:
The TradeStationClient will automatically:
from src.client.tradestation_client import TradeStationClient
client = TradeStationClient()The client has service objects for different categories of API endpoints:
Examples:
# Get symbol details
symbol_details = await client.market_data.get_symbol_details('AAPL')
# Get quotes for multiple symbols
quotes = await client.market_data.get_quote_snapshots("AAPL,MSFT,SPY")For real-time data like quotes, TradeStation uses Server-Sent Events over HTTP. The client provides a StreamReader to process this.
import json
# Start a streaming connection
stream_reader = await client.market_data.stream_quotes("AAPL,MSFT,GOOG")
# Process streaming data line by line
while True:
line = await stream_reader.readline()
if not line:
break # Stream closed
try:
data = json.loads(line.strip().decode('utf-8'))
if 'Symbol' in data and 'Last' in data: # Process quote
print(f"Quote: {data.get('Symbol')} Last: {data.get('Last')}")
elif 'Heartbeat' in data: # Process heartbeat
print(f"Heartbeat: {data.get('Timestamp')}")
elif 'Error' in data: # Process error
print(f"Error: {data.get('Message')}")
break # Or handle error appropriately
except json.JSONDecodeError:
# Handle non-JSON lines if necessary
pass
except Exception as e:
# Handle other processing errors
print(f"Error processing line: {e}")
break
# HttpClient cleanup handles the underlying connectionAlways wrap API calls in try/except blocks to handle potential errors:
try:
response = await client.market_data.get_symbol_details('AAPL')
except Exception as error:
print(f"Error: {str(error)}")
finally:
# Clean up resources (closes underlying HTTP session)
if client:
await client.http_client.close()After mastering these examples, explore the other examples in the examples directory:
These QuickStart examples provide an introduction to the core functionality of the TradeStation API Python wrapper. They demonstrate:
By exploring these examples, you should now understand how to authenticate with the TradeStation API, fetch market data, and establish real-time data streams. The Python wrapper handles the complex authentication, rate limiting, and connection management, allowing you to focus on your trading strategies and applications.
For more advanced use cases, check the other example directories or refer to the official TradeStation API documentation for details on available endpoints and data structures.
| Back | FazBrowse Home | New Git URL |