pub struct PitSymbolMap(/* private fields */);Expand description
A point-in-time symbol map. Useful for working with live symbology or a historical request over a single day or other situations where the symbol mappings are known not to change.
Commonly built with Metadata::symbol_map_for_date(). For live data, call
on_record() with each incoming record to keep the map
updated as symbol mappings arrive.
§Examples
Single-day historical usage:
use dbn::{
decode::{DbnDecoder, DecodeRecord, DbnMetadata},
pretty,
symbol_map::SymbolIndex,
Mbp1Msg,
};
let mut decoder = DbnDecoder::from_zstd_file("mbp1.dbn.zst")?;
let date = decoder.metadata().start().date();
let symbol_map = decoder.metadata().symbol_map_for_date(date)?;
while let Some(mbp) = decoder.decode_record::<Mbp1Msg>()? {
if let Some(symbol) = symbol_map.get_for_rec(mbp) {
println!(
"{symbol}: bid={} ask={}",
pretty::Px(mbp.levels[0].bid_px),
pretty::Px(mbp.levels[0].ask_px)
);
} else {
eprintln!("Missing symbol for {mbp:?}")
}
}Implementations§
Source§impl PitSymbolMap
impl PitSymbolMap
Sourcepub fn from_metadata(metadata: &Metadata, date: Date) -> Result<Self>
pub fn from_metadata(metadata: &Metadata, date: Date) -> Result<Self>
Creates a new PitSymbolMap populated with the mappings from metadata for
date.
§Errors
This function returns an error if neither stype_in or stype_out are
SType::InstrumentId. It will also return an
error if it can’t parse a symbol into u32 instrument ID or if date is
outside the query range of the metadata.
Sourcepub fn on_record(&mut self, record: RecordRef<'_>) -> Result<()>
pub fn on_record(&mut self, record: RecordRef<'_>) -> Result<()>
Handles updating the mappings (if required) for a generic record.
§Errors
This function returns an error when record contains a symbol mapping
with invalid UTF-8.
Sourcepub fn on_symbol_mapping<S: SymbolMappingRec>(
&mut self,
symbol_mapping: &S,
) -> Result<()>
pub fn on_symbol_mapping<S: SymbolMappingRec>( &mut self, symbol_mapping: &S, ) -> Result<()>
Handles updating the mappings from a symbol mapping record.
§Errors
This function returns an error if the symbol contains invalid UTF-8.
Sourcepub fn on_instrument_def<D: InstrumentDefRec>(
&mut self,
instrument_def: &D,
) -> Result<()>
pub fn on_instrument_def<D: InstrumentDefRec>( &mut self, instrument_def: &D, ) -> Result<()>
Handles updating the mappings from an instrument definition record.
§Errors
This function returns an error if the symbol contains invalid UTF-8.
Trait Implementations§
Source§impl Clone for PitSymbolMap
impl Clone for PitSymbolMap
Source§fn clone(&self) -> PitSymbolMap
fn clone(&self) -> PitSymbolMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more