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
impl Client
Sourcepub async fn auth_status(&self) -> Result<AuthStatus>
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.
Sourcepub async fn tickle(&self) -> Result<TickleResponse>
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.
Sourcepub async fn health(&self) -> Result<AuthStatus>
pub async fn health(&self) -> Result<AuthStatus>
Convenience: return the status if authenticated, else a typed error
(Error::NotAuthenticated / Error::NoSession).
§Errors
See variants.
Sourcepub fn spawn_keepalive(&self, interval: Duration) -> KeepaliveHandle
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
impl Client
Sourcepub fn new(base_url: impl AsRef<str>) -> Result<Self>
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.
Sourcepub fn builder(base_url: impl AsRef<str>) -> ClientBuilder
pub fn builder(base_url: impl AsRef<str>) -> ClientBuilder
Return a builder for fine-grained configuration.
Sourcepub fn api(&self) -> &IbRestApiClient
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.
Sourcepub fn http(&self) -> &Client
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).
Sourcepub fn base_url(&self) -> &Url
pub fn base_url(&self) -> &Url
Base URL the client is pointed at, including the CPAPI prefix
(e.g. https://localhost:5000/v1/api).
Sourcepub fn gateway_root_url(&self) -> &Url
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).
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
impl Client
Sourcepub async fn all_positions(&self, account_id: &str) -> Result<Vec<Position>>
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.