Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A configured client for the IBKR Client Portal Web API.

Client holds a bezant_api::IbRestApiClient internally. The Arc makes it cheap to clone — share one instance across your app.

Implementations§

Source§

impl Client

Source

pub async fn auth_status(&self) -> Result<AuthStatus>

Query current auth + connection status via POST /iserver/auth/status.

§Errors

Transport + decode errors; Error::Api for any underlying error.

Source

pub async fn tickle(&self) -> Result<TickleResponse>

Tickle the Gateway (POST /tickle) to keep the session alive.

CPAPI sessions expire after ~5 minutes of inactivity; call this at least once a minute from a background task, or use Client::spawn_keepalive.

§Errors

Transport + decode errors.

Source

pub async fn health(&self) -> Result<AuthStatus>

Convenience: return the status if authenticated, else a typed error (Error::NotAuthenticated / Error::NoSession).

§Errors

See variants.

Source

pub fn spawn_keepalive(&self, interval: Duration) -> KeepaliveHandle

Spawn a tokio task that calls Client::tickle on interval until the returned KeepaliveHandle is dropped. The CPAPI session times out around 5 minutes; 60s is a sensible default.

Tickle failures are logged via tracing::warn! and don’t abort the task — a transient outage is recoverable once the Gateway is back.

Source§

impl Client

Source

pub fn new(base_url: impl AsRef<str>) -> Result<Self>

Construct a client pointed at base_url with Bezant’s recommended defaults (accepts the Gateway’s self-signed cert, 30s timeout, persistent cookie jar).

§Errors

Returns Error::InvalidBaseUrl if base_url is not a valid URL and Error::Http if reqwest fails to build its client.

Source

pub fn builder(base_url: impl AsRef<str>) -> ClientBuilder

Return a builder for fine-grained configuration.

Source

pub fn api(&self) -> &IbRestApiClient

Borrow the underlying generated API client for raw endpoint access.

Every one of the ~155 CPAPI endpoints is available via typed methods on bezant_api::IbRestApiClient.

Source

pub fn http(&self) -> &Client

Borrow the underlying reqwest::Client for untyped HTTP passthrough (e.g. when you want to proxy CPAPI calls rather than decode them).

Source

pub fn base_url(&self) -> &Url

Base URL the client is pointed at, including the CPAPI prefix (e.g. https://localhost:5000/v1/api).

Source

pub fn gateway_root_url(&self) -> &Url

The Gateway’s root URL — Client::base_url with the CPAPI prefix trimmed off (e.g. https://localhost:5000/). Useful when you need to hit paths the Gateway serves outside /v1/api (login, static assets).

Source

pub fn cookie_jar(&self) -> Arc<NameKeyedJar>

Shared cookie jar backing the underlying reqwest::Client.

Expose this when you’re running bezant alongside a reverse proxy (for example bezant-server’s /sso/Login passthrough): you can inject cookies that arrive from the proxied caller so that typed API calls made through the same Client see the same session.

The underlying NameKeyedJar keys cookies purely by name — inserting JSESSIONID=NEW overwrites JSESSIONID=OLD regardless of the path either was originally set on. This trades RFC 6265 path/domain semantics for “the Gateway never sees two values for the same cookie name”, which CPGateway requires.

Source§

impl Client

Source

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

Fetch every position across every page for account_id.

CPAPI returns up to POSITIONS_PAGE_SIZE entries per page; this helper walks pages starting from 0 and stops once a short page (or an empty one) is returned. MAX_POSITION_PAGES caps runaway loops.

§Errors

Any transport / decode failure surfaces as Error. An Error::NotAuthenticated is returned if the Gateway reports the session is not live.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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