1.1消息能用靜態方法Session::sendToTarget發送給對方。這個方法用多個簽名: [cpp] // 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&); 1.2創建消息 就行讀取消息,創建消息也有幾個類型安全的層次。 1.2.1最低類型安全 這個別出現在你的代碼中:!!! [cpp] 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); } 1.2.2高類型安全 我們用field類,代碼會清晰而且增加了類型安全。另外,這個是你在需要開發多個消息或者多個版本Fix版本時用的代碼: www.2cto.com [cpp] 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); } 1.2.2最高類型安全(這麼做!!!) 最後,強烈推薦用這個類型安全的消息類。這裡,構造函數將包含所有required fields,增加正確的消息類型和BeginString 。另外,用set方法代替setField,編譯器不會讓你增加不是Fix4.1的OrderCancelRequest 成員的field。記住:你將仍能用setField來強制設置任何你想設置的field。www.2cto.com [cpp] 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")); }