Quickfix Send a message

Source: Internet
Author: User
Tags session id

1.1 Messages can be sent to each other in a static method Session::sendtotarget. This method uses multiple signatures:

    Send a message that already contains a beginstring, Sendercompid, and a targetcompid
    static bool Sendtotarget (Mess Age&, const std::string& qualifier = "")
        throw (sessionnotfound&);

    Send a message based on the SessionID and convenient for use
    //in Fromapp since it provides a session ID for incoming
    //messages
    static bool Sendtotarget (Message&, const sessionid&)
      throw (sessionnotfound&);

    Append a sendercompid and targetcompid before sending
    static bool Sendtotarget (Message&, const SENDERCOMPID&AM p;, const targetcompid&, const std::string& qualifier = "")
      throw (sessionnotfound&);

    Pass Sendercompid
    and targetcompid in as strings static bool Sendtotarget (Message&, const std::string&, c Onst Std::string&, const std::string& qualifier = "")
      throw (sessionnotfound&);

1.2 Creating messages

Read messages on rows, and there are several types of security levels to create messages.


1.2.1 Minimum type of safety

This individual appears in your code: ...

    void Sendordercancelrequest ()
    {
      fix::message message;
      Beginstring
      Message.getheader (). SetField (8, "fix.4.2");
      Sendercompid
      Message.getheader () SetField ("TW");
      Targetcompid, with enumeration
      Message.getheader (). SetField (Fix::field::targetcompid, "TARGET");
      Msgtype
      Message.getheader (). SetField ("F");
      Origclordid
      Message.setfield ("123");
      Clordid
      Message.setfield (one, "321");
      Symbol
      Message.setfield ("Lnux");
      Side, with value enumeration
      Message.setfield (SI, fix::side_buy);
      Text
      Message.setfield ("Cancel my order!");

      Fix::session::sendtotarget (message);
    }
1.2.2 High Type safety

We use the field class, and the code is clear and adds type safety. In addition, this is the code you use when you need to develop multiple messages or multiple versions of the fix version:

    void Sendordercancelrequest ()
    {
      fix::message message;
      Fix::header header& = Message.getheader ();

      Header.setfield (fix::beginstring ("fix.4.2"));
      Header.setfield (TW) (fix::sendercompid);
      Header.setfield (Fix::targetcompid ("TARGET"));
      Header.setfield (Fix::msgtype (fix::msgtype_ordercancelrequest));
      Message.setfield (Fix::origclordid ("123"));
      Message.setfield (Fix::clordid ("321"));
      Message.setfield (Fix::symbol ("Lnux"));
      Message.setfield (Fix::side (fix::side_buy));
      Message.setfield (Fix::text ("Cancel my order!"));

      Fix::session::sendtotarget (message);
    }
1.2.2 Highest type of security (doing so ...) )

Finally, a message class with this type of security is strongly recommended. Here, the constructor will contain all required fields, adding the correct message type and beginstring. In addition, using the Set method instead of SetField, the compiler will not allow you to increase the field of Ordercancelrequest members that are not Fix4.1. Remember: You will still be able to use SetField to force any field you want to set.

    void Sendordercancelrequest ()
    {
      fix41::ordercancelrequest message (
        fix::origclordid ("123"),
        FIX: : Clordid ("321"),
        fix::symbol ("Lnux"),
        fix::side (fix::side_buy));

      Message.set (Fix::text ("Cancel my order!"));

      Fix::session::sendtotarget (Message, Sendercompid ("TW"), Targetcompid ("TARGET"));
    



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.