Sending Messages

Messages can be sent to a counter party with the static Session::sendToTarget methods.

See this code in PYTHON, RUBY

    // send a message that already contains a BeginString, SenderCompID, and a TargetCompID
    static bool sendToTarget( Message&, const std::string& qualifier = "" )
      throw(SessionNotFound&);

    // send a message based on the sessionID, 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&, const TargetCompID&, const std::string& qualifier = "" )
      throw(SessionNotFound&);

    // pass SenderCompID and TargetCompID in as strings
    static bool sendToTarget( Message&, const std::string&, const std::string&, const std::string& qualifier = "" )
      throw(SessionNotFound&);

## Type Safe Messages And Fields

Message constructors take in all required fields and adds the correct MsgType and BeginString for you. With the set method, the compiler will not let you add a field that is not a part of a message as defined by the spec.

    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"));
    }

## Type Safe Field Only

The setField method allows you to add any field to any message.

See this code in PYTHON, RUBY

    void sendOrderCancelRequest()
    {
      FIX::Message message;
      FIX::Header header& = message.getHeader();

      header.setField(FIX::BeginString("FIX.4.2"));
      header.setField(FIX::SenderCompID(TW));
      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);
    }

## No Type Safety

You can also use setField to pass in primitives.

See this code in PYTHON, RUBY

    void sendOrderCancelRequest()
    {
      FIX::Message message;
      // BeginString
      message.getHeader().setField(8, "FIX.4.2");
      // SenderCompID
      message.getHeader().setField(49, "TW");
      // TargetCompID, with enumeration
      message.getHeader().setField(FIX::FIELD::TargetCompID, "TARGET");
      // MsgType
      message.getHeader().setField(35, 'F');
      // OrigClOrdID
      message.setField(41, "123");
      // ClOrdID
      message.setField(11, "321");
      // Symbol
      message.setField(55, "LNUX");
      // Side, with value enumeration
      message.setField(54, FIX::Side_BUY);
      // Text
      message.setField(58, "Cancel My Order!");

      FIX::Session::sendToTarget(message);
    }