fixer-fix 0.10.1

Generated FIX protocol types for fixer
Documentation
// Code generated by fixer-gen. DO NOT EDIT.
#![allow(clippy::new_without_default)]
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::too_many_arguments)]
#![allow(unused_imports)]

use fixer::message::Message;
use fixer::fix_string::FIXString;
use fixer::errors::MessageRejectErrorEnum;
use fixer::session::session_id::SessionID;

use rust_decimal::Decimal;


use jiff::Timestamp;

use crate::field;
use crate::tag;

/// `Quote` is the `fix40` `Quote` type, `MsgType` = S.
pub struct Quote {
    pub message: Message,
}

impl Quote {
    /// Creates a new `Quote` with required fields.
    pub fn new(quote_id: field::QuoteIDField, symbol: field::SymbolField, bid_px: field::BidPxField) -> Self {
        let mut msg = Message::new();
        msg.header.set_field(tag::MSG_TYPE, FIXString::from("S".to_string()));

        msg.body.set_field(tag::QUOTE_ID, quote_id.0);

        msg.body.set_field(tag::SYMBOL, symbol.0);

        msg.body.set_field(tag::BID_PX, bid_px.0);

        Self { message: msg }
    }

    /// Creates a `Quote` from an existing `Message`.
    pub fn from_message(msg: Message) -> Self {
        Self { message: msg }
    }

    /// Returns the underlying `Message`.
    pub fn to_message(self) -> Message {
        self.message
    }




