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
impl PriceGrid
Sourcepub fn set(&self, key: InstrumentKey, step: Price)
pub fn set(&self, key: InstrumentKey, step: Price)
Remembers the price step of an instrument. A step of zero or below forgets it.
Sourcepub fn learn(&self, params: &TradingParams)
pub fn learn(&self, params: &TradingParams)
Remembers the price step and the lot size from the trading parameters of an instrument.
Sourcepub fn set_lot(&self, key: InstrumentKey, lot: Qty)
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.
Sourcepub fn lot(&self, key: &InstrumentKey) -> Option<Qty>
pub fn lot(&self, key: &InstrumentKey) -> Option<Qty>
The lot size of an instrument, if it is known.
Sourcepub fn check_qty(&self, key: &InstrumentKey, qty: Qty) -> Result<(), Error>
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.