#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{Decimal, Instances, InvalidValue, LazyKnownTags, RawMessage, Tag};
use super::super::components::{
Header, InstrmtLegGrp, Instrument, InstrumentExtension, Trailer, UndInstrmtGrp,
};
use super::super::enums::{ExpirationCycle, SecurityResponseType};
pub struct SecurityDefinition(RawMessage);
impl SecurityDefinition {
pub const MSG_TYPE: &[u8] = b"d";
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[
Tag(320), Tag(322), Tag(323), Tag(711), Tag(15), Tag(336), Tag(625), Tag(58),
Tag(354), Tag(355), Tag(555), Tag(827), Tag(561), Tag(562),
],
&[
Header::known_tags(), Trailer::known_tags(), Instrument::known_tags(),
InstrumentExtension::known_tags(), UndInstrmtGrp::known_tags(),
InstrmtLegGrp::known_tags(),
],
);
&TAGS
}
pub fn from_raw(raw: RawMessage) -> Self {
Self(raw)
}
pub fn raw(&self) -> &RawMessage {
&self.0
}
pub fn header(&self) -> Header<'_> {
Header(self.0.scope(), Self::known_tags().get())
}
pub fn trailer(&self) -> Trailer<'_> {
Trailer(self.0.scope())
}
#[doc(alias = "SecurityReqID")]
pub fn security_req_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(320))
}
#[doc(alias = "SecurityResponseID")]
pub fn security_response_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(322))
}
#[doc(alias = "SecurityResponseType")]
pub fn security_response_type(&self) -> Result<Option<SecurityResponseType>, InvalidValue> {
Ok(self.0.get_int(Tag(323))?.map(SecurityResponseType::from_value))
}
pub fn instrument(&self) -> Instrument<'_> {
Instrument(self.0.scope(), Self::known_tags().get())
}
pub fn instrument_extension(&self) -> InstrumentExtension<'_> {
InstrumentExtension(self.0.scope(), Self::known_tags().get())
}
#[doc(alias = "NoUnderlyings")]
pub fn underlyings(&self) -> Result<Instances<'_, UndInstrmtGrp<'_>>, InvalidValue> {
self.0.get_group(&UndInstrmtGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "Currency")]
pub fn currency(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(15))
}
#[doc(alias = "TradingSessionID")]
pub fn trading_session_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(336))
}
#[doc(alias = "TradingSessionSubID")]
pub fn trading_session_sub_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(625))
}
#[doc(alias = "Text")]
pub fn text(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(58))
}
#[doc(alias = "EncodedTextLen")]
pub fn encoded_text_len(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(354))
}
#[doc(alias = "EncodedText")]
pub fn encoded_text(&self) -> Option<&[u8]> {
self.0.get(Tag(355))
}
#[doc(alias = "NoLegs")]
pub fn legs(&self) -> Result<Instances<'_, InstrmtLegGrp<'_>>, InvalidValue> {
self.0.get_group(&InstrmtLegGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "ExpirationCycle")]
pub fn expiration_cycle(&self) -> Result<Option<ExpirationCycle>, InvalidValue> {
Ok(self.0.get_int(Tag(827))?.map(ExpirationCycle::from_value))
}
#[doc(alias = "RoundLot")]
pub fn round_lot(&self) -> Result<Option<Decimal>, InvalidValue> {
self.0.get_decimal(Tag(561))
}
#[doc(alias = "MinTradeVol")]
pub fn min_trade_vol(&self) -> Result<Option<Decimal>, InvalidValue> {
self.0.get_decimal(Tag(562))
}
}
impl std::fmt::Debug for SecurityDefinition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SecurityDefinition({})", self.0)
}
}
impl std::fmt::Display for SecurityDefinition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}