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 crate::field;
use crate::tag;

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

impl QuoteRequest {
    /// Creates a new `QuoteRequest` with required fields.
    pub fn new(quote_req_id: field::QuoteReqIDField, symbol: field::SymbolField) -> Self {
        let mut msg = Message::new();
        msg.header.set_field(tag::MSG_TYPE, FIXString::from("R".to_string()));

        msg.body.set_field(tag::QUOTE_REQ_ID, quote_req_id.0);

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

        Self { message: msg }
    }

    /// Creates a `QuoteRequest` 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 `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 `OrderQty`, Tag 38.
    pub fn set_order_qty(&mut self, val: Decimal, scale: i32) {
        self.message.body.set_field(tag::ORDER_QTY, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
    }

    /// Gets `OrderQty`, Tag 38.
    pub fn get_order_qty(&self) -> Result<Decimal, MessageRejectErrorEnum> {
        let mut fld = field::OrderQtyField::new(Decimal::ZERO, 0);
        self.message.body.get_field(tag::ORDER_QTY, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `OrderQty` is present, Tag 38.
    pub fn has_order_qty(&self) -> bool {
        self.message.body.has(tag::ORDER_QTY)
    }




    /// Sets `PrevClosePx`, Tag 140.
    pub fn set_prev_close_px(&mut self, val: Decimal, scale: i32) {
        self.message.body.set_field(tag::PREV_CLOSE_PX, fixer::fix_decimal::FIXDecimal { decimal: val, scale });
    }

    /// Gets `PrevClosePx`, Tag 140.
    pub fn get_prev_close_px(&self) -> Result<Decimal, MessageRejectErrorEnum> {
        let mut fld = field::PrevClosePxField::new(Decimal::ZERO, 0);
        self.message.body.get_field(tag::PREV_CLOSE_PX, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `PrevClosePx` is present, Tag 140.
    pub fn has_prev_close_px(&self) -> bool {
        self.message.body.has(tag::PREV_CLOSE_PX)
    }




    /// 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 `Side`, Tag 54.
    pub fn set_side(&mut self, v: String) {
        self.message.body.set_field(tag::SIDE, FIXString::from(v));
    }

    /// Gets `Side`, Tag 54.
    pub fn get_side(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::SideField::new(String::new());
        self.message.body.get_field(tag::SIDE, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `Side` is present, Tag 54.
    pub fn has_side(&self) -> bool {
        self.message.body.has(tag::SIDE)
    }




    /// 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)
    }


}

/// `RouteOut` is the callback type for routing `QuoteRequest` messages.
pub type RouteOut = fn(msg: QuoteRequest, 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 `QuoteRequest`.
pub fn route(router: RouteOut) -> Route {
    let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
        router(QuoteRequest::from_message(msg.clone()), session_id)
    };
    ("FIX.4.0", "R", Box::new(r))
}