pub struct QuestradeClient { /* private fields */ }Expand description
Async HTTP client for the Questrade REST API.
Wraps a TokenManager for transparent OAuth token refresh and provides
methods for market data (quotes, option chains, candles) and account data
(positions, balances, activities).
Construct via QuestradeClient::new for defaults, or use
QuestradeClientBuilder to supply a custom reqwest::Client
(e.g. for custom TLS roots or proxy configuration):
let custom_http = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()?;
let client = QuestradeClientBuilder::new()
.token_manager(tm)
.http_client(custom_http)
.build()?;Implementations§
Source§impl QuestradeClient
impl QuestradeClient
Sourcepub fn new(token_manager: TokenManager) -> Result<Self>
pub fn new(token_manager: TokenManager) -> Result<Self>
Create a new client backed by the given TokenManager.
This is a convenience shorthand equivalent to:
let client = QuestradeClientBuilder::new()
.token_manager(token_manager)
.build()?;§Errors
Returns an error if the underlying HTTP client cannot be built (e.g. TLS initialisation fails).
Sourcepub fn with_raw_logging(self, enabled: bool) -> Self
pub fn with_raw_logging(self, enabled: bool) -> Self
Enable or disable raw response body logging at trace! level.
When enabled, get() and post() read the response body as text,
log it at trace! level, then deserialize from the string. When
disabled (the default), responses are deserialized directly from the
stream for zero overhead.
Sourcepub async fn get_text(&self, path: &str) -> Result<String>
pub async fn get_text(&self, path: &str) -> Result<String>
GET request that returns the raw response body as a string.
Performs the same auth/retry dance as get() but returns
the response body as-is without deserializing. Useful for inspecting
raw API responses during development.
Sourcepub fn parse_datetime(s: &str) -> Result<OffsetDateTime>
pub fn parse_datetime(s: &str) -> Result<OffsetDateTime>
Parse a Questrade datetime string to OffsetDateTime.
Questrade returns datetimes like "2014-10-24T20:06:40.131000-04:00".
Sourcepub fn parse_date(s: &str) -> Result<Date>
pub fn parse_date(s: &str) -> Result<Date>
Parse a Questrade datetime to just a time::Date (for option expiry).
Sourcepub async fn resolve_symbol(&self, ticker: &str) -> Result<u64>
pub async fn resolve_symbol(&self, ticker: &str) -> Result<u64>
Resolve a ticker string to a Questrade symbol ID.
Sourcepub async fn get_raw_quote(&self, symbol_id: u64) -> Result<Quote>
pub async fn get_raw_quote(&self, symbol_id: u64) -> Result<Quote>
Fetch a raw equity quote by symbol ID.
Sourcepub async fn get_option_chain_structure(
&self,
symbol_id: u64,
) -> Result<OptionChainResponse>
pub async fn get_option_chain_structure( &self, symbol_id: u64, ) -> Result<OptionChainResponse>
Fetch the option chain structure (expiries + strikes + symbol IDs) for a symbol.
Sourcepub async fn get_option_quotes_by_ids(
&self,
symbol_ids: &[u64],
) -> Result<HashMap<u64, (f64, f64)>>
pub async fn get_option_quotes_by_ids( &self, symbol_ids: &[u64], ) -> Result<HashMap<u64, (f64, f64)>>
Fetch current quotes for a set of option symbol IDs. Returns a map of symbol_id -> (bid, ask).
Sourcepub async fn get_option_quotes_raw(
&self,
ids: &[u64],
) -> Result<Vec<OptionQuote>>
pub async fn get_option_quotes_raw( &self, ids: &[u64], ) -> Result<Vec<OptionQuote>>
Fetch full option quote objects for a set of option symbol IDs (in batches).
Sourcepub async fn get_candles(
&self,
symbol_id: u64,
start: OffsetDateTime,
end: OffsetDateTime,
interval: &str,
) -> Result<Vec<Candle>>
pub async fn get_candles( &self, symbol_id: u64, start: OffsetDateTime, end: OffsetDateTime, interval: &str, ) -> Result<Vec<Candle>>
Fetch historical candles for a symbol.
Sourcepub async fn get_server_time(&self) -> Result<OffsetDateTime>
pub async fn get_server_time(&self) -> Result<OffsetDateTime>
Fetch the current server time from Questrade.
Uses GET /v1/time. Not cached — real-time by definition.
Sourcepub async fn get_accounts(&self) -> Result<Vec<Account>>
pub async fn get_accounts(&self) -> Result<Vec<Account>>
Fetch all accounts for the authenticated user.
Sourcepub async fn get_positions(&self, account_id: &str) -> Result<Vec<PositionItem>>
pub async fn get_positions(&self, account_id: &str) -> Result<Vec<PositionItem>>
Fetch positions for a specific account.
Sourcepub async fn get_account_balances(
&self,
account_id: &str,
) -> Result<AccountBalances>
pub async fn get_account_balances( &self, account_id: &str, ) -> Result<AccountBalances>
Fetch current and start-of-day balances for a specific account.
Sourcepub async fn get_markets(&self) -> Result<Vec<MarketInfo>>
pub async fn get_markets(&self) -> Result<Vec<MarketInfo>>
Fetch metadata for all markets (trading hours, open/closed status).
Sourcepub async fn get_symbol(&self, symbol_id: u64) -> Result<SymbolDetail>
pub async fn get_symbol(&self, symbol_id: u64) -> Result<SymbolDetail>
Fetch full symbol details by numeric ID via GET /v1/symbols/:id.
Sourcepub async fn get_activities(
&self,
account_id: &str,
start: OffsetDateTime,
end: OffsetDateTime,
) -> Result<Vec<ActivityItem>>
pub async fn get_activities( &self, account_id: &str, start: OffsetDateTime, end: OffsetDateTime, ) -> Result<Vec<ActivityItem>>
Fetch account activities (executions, dividends, etc.) for a date range.
Questrade limits queries to 31-day windows per request; we use 30-day
windows to stay safely within the boundary. This method transparently
splits any range longer than 30 days into compliant sub-windows and
combines the results, sorted by trade_date ascending.
Sourcepub async fn get_orders(
&self,
account_id: &str,
start: OffsetDateTime,
end: OffsetDateTime,
state_filter: OrderStateFilter,
) -> Result<Vec<OrderItem>>
pub async fn get_orders( &self, account_id: &str, start: OffsetDateTime, end: OffsetDateTime, state_filter: OrderStateFilter, ) -> Result<Vec<OrderItem>>
Fetch orders for a specific account within a date range.
Use state_filter to limit results to open, closed, or all orders.
Unlike activities, there is no documented date-range window limit for
this endpoint.
Sourcepub async fn get_executions(
&self,
account_id: &str,
start: OffsetDateTime,
end: OffsetDateTime,
) -> Result<Vec<Execution>>
pub async fn get_executions( &self, account_id: &str, start: OffsetDateTime, end: OffsetDateTime, ) -> Result<Vec<Execution>>
Fetch trade executions (fill-level detail) for a date range.
Uses 30-day windowing, same as get_activities.
Results are sorted by timestamp ascending.