brokapi_tbank/map/mod.rs
1//! T-Bank protocol messages -> `brokapi-core` domain types.
2//!
3//! Units. T-Bank counts orders, order book levels, trades and candle volumes in LOTS and prices per
4//! one instrument (not per lot). The library counts in units of the instrument, so the functions here
5//! that read a quantity in lots take the lot size and return units (`OrderParts::with_lot`, the `lot`
6//! argument of `stop::snapshot`), and the connectors scale the market data (`crate::lots`). Own trades
7//! (`OrderTrade.quantity`, the history) and portfolio positions (`Quotation`) are in pieces already,
8//! and are kept as they are. `Timeframe::MN` is 30 days when a candle close time has to be derived.
9//!
10//! Every function here is pure: it takes broker messages and returns domain types, with no network
11//! and no state. That makes them cheap to test and safe to call from anywhere. The connectors use
12//! them for you. Use them yourself when you read raw messages (for example through
13//! [`TbankRaw`](crate::TbankRaw)) and want the same domain types.
14//!
15//! # Examples
16//!
17//! ```
18//! use brokapi_tbank::map::market::{levels, wire_depth};
19//! use brokapi_tbank_protocol::money::quotation;
20//! use brokapi_tbank_protocol::v1::Order;
21//!
22//! // Depth 15 is sent as 20: the broker accepts 1, 10, 20, 30, 40, 50.
23//! assert_eq!(wire_depth(15), 20);
24//!
25//! // Book levels come out best first: bids by price descending.
26//! let bids = [
27//! Order { price: Some(quotation("273")), quantity: 5 },
28//! Order { price: Some(quotation("274")), quantity: 9 },
29//! ];
30//! let top = levels(&bids, true, 1);
31//! assert_eq!(top[0].price, "274".parse()?);
32//! # Ok::<(), brokapi_core::NumberError>(())
33//! ```
34
35pub mod execution;
36pub mod instrument;
37pub mod market;
38pub mod order;
39pub mod portfolio;
40pub mod schedule;
41pub mod stop;