Skip to main content

Module ids

Module ids 

Source
Expand description

Instrument identifiers and clocks. Conversions never touch the network.

§Examples

use brokapi_core::{InstrumentId, InstrumentKey, NativeId};
use brokapi_tbank::ids::{id_from_parts, instrument_ref};

// A broker message names an instrument by uid, figi or ticker and class code.
let id = id_from_parts("uid-sber", "BBG004730N88", "SBER", "TQBR");
assert_eq!(id.key, InstrumentKey::new("SBER", "TQBR"));
// The uid wins: it does not change when a ticker is renamed.
assert_eq!(id.native, NativeId::Uid("uid-sber".into()));
// The same id as the string a request carries in `instrument_id`.
assert_eq!(instrument_ref(&id), "uid-sber");

Functions§

id_from_parts
Canonical id from the fields a broker message carries. Prefers the uid (stable across tickers).
instrument_ref
Value for the instrument_id request fields: figi, instrument_uid or ticker_classcode.
instrument_request
The directory request for an [InstrumentId]: by uid, figi, or ticker with class code.
matches
true when a broker message (identified by any of uid/figi/ticker+class) is about id.
money_of
A [MoneyValue] as [Money], exactly. The currency is ignored: read it from the message.
nanos_to_proto
Converts nanoseconds since the Unix epoch to a protobuf Timestamp. Negative times keep a non-negative nanos part, as protobuf requires.
price_of_money
A [MoneyValue] as a [Price], exactly. The currency is ignored.
price_of_quotation
A [Quotation] as a [Price], exactly (units and nano, no f64).
price_to_quotation
A [Price] as the [Quotation] a request carries, exactly.
proto_to_nanos
Converts a protobuf Timestamp to nanoseconds since the Unix epoch. Overflow saturates.
qty_of_quotation
A [Quotation] as a [Qty], exactly.
require_native
Refuses an [InstrumentId] whose [NativeId] is of another broker’s kind (SymbolMic is the Finam form), before anything is sent.
stamps
Reception timestamps with the broker time attached when the message has one.
wall_nanos
Current wall-clock time in nanoseconds since the Unix epoch.