Skip to main content

QuestradeClient

Struct QuestradeClient 

Source
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

Source

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

Source

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.

Source

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.

Source

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

Source

pub fn parse_date(s: &str) -> Result<Date>

Parse a Questrade datetime to just a time::Date (for option expiry).

Source

pub async fn resolve_symbol(&self, ticker: &str) -> Result<u64>

Resolve a ticker string to a Questrade symbol ID.

Source

pub async fn get_raw_quote(&self, symbol_id: u64) -> Result<Quote>

Fetch a raw equity quote by symbol ID.

Source

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.

Source

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

Source

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

Source

pub async fn get_candles( &self, symbol_id: u64, start: OffsetDateTime, end: OffsetDateTime, interval: &str, ) -> Result<Vec<Candle>>

Fetch historical candles for a symbol.

Source

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.

Source

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

Fetch all accounts for the authenticated user.

Source

pub async fn get_positions(&self, account_id: &str) -> Result<Vec<PositionItem>>

Fetch positions for a specific account.

Source

pub async fn get_account_balances( &self, account_id: &str, ) -> Result<AccountBalances>

Fetch current and start-of-day balances for a specific account.

Source

pub async fn get_markets(&self) -> Result<Vec<MarketInfo>>

Fetch metadata for all markets (trading hours, open/closed status).

Source

pub async fn get_symbol(&self, symbol_id: u64) -> Result<SymbolDetail>

Fetch full symbol details by numeric ID via GET /v1/symbols/:id.

Source

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.

Source

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.

Source

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.

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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