Skip to main content

Module util

Module util 

Source
Expand description

Shared helpers: instrument ids, timestamps, decimals.

Functions§

dec
google.type.Decimal -> [Dec], exactly: the text is parsed as it is, no f64 on the way. Empty, absent or unparseable -> None. The grammar of the message allows a sign, a leading or trailing point and an exponent.
dec0
Like dec but 0 for absent.
instrument_from_symbol
Instrument id from a Finam symbol (SBER@MISX). A symbol without @ gets an empty MIC.
money
google.type.Money -> (currency, amount), exactly. units and nanos carry the sign of the value.
no_instrument
Placeholder instrument for subscriptions that are not about one instrument (orders, account).
now_nanos
Wall clock now, in nanoseconds since the Unix epoch. Gives 0 when the clock is before the epoch.
price
dec as a [Price].
price0
dec0 as a [Price].
qty
dec as a [Qty].
qty0
dec0 as a [Qty].
symbol_of
SBER@MISX for the Finam API. Needs NativeId::SymbolMic, no network.
timestamps
Receive timestamps with the broker time attached when present.
to_decimal
A number -> google.type.Decimal, exactly. The text is plain (Rust never writes an exponent for a decimal), the scale is kept: 244.30 is sent as "244.30".
to_money
(currency, amount) -> google.type.Money, exactly. The reverse of money.
to_timestamp
Unix nanoseconds -> protobuf timestamp. Negative values give seconds < 0 and nanos >= 0, the protobuf way.
ts_nanos
Protobuf timestamp -> Unix nanoseconds. Saturates instead of overflowing on absurd values.