Skip to main content

PriceGrid

Struct PriceGrid 

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

The price step of each instrument the connector was told about.

A connector that sends orders refuses a price that is not a whole number of steps before it sends anything: the error is [Error::Rejected] with the code price_off_step, no quota is spent and the cid stays unused. An instrument whose step is not known passes unchecked: the broker decides then. The grid starts empty. Fill it from [TradingParams], which you read once per instrument with InstrumentSource::trading_params.

The grid also keeps the lot size of an instrument. Quantities are in units of the instrument at every broker (see [Qty]), and an exchange trades whole lots, so a quantity that is not a whole number of lots is refused the same way, before anything is sent: [Error::Rejected] with the code invalid_qty. An instrument whose lot is not known passes unchecked (the T-Bank connector looks the lot up itself, it does not need the grid for that).

The handle is cheap to clone, and all clones are one grid: share it between the connectors of one broker.

§Examples

use brokapi_core::{Decimal, InstrumentKey, Price, dec};
use brokapi_runtime::PriceGrid;

let grid = PriceGrid::default();
let sber = InstrumentKey::new("SBER", "TQBR");

// The step is not known yet: the check passes.
assert!(grid.check(&sber, Price::new(dec!(244.307))).is_ok());

grid.set(sber.clone(), Price::new(dec!(0.01)));
assert!(grid.check(&sber, Price::new(dec!(244.30))).is_ok());
assert!(grid.check(&sber, Price::new(dec!(244.307))).is_err());

Implementations§

Source§

impl PriceGrid

Source

pub fn set(&self, key: InstrumentKey, step: Price)

Remembers the price step of an instrument. A step of zero or below forgets it.

Source

pub fn learn(&self, params: &TradingParams)

Remembers the price step and the lot size from the trading parameters of an instrument.

Source

pub fn set_lot(&self, key: InstrumentKey, lot: Qty)

Remembers the lot size (units of the instrument in one lot). A size of zero or below forgets it.

Source

pub fn lot(&self, key: &InstrumentKey) -> Option<Qty>

The lot size of an instrument, if it is known.

Source

pub fn check_qty(&self, key: &InstrumentKey, qty: Qty) -> Result<(), Error>

Checks an order quantity against the lot size of the instrument.

§Errors

[Error::Rejected] with the code invalid_qty when the quantity is not positive, or when the lot size is known and the quantity is not a whole number of lots.

Source

pub fn step(&self, key: &InstrumentKey) -> Option<Price>

The step of an instrument, if it is known.

Source

pub fn check(&self, key: &InstrumentKey, price: Price) -> Result<(), Error>

Checks a price against the step of the instrument.

§Errors

[Error::Rejected] with the code price_off_step when the step is known and the price is not a whole number of steps.

Trait Implementations§

Source§

impl Clone for PriceGrid

Source§

fn clone(&self) -> PriceGrid

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 Debug for PriceGrid

Source§

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

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

impl Default for PriceGrid

Source§

fn default() -> PriceGrid

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.

§

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

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