pub struct Client { /* private fields */ }Expand description
TradeStation API client with automatic token management.
§Example
use tradestation_api::{Client, Credentials};
let creds = Credentials::new("id", "secret");
let mut client = Client::new(creds);
client.authenticate("auth_code").await?;
let accounts = client.get_accounts().await?;Implementations§
Source§impl Client
impl Client
Sourcepub async fn get_accounts(&mut self) -> Result<Vec<Account>, Error>
pub async fn get_accounts(&mut self) -> Result<Vec<Account>, Error>
Get all trading accounts associated with the authenticated user.
Sourcepub async fn get_balances(
&mut self,
account_ids: &[&str],
) -> Result<Vec<Balance>, Error>
pub async fn get_balances( &mut self, account_ids: &[&str], ) -> Result<Vec<Balance>, Error>
Get real-time balances for the specified accounts.
Sourcepub async fn get_positions(
&mut self,
account_ids: &[&str],
) -> Result<Vec<Position>, Error>
pub async fn get_positions( &mut self, account_ids: &[&str], ) -> Result<Vec<Position>, Error>
Get open positions for the specified accounts.
Sourcepub async fn get_orders(
&mut self,
account_ids: &[&str],
) -> Result<Vec<Order>, Error>
pub async fn get_orders( &mut self, account_ids: &[&str], ) -> Result<Vec<Order>, Error>
Get active orders for the specified accounts.
Sourcepub async fn get_bod_balances(
&mut self,
account_ids: &[&str],
) -> Result<Vec<BodBalance>, Error>
pub async fn get_bod_balances( &mut self, account_ids: &[&str], ) -> Result<Vec<BodBalance>, Error>
Get beginning-of-day balance snapshots for the specified accounts.
Sourcepub async fn get_orders_by_id(
&mut self,
account_ids: &[&str],
order_ids: &[&str],
) -> Result<Vec<Order>, Error>
pub async fn get_orders_by_id( &mut self, account_ids: &[&str], order_ids: &[&str], ) -> Result<Vec<Order>, Error>
Get specific orders by order ID.
Sourcepub async fn get_historical_orders(
&mut self,
account_ids: &[&str],
since: &str,
) -> Result<Vec<Order>, Error>
pub async fn get_historical_orders( &mut self, account_ids: &[&str], since: &str, ) -> Result<Vec<Order>, Error>
Get historical (filled/cancelled) orders for the specified accounts.
since is a date string in YYYY-MM-DD format specifying how far back to look.
TradeStation limits historical orders to ~90 days.
Source§impl Client
impl Client
Sourcepub fn new(credentials: Credentials) -> Self
pub fn new(credentials: Credentials) -> Self
Create a new client targeting the production API.
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Override the base URL (useful for testing with mock servers).
Sourcepub fn with_token(self, token: Token) -> Self
pub fn with_token(self, token: Token) -> Self
Set a pre-existing token (e.g., loaded from persistent storage).
Sourcepub async fn authenticate(&mut self, code: &str) -> Result<&Token, Error>
pub async fn authenticate(&mut self, code: &str) -> Result<&Token, Error>
Exchange an authorization code for tokens, completing the OAuth2 flow.
Sourcepub async fn access_token(&mut self) -> Result<String, Error>
pub async fn access_token(&mut self) -> Result<String, Error>
Get a valid access token, automatically refreshing if expired.
Sourcepub async fn get(&mut self, path: &str) -> Result<Response, Error>
pub async fn get(&mut self, path: &str) -> Result<Response, Error>
Make an authenticated GET request to the given path.
Sourcepub async fn post<T: Serialize>(
&mut self,
path: &str,
body: &T,
) -> Result<Response, Error>
pub async fn post<T: Serialize>( &mut self, path: &str, body: &T, ) -> Result<Response, Error>
Make an authenticated POST request with a JSON body.
Sourcepub async fn delete(&mut self, path: &str) -> Result<Response, Error>
pub async fn delete(&mut self, path: &str) -> Result<Response, Error>
Make an authenticated DELETE request.
Sourcepub async fn put<T: Serialize>(
&mut self,
path: &str,
body: &T,
) -> Result<Response, Error>
pub async fn put<T: Serialize>( &mut self, path: &str, body: &T, ) -> Result<Response, Error>
Make an authenticated PUT request with a JSON body.
Sourcepub fn token_info(&self) -> Option<&Token>
pub fn token_info(&self) -> Option<&Token>
Get the current token (for status display or persistence).
Source§impl Client
impl Client
Sourcepub async fn place_order(
&mut self,
order: &OrderRequest,
) -> Result<OrderResponse, Error>
pub async fn place_order( &mut self, order: &OrderRequest, ) -> Result<OrderResponse, Error>
Sourcepub async fn confirm_order(
&mut self,
order: &OrderRequest,
) -> Result<OrderResponse, Error>
pub async fn confirm_order( &mut self, order: &OrderRequest, ) -> Result<OrderResponse, Error>
Preview an order without executing it.
Returns estimated fill details and any validation errors.
Sourcepub async fn cancel_order(
&mut self,
order_id: &str,
) -> Result<OrderResponse, Error>
pub async fn cancel_order( &mut self, order_id: &str, ) -> Result<OrderResponse, Error>
Cancel an existing order by its order ID.
Sourcepub async fn replace_order(
&mut self,
order_id: &str,
order: &OrderRequest,
) -> Result<OrderResponse, Error>
pub async fn replace_order( &mut self, order_id: &str, order: &OrderRequest, ) -> Result<OrderResponse, Error>
Replace (modify) an existing order with new parameters.
Sourcepub async fn place_order_group(
&mut self,
group: &OrderGroupRequest,
) -> Result<OrderResponse, Error>
pub async fn place_order_group( &mut self, group: &OrderGroupRequest, ) -> Result<OrderResponse, Error>
Place an OCO or bracket order group.
Sourcepub async fn confirm_order_group(
&mut self,
group: &OrderGroupRequest,
) -> Result<OrderResponse, Error>
pub async fn confirm_order_group( &mut self, group: &OrderGroupRequest, ) -> Result<OrderResponse, Error>
Preview an order group without executing.
Sourcepub async fn get_activation_triggers(
&mut self,
) -> Result<Vec<ActivationTrigger>, Error>
pub async fn get_activation_triggers( &mut self, ) -> Result<Vec<ActivationTrigger>, Error>
Get available activation triggers for conditional orders.
Source§impl Client
impl Client
Sourcepub async fn get_quotes(
&mut self,
symbols: &[&str],
) -> Result<Vec<Quote>, Error>
pub async fn get_quotes( &mut self, symbols: &[&str], ) -> Result<Vec<Quote>, Error>
Fetch quote snapshots for one or more symbols.
Accepts a slice of ticker symbols (e.g., &["AAPL", "MSFT"]).
Sourcepub async fn get_symbol_info(
&mut self,
symbols: &[&str],
) -> Result<Vec<SymbolInfo>, Error>
pub async fn get_symbol_info( &mut self, symbols: &[&str], ) -> Result<Vec<SymbolInfo>, Error>
Fetch symbol definition metadata.
Sourcepub async fn get_crypto_pairs(&mut self) -> Result<Vec<String>, Error>
pub async fn get_crypto_pairs(&mut self) -> Result<Vec<String>, Error>
Fetch available cryptocurrency trading pairs.
Sourcepub async fn get_option_expirations(
&mut self,
underlying: &str,
) -> Result<Vec<OptionExpiration>, Error>
pub async fn get_option_expirations( &mut self, underlying: &str, ) -> Result<Vec<OptionExpiration>, Error>
Fetch option expiration dates for an underlying symbol.
Sourcepub async fn get_option_strikes(
&mut self,
underlying: &str,
) -> Result<Vec<OptionStrike>, Error>
pub async fn get_option_strikes( &mut self, underlying: &str, ) -> Result<Vec<OptionStrike>, Error>
Fetch available strike prices for an underlying symbol.
Sourcepub async fn get_option_spread_types(
&mut self,
) -> Result<Vec<SpreadType>, Error>
pub async fn get_option_spread_types( &mut self, ) -> Result<Vec<SpreadType>, Error>
Fetch available option spread types (e.g., Vertical, Calendar).
Sourcepub async fn get_option_risk_reward(
&mut self,
request: &RiskRewardRequest,
) -> Result<RiskRewardResponse, Error>
pub async fn get_option_risk_reward( &mut self, request: &RiskRewardRequest, ) -> Result<RiskRewardResponse, Error>
Analyze option risk/reward for a given trade.
Source§impl Client
impl Client
Sourcepub async fn stream_quotes(
&mut self,
symbols: &[&str],
) -> Result<BoxStream<StreamQuote>, Error>
pub async fn stream_quotes( &mut self, symbols: &[&str], ) -> Result<BoxStream<StreamQuote>, Error>
Stream live quote updates for one or more symbols.
Returns an async stream of StreamQuote values including
StreamStatus messages (EndSnapshot, GoAway).
Sourcepub async fn stream_bars(
&mut self,
symbol: &str,
interval: &str,
unit: &str,
) -> Result<BoxStream<StreamBar>, Error>
pub async fn stream_bars( &mut self, symbol: &str, interval: &str, unit: &str, ) -> Result<BoxStream<StreamBar>, Error>
Stream live bar updates for a symbol.
§Parameters
symbol: Ticker symbol (e.g., “AAPL”)interval: Bar interval (e.g., “1”, “5”)unit: Bar unit (e.g., “Minute”, “Daily”)
Sourcepub async fn stream_market_depth_quotes(
&mut self,
symbol: &str,
) -> Result<BoxStream<StreamMarketDepthQuote>, Error>
pub async fn stream_market_depth_quotes( &mut self, symbol: &str, ) -> Result<BoxStream<StreamMarketDepthQuote>, Error>
Stream Level 2 market depth quotes for a symbol.
Sourcepub async fn stream_market_depth_aggregates(
&mut self,
symbol: &str,
) -> Result<BoxStream<StreamMarketDepthAggregate>, Error>
pub async fn stream_market_depth_aggregates( &mut self, symbol: &str, ) -> Result<BoxStream<StreamMarketDepthAggregate>, Error>
Stream market depth aggregates for a symbol.
Sourcepub async fn stream_option_chains(
&mut self,
underlying: &str,
) -> Result<BoxStream<StreamOptionChain>, Error>
pub async fn stream_option_chains( &mut self, underlying: &str, ) -> Result<BoxStream<StreamOptionChain>, Error>
Stream option chain updates for an underlying symbol.
Sourcepub async fn stream_option_quotes(
&mut self,
legs: &[&str],
) -> Result<BoxStream<StreamOptionQuote>, Error>
pub async fn stream_option_quotes( &mut self, legs: &[&str], ) -> Result<BoxStream<StreamOptionQuote>, Error>
Stream option quote updates for specific option legs.
Sourcepub async fn stream_orders(
&mut self,
account_ids: &[&str],
) -> Result<BoxStream<StreamOrder>, Error>
pub async fn stream_orders( &mut self, account_ids: &[&str], ) -> Result<BoxStream<StreamOrder>, Error>
Stream order status updates for the specified accounts.
Sourcepub async fn stream_orders_by_id(
&mut self,
account_ids: &[&str],
order_ids: &[&str],
) -> Result<BoxStream<StreamOrder>, Error>
pub async fn stream_orders_by_id( &mut self, account_ids: &[&str], order_ids: &[&str], ) -> Result<BoxStream<StreamOrder>, Error>
Stream order updates for specific order IDs.
Sourcepub async fn stream_positions(
&mut self,
account_ids: &[&str],
) -> Result<BoxStream<StreamPosition>, Error>
pub async fn stream_positions( &mut self, account_ids: &[&str], ) -> Result<BoxStream<StreamPosition>, Error>
Stream position updates for the specified accounts.