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
impl IbPriceConverter
Sourcepub const fn new(precision: u8) -> Self
pub const fn new(precision: u8) -> Self
Creates a converter that applies the precision only, with no magnifier and no rounding to an increment.
Sourcepub const fn with_price_magnifier(self, magnifier: i32) -> Self
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.
Sourcepub fn for_instrument(instrument: &InstrumentAny, price_magnifier: i32) -> Self
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.
Sourcepub fn is_sentinel(&self, ib_price: f64, size: Option<f64>) -> bool
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).
Sourcepub fn price(&self, ib_price: f64) -> Result<Price>
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.
Sourcepub fn bid_price(&self, ib_price: f64) -> Result<Price>
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.
Sourcepub fn ask_price(&self, ib_price: f64) -> Result<Price>
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.
Sourcepub fn bar_price(&self, price_type: PriceType, ib_price: f64) -> Result<Price>
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
impl Clone for IbPriceConverter
impl Copy for IbPriceConverter
Source§impl Debug for IbPriceConverter
impl Debug for IbPriceConverter
impl Eq for IbPriceConverter
Source§impl PartialEq for IbPriceConverter
impl PartialEq for IbPriceConverter
impl StructuralPartialEq for IbPriceConverter
Auto Trait Implementations§
impl Freeze for IbPriceConverter
impl RefUnwindSafe for IbPriceConverter
impl Send for IbPriceConverter
impl Sync for IbPriceConverter
impl Unpin for IbPriceConverter
impl UnsafeUnpin for IbPriceConverter
impl UnwindSafe for IbPriceConverter
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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