Skip to main content

Client

Struct Client 

Source
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

Source

pub async fn get_accounts(&mut self) -> Result<Vec<Account>, Error>

Get all trading accounts associated with the authenticated user.

Source

pub async fn get_balances( &mut self, account_ids: &[&str], ) -> Result<Vec<Balance>, Error>

Get real-time balances for the specified accounts.

Source

pub async fn get_positions( &mut self, account_ids: &[&str], ) -> Result<Vec<Position>, Error>

Get open positions for the specified accounts.

Source

pub async fn get_orders( &mut self, account_ids: &[&str], ) -> Result<Vec<Order>, Error>

Get active orders for the specified accounts.

Source

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.

Source

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.

Source

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

pub async fn get_historical_orders_by_id( &mut self, account_ids: &[&str], order_ids: &[&str], ) -> Result<Vec<Order>, Error>

Get specific historical orders by order ID.

Source

pub async fn get_wallets( &mut self, account_ids: &[&str], ) -> Result<Vec<Wallet>, Error>

Get cryptocurrency wallet balances for the specified accounts.

Source§

impl Client

Source

pub fn new(credentials: Credentials) -> Self

Create a new client targeting the production API.

Source

pub fn with_sim(self) -> Self

Use the simulation API instead of production.

Source

pub fn with_base_url(self, url: impl Into<String>) -> Self

Override the base URL (useful for testing with mock servers).

Source

pub fn with_token(self, token: Token) -> Self

Set a pre-existing token (e.g., loaded from persistent storage).

Source

pub async fn authenticate(&mut self, code: &str) -> Result<&Token, Error>

Exchange an authorization code for tokens, completing the OAuth2 flow.

Source

pub async fn access_token(&mut self) -> Result<String, Error>

Get a valid access token, automatically refreshing if expired.

Source

pub async fn get(&mut self, path: &str) -> Result<Response, Error>

Make an authenticated GET request to the given path.

Source

pub async fn post<T: Serialize>( &mut self, path: &str, body: &T, ) -> Result<Response, Error>

Make an authenticated POST request with a JSON body.

Source

pub async fn delete(&mut self, path: &str) -> Result<Response, Error>

Make an authenticated DELETE request.

Source

pub async fn put<T: Serialize>( &mut self, path: &str, body: &T, ) -> Result<Response, Error>

Make an authenticated PUT request with a JSON body.

Source

pub fn token_info(&self) -> Option<&Token>

Get the current token (for status display or persistence).

Source

pub fn base_url(&self) -> &str

Get the current base URL.

Source§

impl Client

Source

pub async fn place_order( &mut self, order: &OrderRequest, ) -> Result<OrderResponse, Error>

Place a new order.

§Errors

Returns Error::Api if the order is rejected by TradeStation.

Source

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.

Source

pub async fn cancel_order( &mut self, order_id: &str, ) -> Result<OrderResponse, Error>

Cancel an existing order by its order ID.

Source

pub async fn replace_order( &mut self, order_id: &str, order: &OrderRequest, ) -> Result<OrderResponse, Error>

Replace (modify) an existing order with new parameters.

Source

pub async fn place_order_group( &mut self, group: &OrderGroupRequest, ) -> Result<OrderResponse, Error>

Place an OCO or bracket order group.

Source

pub async fn confirm_order_group( &mut self, group: &OrderGroupRequest, ) -> Result<OrderResponse, Error>

Preview an order group without executing.

Source

pub async fn get_activation_triggers( &mut self, ) -> Result<Vec<ActivationTrigger>, Error>

Get available activation triggers for conditional orders.

Source

pub async fn get_routes(&mut self) -> Result<Vec<Route>, Error>

Get available order routing destinations.

Source§

impl Client

Source

pub async fn get_bars( &mut self, query: &BarChartQuery, ) -> Result<Vec<Bar>, Error>

Fetch historical bar chart data for a symbol.

§Errors

Returns Error::Api if the API request fails.

Source

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"]).

Source

pub async fn get_symbol_info( &mut self, symbols: &[&str], ) -> Result<Vec<SymbolInfo>, Error>

Fetch symbol definition metadata.

Source

pub async fn get_crypto_pairs(&mut self) -> Result<Vec<String>, Error>

Fetch available cryptocurrency trading pairs.

Source

pub async fn get_option_expirations( &mut self, underlying: &str, ) -> Result<Vec<OptionExpiration>, Error>

Fetch option expiration dates for an underlying symbol.

Source

pub async fn get_option_strikes( &mut self, underlying: &str, ) -> Result<Vec<OptionStrike>, Error>

Fetch available strike prices for an underlying symbol.

Source

pub async fn get_option_spread_types( &mut self, ) -> Result<Vec<SpreadType>, Error>

Fetch available option spread types (e.g., Vertical, Calendar).

Source

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

Source

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).

Source

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”)
Source

pub async fn stream_market_depth_quotes( &mut self, symbol: &str, ) -> Result<BoxStream<StreamMarketDepthQuote>, Error>

Stream Level 2 market depth quotes for a symbol.

Source

pub async fn stream_market_depth_aggregates( &mut self, symbol: &str, ) -> Result<BoxStream<StreamMarketDepthAggregate>, Error>

Stream market depth aggregates for a symbol.

Source

pub async fn stream_option_chains( &mut self, underlying: &str, ) -> Result<BoxStream<StreamOptionChain>, Error>

Stream option chain updates for an underlying symbol.

Source

pub async fn stream_option_quotes( &mut self, legs: &[&str], ) -> Result<BoxStream<StreamOptionQuote>, Error>

Stream option quote updates for specific option legs.

Source

pub async fn stream_orders( &mut self, account_ids: &[&str], ) -> Result<BoxStream<StreamOrder>, Error>

Stream order status updates for the specified accounts.

Source

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.

Source

pub async fn stream_positions( &mut self, account_ids: &[&str], ) -> Result<BoxStream<StreamPosition>, Error>

Stream position updates for the specified accounts.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more