Skip to main content

HistoricalTicksBuilder

Struct HistoricalTicksBuilder 

Source
pub struct HistoricalTicksBuilder<'a, C> { /* private fields */ }
Expand description

Builder for the historical-ticks API.

IBKR requires at least one of starting / ending to anchor the query. The builder does not pre-flight this — the wire encoder accepts both unset, and IBKR surfaces its own error if neither is provided.

Implementations§

Source§

impl<'a, C> HistoricalTicksBuilder<'a, C>

Source

pub fn starting(self, start: OffsetDateTime) -> Self

Anchor the query at the start date (fetch forward in time).

Source

pub fn ending(self, end: OffsetDateTime) -> Self

Anchor the query at the end date (fetch backward in time).

Source

pub fn trading_hours(self, trading_hours: TradingHours) -> Self

Override regular- vs extended-hours (defaults to TradingHours::Regular).

Source§

impl<'a> HistoricalTicksBuilder<'a, Client>

Source

pub fn trade(self) -> Result<TickSubscription<TickLast>, Error>

Submit the request and return trade ticks.

§Examples
use ibapi::client::blocking::Client;
use ibapi::contracts::Contract;
use time::macros::datetime;

let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed");
let contract = Contract::stock("TSLA").build();

let ticks = client
    .historical_ticks(&contract, 100)
    .starting(datetime!(2023-04-15 0:00 UTC))
    .trade()
    .expect("historical ticks request failed");

for tick in ticks.iter_data() {
    println!("{:?}", tick.expect("decode error"));
}
Source

pub fn mid_point(self) -> Result<TickSubscription<TickMidpoint>, Error>

Submit the request and return midpoint ticks.

§Examples
use ibapi::client::blocking::Client;
use ibapi::contracts::Contract;
use time::macros::datetime;

let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed");
let contract = Contract::stock("TSLA").build();

let ticks = client
    .historical_ticks(&contract, 100)
    .ending(datetime!(2023-04-15 0:00 UTC))
    .mid_point()
    .expect("historical ticks request failed");

for tick in ticks.iter_data() {
    println!("{:?}", tick.expect("decode error"));
}
Source

pub fn bid_ask( self, ignore_size: IgnoreSize, ) -> Result<TickSubscription<TickBidAsk>, Error>

Submit the request and return bid/ask ticks. Pass IgnoreSize::Yes to drop tick sizes from the response.

§Examples
use ibapi::client::blocking::Client;
use ibapi::contracts::Contract;
use ibapi::market_data::IgnoreSize;
use time::macros::datetime;

let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed");
let contract = Contract::stock("TSLA").build();

let ticks = client
    .historical_ticks(&contract, 100)
    .starting(datetime!(2023-04-15 0:00 UTC))
    .bid_ask(IgnoreSize::No)
    .expect("historical ticks request failed");

for tick in ticks.iter_data() {
    println!("{:?}", tick.expect("decode error"));
}
Source§

impl<'a> HistoricalTicksBuilder<'a, Client>

Source

pub async fn trade(self) -> Result<TickSubscription<TickLast>, Error>

Submit the request and return trade ticks.

§Examples
use ibapi::prelude::*;
use time::macros::datetime;

#[tokio::main]
async fn main() {
    let client = Client::connect("127.0.0.1:4002", 100).await.expect("connection failed");
    let contract = Contract::stock("TSLA").build();

    let mut ticks = client
        .historical_ticks(&contract, 100)
        .starting(datetime!(2023-04-15 0:00 UTC))
        .trade()
        .await
        .expect("historical ticks request failed")
        .filter_data();

    while let Some(tick) = ticks.next().await {
        println!("{:?}", tick.expect("decode error"));
    }
}
Source

pub async fn mid_point(self) -> Result<TickSubscription<TickMidpoint>, Error>

Submit the request and return midpoint ticks.

§Examples
use ibapi::prelude::*;
use time::macros::datetime;

#[tokio::main]
async fn main() {
    let client = Client::connect("127.0.0.1:4002", 100).await.expect("connection failed");
    let contract = Contract::stock("TSLA").build();

    let mut ticks = client
        .historical_ticks(&contract, 100)
        .ending(datetime!(2023-04-15 0:00 UTC))
        .mid_point()
        .await
        .expect("historical ticks request failed")
        .filter_data();

    while let Some(tick) = ticks.next().await {
        println!("{:?}", tick.expect("decode error"));
    }
}
Source

pub async fn bid_ask( self, ignore_size: IgnoreSize, ) -> Result<TickSubscription<TickBidAsk>, Error>

Submit the request and return bid/ask ticks. Pass IgnoreSize::Yes to drop tick sizes from the response.

§Examples
use ibapi::prelude::*;
use ibapi::market_data::IgnoreSize;
use time::macros::datetime;

#[tokio::main]
async fn main() {
    let client = Client::connect("127.0.0.1:4002", 100).await.expect("connection failed");
    let contract = Contract::stock("TSLA").build();

    let mut ticks = client
        .historical_ticks(&contract, 100)
        .starting(datetime!(2023-04-15 0:00 UTC))
        .bid_ask(IgnoreSize::No)
        .await
        .expect("historical ticks request failed")
        .filter_data();

    while let Some(tick) = ticks.next().await {
        println!("{:?}", tick.expect("decode error"));
    }
}

Auto Trait Implementations§

§

impl<'a, C> Freeze for HistoricalTicksBuilder<'a, C>
where &'a C: Freeze,

§

impl<'a, C> RefUnwindSafe for HistoricalTicksBuilder<'a, C>

§

impl<'a, C> Send for HistoricalTicksBuilder<'a, C>
where &'a C: Send,

§

impl<'a, C> Sync for HistoricalTicksBuilder<'a, C>
where &'a C: Sync,

§

impl<'a, C> Unpin for HistoricalTicksBuilder<'a, C>
where &'a C: Unpin,

§

impl<'a, C> UnsafeUnpin for HistoricalTicksBuilder<'a, C>

§

impl<'a, C> UnwindSafe for HistoricalTicksBuilder<'a, C>

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, 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.