    /// Sets `BidPx`, Tag 132.
    pub fn set_bid_px(&mut self, val: Decimal, scale: i32) {
        self.message.body.set_field(tag::BID_PX, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
    }

    /// Gets `BidPx`, Tag 132.
    pub fn get_bid_px(&self) -> Result<Decimal, MessageRejectErrorEnum> {
        let mut fld = field::BidPxField::new(Decimal::ZERO, 0);
        self.message.body.get_field(tag::BID_PX, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `BidPx` is present, Tag 132.
    pub fn has_bid_px(&self) -> bool {
        self.message.body.has(tag::BID_PX)
    }




    /// Sets `BidSize`, Tag 134.
    pub fn set_bid_size(&mut self, val: Decimal, scale: i32) {
        self.message.body.set_field(tag::BID_SIZE, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
    }

    /// Gets `BidSize`, Tag 134.
    pub fn get_bid_size(&self) -> Result<Decimal, MessageRejectErrorEnum> {
        let mut fld = field::BidSizeField::new(Decimal::ZERO, 0);
        self.message.body.get_field(tag::BID_SIZE, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `BidSize` is present, Tag 134.
    pub fn has_bid_size(&self) -> bool {
        self.message.body.has(tag::BID_SIZE)
    }




    /// Sets `IDSource`, Tag 22.
    pub fn set_id_source(&mut self, v: String) {
        self.message.body.set_field(tag::ID_SOURCE, FIXString::from(v));
    }

    /// Gets `IDSource`, Tag 22.
    pub fn get_id_source(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::IDSourceField::new(String::new());
        self.message.body.get_field(tag::ID_SOURCE, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `IDSource` is present, Tag 22.
    pub fn has_id_source(&self) -> bool {
        self.message.body.has(tag::ID_SOURCE)
    }




    /// Sets `Issuer`, Tag 106.
    pub fn set_issuer(&mut self, v: String) {
        self.message.body.set_field(tag::ISSUER, FIXString::from(v));
    }

    /// Gets `Issuer`, Tag 106.
    pub fn get_issuer(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::IssuerField::new(String::new());
        self.message.body.get_field(tag::ISSUER, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `Issuer` is present, Tag 106.
    pub fn has_issuer(&self) -> bool {
        self.message.body.has(tag::ISSUER)
    }




    /// Sets `OfferPx`, Tag 133.
    pub fn set_offer_px(&mut self, val: Decimal, scale: i32) {
        self.message.body.set_field(tag::OFFER_PX, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
    }

    /// Gets `OfferPx`, Tag 133.
    pub fn get_offer_px(&self) -> Result<Decimal, MessageRejectErrorEnum> {
        let mut fld = field::OfferPxField::new(Decimal::ZERO, 0);
        self.message.body.get_field(tag::OFFER_PX, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `OfferPx` is present, Tag 133.
    pub fn has_offer_px(&self) -> bool {
        self.message.body.has(tag::OFFER_PX)
    }




    /// Sets `OfferSize`, Tag 135.
    pub fn set_offer_size(&mut self, val: Decimal, scale: i32) {
        self.message.body.set_field(tag::OFFER_SIZE, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
    }

    /// Gets `OfferSize`, Tag 135.
    pub fn get_offer_size(&self) -> Result<Decimal, MessageRejectErrorEnum> {
        let mut fld = field::OfferSizeField::new(Decimal::ZERO, 0);
        self.message.body.get_field(tag::OFFER_SIZE, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `OfferSize` is present, Tag 135.
    pub fn has_offer_size(&self) -> bool {
        self.message.body.has(tag::OFFER_SIZE)
    }




    /// Sets `QuoteID`, Tag 117.
    pub fn set_quote_id(&mut self, v: String) {
        self.message.body.set_field(tag::QUOTE_ID, FIXString::from(v));
    }

    /// Gets `QuoteID`, Tag 117.
    pub fn get_quote_id(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::QuoteIDField::new(String::new());
        self.message.body.get_field(tag::QUOTE_ID, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `QuoteID` is present, Tag 117.
    pub fn has_quote_id(&self) -> bool {
        self.message.body.has(tag::QUOTE_ID)
    }




    /// Sets `QuoteReqID`, Tag 131.
    pub fn set_quote_req_id(&mut self, v: String) {
        self.message.body.set_field(tag::QUOTE_REQ_ID, FIXString::from(v));
    }

    /// Gets `QuoteReqID`, Tag 131.
    pub fn get_quote_req_id(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::QuoteReqIDField::new(String::new());
        self.message.body.get_field(tag::QUOTE_REQ_ID, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `QuoteReqID` is present, Tag 131.
    pub fn has_quote_req_id(&self) -> bool {
        self.message.body.has(tag::QUOTE_REQ_ID)
    }




    /// Sets `SecurityDesc`, Tag 107.
    pub fn set_security_desc(&mut self, v: String) {
        self.message.body.set_field(tag::SECURITY_DESC, FIXString::from(v));
    }

    /// Gets `SecurityDesc`, Tag 107.
    pub fn get_security_desc(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::SecurityDescField::new(String::new());
        self.message.body.get_field(tag::SECURITY_DESC, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `SecurityDesc` is present, Tag 107.
    pub fn has_security_desc(&self) -> bool {
        self.message.body.has(tag::SECURITY_DESC)
    }




    /// Sets `SecurityID`, Tag 48.
    pub fn set_security_id(&mut self, v: String) {
        self.message.body.set_field(tag::SECURITY_ID, FIXString::from(v));
    }

    /// Gets `SecurityID`, Tag 48.
    pub fn get_security_id(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::SecurityIDField::new(String::new());
        self.message.body.get_field(tag::SECURITY_ID, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `SecurityID` is present, Tag 48.
    pub fn has_security_id(&self) -> bool {
        self.message.body.has(tag::SECURITY_ID)
    }




    /// Sets `Symbol`, Tag 55.
    pub fn set_symbol(&mut self, v: String) {
        self.message.body.set_field(tag::SYMBOL, FIXString::from(v));
    }

    /// Gets `Symbol`, Tag 55.
    pub fn get_symbol(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::SymbolField::new(String::new());
        self.message.body.get_field(tag::SYMBOL, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `Symbol` is present, Tag 55.
    pub fn has_symbol(&self) -> bool {
        self.message.body.has(tag::SYMBOL)
    }




    /// Sets `SymbolSfx`, Tag 65.
    pub fn set_symbol_sfx(&mut self, v: String) {
        self.message.body.set_field(tag::SYMBOL_SFX, FIXString::from(v));
    }

    /// Gets `SymbolSfx`, Tag 65.
    pub fn get_symbol_sfx(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::SymbolSfxField::new(String::new());
        self.message.body.get_field(tag::SYMBOL_SFX, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `SymbolSfx` is present, Tag 65.
    pub fn has_symbol_sfx(&self) -> bool {
        self.message.body.has(tag::SYMBOL_SFX)
    }




    /// Sets `ValidUntilTime`, Tag 62.
    pub fn set_valid_until_time(&mut self, v: Timestamp) {
        self.message.body.set_field(tag::VALID_UNTIL_TIME, fixer::fix_utc_timestamp::FIXUTCTimestamp {
            time: v,
            precision: fixer::fix_utc_timestamp::TimestampPrecision::Millis,
        });
    }

    /// Gets `ValidUntilTime`, Tag 62.
    pub fn get_valid_until_time(&self) -> Result<Timestamp, MessageRejectErrorEnum> {
        let mut fld = field::ValidUntilTimeField::new(Timestamp::UNIX_EPOCH);
        self.message.body.get_field(tag::VALID_UNTIL_TIME, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `ValidUntilTime` is present, Tag 62.
    pub fn has_valid_until_time(&self) -> bool {
        self.message.body.has(tag::VALID_UNTIL_TIME)
    }


}

/// `RouteOut` is the callback type for routing `Quote` messages.
pub type RouteOut = fn(msg: Quote, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;

/// Route type returned by the `route` function.
pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);

/// Returns the begin string, message type, and route function for `Quote`.
pub fn route(router: RouteOut) -> Route {
    let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
        router(Quote::from_message(msg.clone()), session_id)
    };
    ("FIX.4.0", "S", Box::new(r))
}