Skip to main content

IbPriceConverter

Struct IbPriceConverter 

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

Converts the prices IB reports for an instrument into the instrument’s prices.

IB reports a magnified contract’s prices in a sub-unit of its currency (CBOT grains in cents, LSE stocks in pence), so these are divided by the contract’s price magnifier. IB also reports an FX pair’s prices in steps finer than the pair’s price increment, its order tick, so these are rounded to the increment: a bid down, an ask up, and any other price to the nearest, ties to the even multiple. A quote then never locks or crosses unless IB’s did, and an ask is never below IB’s ask.

Implementations§

Source§

impl IbPriceConverter

Source

pub const fn new(precision: u8) -> Self

Creates a converter that applies the precision only, with no magnifier and no rounding to an increment.

Source

pub const fn with_price_magnifier(self, magnifier: i32) -> Self

Returns the converter with the contract’s price magnifier, where a value below 1 means 1.

Source

pub fn for_instrument(instrument: &InstrumentAny, price_magnifier: i32) -> Self

Creates the converter for instrument and its contract’s price_magnifier, rounding to the price increment for FX pairs.

Source

pub const fn precision(&self) -> u8

Returns the price precision.

Source

pub fn is_sentinel(&self, ib_price: f64, size: Option<f64>) -> bool

Returns whether ib_price is IB’s no-quote value for a side: -1 without a size, which IB reports multiplied by the price magnifier for a magnified contract (-100 for a ZC option on delayed data).

Source

pub fn price(&self, ib_price: f64) -> Result<Price>

Converts a price reported by IB into the instrument’s price, rounding to the nearest multiple of the price increment, ties to the even multiple.

Use this for a trade, midpoint, last, or index price. A quote’s bid and ask use Self::bid_price and Self::ask_price.

§Errors

Returns an error if the price is not finite or cannot be represented at the converter’s precision.

Source

pub fn bid_price(&self, ib_price: f64) -> Result<Price>

Converts a bid price reported by IB, rounding down to a multiple of the price increment.

A published bid is never above IB’s bid.

§Errors

Returns an error if the price is not finite or cannot be represented at the converter’s precision.

Source

pub fn ask_price(&self, ib_price: f64) -> Result<Price>

Converts an ask price reported by IB, rounding up to a multiple of the price increment.

A published ask is never below IB’s ask, so a limit order priced at it can fill, and the published bid stays below the published ask whenever IB’s does.

§Errors

Returns an error if the price is not finite or cannot be represented at the converter’s precision.

Source

pub fn bar_price(&self, price_type: PriceType, ib_price: f64) -> Result<Price>

Converts a price of a bar of price_type: a bid bar rounds down, an ask bar rounds up, and any other bar to the nearest multiple of the price increment.

§Errors

Returns an error if the price is not finite or cannot be represented at the converter’s precision.

Trait Implementations§

Source§

impl Clone for IbPriceConverter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for IbPriceConverter

Source§

impl Debug for IbPriceConverter

Source§

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

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

impl Eq for IbPriceConverter

Source§

impl PartialEq for IbPriceConverter

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for IbPriceConverter

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> DynEq for T
where T: Eq + Any,

§

fn dyn_eq(&self, other: &(dyn Any + 'static)) -> bool

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more