Skip to main content

require_ticker_class

Function require_ticker_class 

pub fn require_ticker_class(id: &InstrumentId) -> Result<InstrumentKey, Error>
Expand description

Returns the BCS instrument key (ticker and class code) of an instrument id.

BCS names an instrument by ticker plus trading board (class code), for example SBER on TQBR.

§Errors

[brokapi_core::Error::Config] when the native id of id is not [NativeId::TickerClass]. An id that came from another broker cannot be used here.

§Examples

use brokapi_bcs::util::require_ticker_class;
use brokapi_core::{InstrumentId, InstrumentKey, NativeId};

let sber = InstrumentId::new(
    InstrumentKey::new("SBER", "TQBR"),
    NativeId::TickerClass { ticker: "SBER".into(), class_code: "TQBR".into() },
);
assert_eq!(require_ticker_class(&sber).unwrap().class_code, "TQBR");

let foreign = InstrumentId::new(InstrumentKey::new("SBER", "MISX"), NativeId::Uid("uid".into()));
assert!(require_ticker_class(&foreign).is_err());