Skip to main content

whole_pieces

Function whole_pieces 

pub fn whole_pieces(qty: Qty) -> Result<i64, Error>
Expand description

The order quantity as the whole number of pieces the BCS order API takes.

BCS counts an order in pieces (orderQuantity, “Количество в заявке (шт.)”, an integer of at least 1), and so does Qty everywhere in this library: the number is passed on as it is. A quantity that is not a whole number of pieces is refused, never rounded: a rounded order would buy something the caller did not ask for.

§Errors

[brokapi_core::Error::Rejected] with code invalid_qty for a fraction, zero, a negative number or a number that does not fit in an i64.

§Examples

use brokapi_bcs::map::whole_pieces;
use brokapi_core::Qty;

assert_eq!(whole_pieces(Qty::from(10))?, 10);
assert_eq!(whole_pieces("10.0".parse()?)?, 10);
// 2.5 is not rounded to 3: it is refused.
assert!(whole_pieces("2.5".parse()?).is_err());
assert!(whole_pieces("0.4".parse()?).is_err());
assert!(whole_pieces(Qty::ZERO).is_err());