Struct IBClientPortal

Source
pub struct IBClientPortal {
    pub port: i32,
    pub listen_ssl: bool,
    pub account: String,
    pub client: Client,
    pub session_id: Option<String>,
}
Expand description

This is the base class of the library. It is used to communicate with the IB CP Gateway.

https://interactivebrokers.github.io/cpwebapi/endpoints

bin/run.sh root/conf.yaml

Fields§

§port: i32§listen_ssl: bool§account: String§client: Client§session_id: Option<String>

Implementations§

Source§

impl IBClientPortal

Source

pub fn new(port: i32, listen_ssl: bool, account: &str) -> IBClientPortal

Source

pub fn from_env() -> Self

Builds the client from env vars. Needs IB_PORT IB_SSL IB_ACCOUNT

Source§

impl IBClientPortal

Source

pub async fn check_auth_status(&self) -> Result<AuthStatus, Error>

Current Authentication status to the Brokerage system. Market Data and Trading is not possible if not authenticated, e.g. authenticated shows false

Source

pub async fn tickle(&self) -> Result<Tickle, Error>

If the gateway has not received any requests for several minutes an open session will automatically timeout. The tickle endpoint pings the server to prevent the session from ending.

Source

pub async fn get_positions(&self, page: i32) -> Result<Vec<Position>, Error>

Returns a list of positions for the given account. The endpoint supports paging, page’s default size is 30 positions. /portfolio/accounts or /portfolio/subaccounts must be called prior to this endpoint.

Source

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

Convenience method to call tickle and get the session id. It is necessary to auth the websocket connection.

Source

pub async fn get_security_definition_by_contract_id( &self, contract_ids: Vec<i64>, ) -> Result<SecurityDefinitions, Error>

Returns a list of security definitions for the given conids

Source

pub async fn get_futures_by_symbol( &self, symbols: Vec<&str>, ) -> Result<FuturesContracts, Error>

Returns a list of non-expired future contracts for given symbol(s)

Source

pub async fn get_stocks_by_symbol( &self, symbols: Vec<&str>, ) -> Result<StockContracts, Error>

Returns an object contains all stock contracts for given symbol(s)

Source

pub async fn search_for_security( &self, symbol_or_name: &str, is_name: bool, sec_type: AssetClass, ) -> Result<Value, Error>

Search by underlying symbol or company name. Relays back what derivative contract(s) it has. This endpoint must be called before using /secdef/info. If company name is specified will only receive limited response: conid, companyName, companyHeader and symbol.

Source

pub async fn get_options( &self, underlying_con_id: i64, sectype: AssetClass, month: Option<String>, exchange: Option<String>, strike: Option<Decimal>, ) -> Result<Value, Error>

Provides Contract Details of Futures, Options, Warrants, Cash and CFDs based on conid. To get the strike price for Options/Warrants use “/iserver/secdef/strikes” endpoint. Must call /secdef/search for the underlying contract first.

Source

pub async fn logout(&self) -> Result<Value, Error>

Logs the user out of the gateway session. Any further activity requires re-authentication.

Source

pub async fn get_account_ledger( &self, ) -> Result<HashMap<String, AccountLedger>, Error>

Source

pub async fn place_order( &self, orders: Vec<OrderTicket>, ) -> Result<Value, Error>

Source

pub async fn get_contract_detail( &self, conid: i64, ) -> Result<ContractDetail, Error>

Get contracts details. Many fields are optional and do not match the api documentation.

Source

pub async fn get_market_data_history( &self, conid: i64, exchange: Option<&str>, period: &str, bar: &str, outside_rth: bool, start_time: Option<NaiveDateTime>, ) -> Result<MarketDataHistory, Error>

Get market data history tradingDayDuration is not always present if period is less than 1 day exchange is optional and will be set to “” if not provided startTime is optional and not documented to retrieve 1min bars the startTime should be 2 minutes after the timestamp expected in the last bar of the response

Source§

impl IBClientPortal

Source

pub async fn connect_to_websocket( &self, subscriptions: Vec<Subscription>, on_message: fn(String), ) -> Result<(), Error>

Trait Implementations§

Source§

impl Clone for IBClientPortal

Source§

fn clone(&self) -> IBClientPortal

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 IBClientPortal

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for IBClientPortal

Source§

fn default() -> IBClientPortal

Returns the “default value” for a type. 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,