Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

【QuickFIX】05 各種メッセージの枠を作成

サーバとのやりとりを行う各種メッセージの「枠」をとりあえず作成
組み込んでおきます

CNEXの仕様書にのみあって、quickfix に無いメッセージもあるので
それについてはヘッダーファイルから作成

受信メッセージ用

16メッセージ
 CG PartyDetailsListReport と
 PU OrderRateUpdate は標準ではなかったのでヘッダーも作成

resp_8__ExecutionReport.cpp
resp_9__OrderCancelReject.cpp
resp_AO_RequestForPositionsAck.cpp
resp_AP_PositionReport.cpp
resp_AZ_CollateralResponse.cpp
resp_BA_CollateralReport.cpp
resp_CG_PartyDetailsListReport.cpp
resp_CG_PartyDetailsListReport.h
resp_C__Email.cpp
resp_N__ListStatus.cpp
resp_PU_OrderRateUpdate.cpp
resp_PU_OrderRateUpdate.h
resp_X__MarketDataIncrementalRefresh.cpp
resp_Y__MarketDataRequestReject.cpp
resp_h__TradingSessionStatus.cpp
resp_j__BusinessMessageReject.cpp
resp_r__OrderMassCancelReport.cpp
resp_y__SecurityList.cpp

送信メッセージ用

10メッセージ

send_1__TestRequest.cpp
send_AF_OrderMassStatusRequest.cpp
send_AN_RequestForPositions.cpp
send_D__NewOrderSingle.cpp
send_F__OrderCancelRequest.cpp
send_G__OrderCancelReplaceRequest.cpp
send_H__OrderStatusRequest.cpp
send_V__MarketDataRequest.cpp
send_q__OrderMassCancelRequest.cpp
send_x__SecurityListRequest.cpp

Applicationヘッダーファイル(差分)

examples/tradeclient/Application.h
@@ -8,6 +8,35 @@

 #include "quickfix/MySQLConnection.h"

+#include "quickfix/fix44/TestRequest.h"                     // send < 1 >
+#include "quickfix/fix44/OrderMassCancelRequest.h"          // send < q >
+#include "quickfix/fix44/SecurityListRequest.h"             // send < x >
+#include "quickfix/fix44/NewOrderSingle.h"                  // send < D >
+#include "quickfix/fix44/OrderCancelRequest.h"              // send < F >
+#include "quickfix/fix44/OrderCancelReplaceRequest.h"       // send < G >
+#include "quickfix/fix44/OrderStatusRequest.h"              // send < H >
+#include "quickfix/fix44/MarketDataRequest.h"               // send < V >
+#include "quickfix/fix44/OrderMassStatusRequest.h"          // send < AF >
+#include "quickfix/fix44/RequestForPositions.h"             // send < AN >
+
+#include "quickfix/fix44/ExecutionReport.h"                 // resp < 8 >
+#include "quickfix/fix44/OrderCancelReject.h"               // resp < 9 >
+#include "quickfix/fix44/TradingSessionStatus.h"            // resp < h >
+#include "quickfix/fix44/BusinessMessageReject.h"           // resp < j >
+#include "quickfix/fix44/OrderMassCancelReport.h"           // resp < r >
+#include "quickfix/fix44/SecurityList.h"                    // resp < y >
+#include "quickfix/fix44/Email.h"                           // resp < C >
+#include "quickfix/fix44/ListStatus.h"                      // resp < N >
+#include "quickfix/fix44/MarketDataIncrementalRefresh.h"    // resp < X >
+#include "quickfix/fix44/MarketDataRequestReject.h"         // resp < Y >
+#include "quickfix/fix44/RequestForPositionsAck.h"          // resp < AO >
+#include "quickfix/fix44/PositionReport.h"                  // resp < AP >
+#include "quickfix/fix44/CollateralResponse.h"              // resp < AZ >
+#include "quickfix/fix44/CollateralReport.h"                // resp < BA >
+
+#include "resp_CG_PartyDetailsListReport.h"                 // resp < CG >
+#include "resp_PU_OrderRateUpdate.h"                        // resp < PU >
+
 #include <queue>
 #include <vector>
 #include <map>
@@ -68,6 +97,34 @@ private:
   void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
   throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType );

+  /* 8  */ void onMessage( const FIX44::ExecutionReport&,              const FIX::SessionID& );
+  /* 9  */ void onMessage( const FIX44::OrderCancelReject&,            const FIX::SessionID& );
+  /* h  */ void onMessage( const FIX44::TradingSessionStatus&,         const FIX::SessionID& );
+  /* j  */ void onMessage( const FIX44::BusinessMessageReject&,        const FIX::SessionID& );
+  /* r  */ void onMessage( const FIX44::OrderMassCancelReport&,        const FIX::SessionID& );
+  /* y  */ void onMessage( const FIX44::SecurityList&,                 const FIX::SessionID& );
+  /* C  */ void onMessage( const FIX44::Email&,                        const FIX::SessionID& );
+  /* N  */ void onMessage( const FIX44::ListStatus&,                   const FIX::SessionID& );
+  /* X  */ void onMessage( const FIX44::MarketDataIncrementalRefresh&, const FIX::SessionID& );
+  /* Y  */ void onMessage( const FIX44::MarketDataRequestReject&,      const FIX::SessionID& );
+  /* AO */ void onMessage( const FIX44::RequestForPositionsAck&,       const FIX::SessionID& );
+  /* AP */ void onMessage( const FIX44::PositionReport&,               const FIX::SessionID& );
+  /* AZ */ void onMessage( const FIX44::CollateralResponse&,           const FIX::SessionID& );
+  /* BA */ void onMessage( const FIX44::CollateralReport&,             const FIX::SessionID& );
+  /* CG */ void onMessage( const FIX44::PartyDetailsListReport&,       const FIX::SessionID& );
+  /* PU */ void onMessage( const FIX44::OrderRateUpdate&,              const FIX::SessionID& );
+
+  /* 1  */ void TestRequest( const char* );
+  /* q  */ void OrderMassCancelRequest();
+  /* x  */ void SecurityListRequest();
+  /* D  */ void NewOrderSingle();
+  /* F  */ void OrderCancelRequest();
+  /* G  */ void OrderCancelReplaceRequest();
+  /* H  */ void OrderStatusRequest();
+  /* V  */ void MarketDataRequest();
+  /* AF */ void OrderMassStatusRequest();
+  /* AN */ void RequestForPositions();
+
   void SetMessageHeader( FIX::Message&, const char* = SessionTypeTrade );
   FIX::MySQLConnection *MySQLConnect();
   std::string getSetting( const char* );

追加したヘッダーを読み込んで、各命令の呼び出し宣言しときます

Makefile.am(追加したファイルを追記)

examples/tradeclient/Makefile.am
noinst_PROGRAMS = tradeclient

tradeclient_SOURCES = \
        tradeclient.cpp \
        Application.h \
        Application.cpp \
        resp_8__ExecutionReport.cpp \
        resp_9__OrderCancelReject.cpp \
        resp_AO_RequestForPositionsAck.cpp \
        resp_AP_PositionReport.cpp \
        resp_AZ_CollateralResponse.cpp \
        resp_BA_CollateralReport.cpp \
        resp_CG_PartyDetailsListReport.cpp \
        resp_CG_PartyDetailsListReport.h \
        resp_C__Email.cpp \
        resp_N__ListStatus.cpp \
        resp_PU_OrderRateUpdate.cpp \
        resp_PU_OrderRateUpdate.h \
        resp_X__MarketDataIncrementalRefresh.cpp \
        resp_Y__MarketDataRequestReject.cpp \
        resp_h__TradingSessionStatus.cpp \
        resp_j__BusinessMessageReject.cpp \
        resp_r__OrderMassCancelReport.cpp \
        resp_y__SecurityList.cpp \
        send_1__TestRequest.cpp \
        send_AF_OrderMassStatusRequest.cpp \
        send_AN_RequestForPositions.cpp \
        send_D__NewOrderSingle.cpp \
        send_F__OrderCancelRequest.cpp \
        send_G__OrderCancelReplaceRequest.cpp \
        send_H__OrderStatusRequest.cpp \
        send_V__MarketDataRequest.cpp \
        send_q__OrderMassCancelRequest.cpp \
        send_x__SecurityListRequest.cpp

tradeclient_LDADD = $(top_builddir)/src/C++/libquickfix.la

INCLUDES = -I$(top_builddir)/include -I..

all-local:
        rm -f ../../bin/tradeclient
        ln -s ../examples/tradeclient/tradeclient ../../bin/tradeclient

追加メッセージ受信用(枠だけ)

< 8 > ExecutionReport

resp_8__ExecutionReport.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* 8  */
void Application::onMessage(const FIX44::ExecutionReport& message, const FIX::SessionID& sessionID )
{
  std::cout << "<8> ExecutionReport: " << std::endl << message.toXML() << std::endl;
}

< 9 > OrderCancelReject

resp_9__OrderCancelReject.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* 9  */
void Application::onMessage(const FIX44::OrderCancelReject& message, const FIX::SessionID& sessionID )
{
  std::cout << "<9> OrderCancelReject: " << std::endl << message.toXML() << std::endl;
}

< AO > RequestForPositionsAck

resp_AO_RequestForPositionsAck.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* AO  */
void Application::onMessage(const FIX44::RequestForPositionsAck& message, const FIX::SessionID& sessionID )
{
  std::cout << "<AO> RequestForPositionsAck: " << std::endl << message.toXML() << std::endl;
}

< AP > PositionReport

resp_AP_PositionReport.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* AP */
void Application::onMessage(const FIX44::PositionReport& message, const FIX::SessionID& sessionID )
{
  std::cout << "<AP> PositionReport: " << std::endl << message.toXML() << std::endl;
}

< AZ > CollateralResponse

resp_AZ_CollateralResponse.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* AZ */
void Application::onMessage(const FIX44::CollateralResponse& message, const FIX::SessionID& sessionID )
{
  std::cout << "<AZ> CollateralResponse: " << std::endl << message.toXML() << std::endl;
}

< BA > CollateralReport

resp_BA_CollateralReport.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* BA */
void Application::onMessage(const FIX44::CollateralReport& message, const FIX::SessionID& sessionID )
{
  std::cout << "<BA> CollateralReport: " << std::endl << message.toXML() << std::endl;
}

< CG > PartyDetailsListReport

resp_CG_PartyDetailsListReport.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* CG  */
void Application::onMessage(const FIX44::PartyDetailsListReport& message, const FIX::SessionID& sessionID )
{
  std::cout << "<CG> PartyDetailsListReport: " << std::endl << message.toXML() << std::endl;
}
resp_CG_PartyDetailsListReport.h
#include "quickfix/Message.h"

namespace FIX44
{

  class PartyDetailsListReport : public Message
  {
  public:
    PartyDetailsListReport() : Message(MsgType()) {}
    PartyDetailsListReport(const FIX::Message& m) : Message(m) {}
    PartyDetailsListReport(const Message& m) : Message(m) {}
    PartyDetailsListReport(const PartyDetailsListReport& m) : Message(m) {}
    static FIX::MsgType MsgType() { return FIX::MsgType("CG"); }

    PartyDetailsListReport(
      const FIX::PartyDetailsListReportID& aPartyDetailsListReportID ,
      const FIX::PartyDetailsListRequestID& aPartyDetailsListRequestID ,
      const FIX::PartyDetailsRequestResult& aPartyDetailsRequestResult)
    : Message(MsgType())
    {
      set(aPartyDetailsListReportID);
      set(aPartyDetailsListRequestID);
      set(aPartyDetailsRequestResult);
    }

    FIELD_SET(*this, FIX::PartyDetailsListReportID);
    FIELD_SET(*this, FIX::PartyDetailsListRequestID);
    FIELD_SET(*this, FIX::PartyDetailsRequestResult);
    FIELD_SET(*this, FIX::TotNumReports);
    FIELD_SET(*this, FIX::PartyDetailsType);
    FIELD_SET(*this, FIX::TransactTime);
    FIELD_SET(*this, FIX::Text);
    FIELD_SET(*this, FIX::NoPartyList);
    class NoPartyList: public FIX::Group
    {
    public:
    NoPartyList() : FIX::Group(1513,448,FIX::message_order(448,447,452,0)) {}
      FIELD_SET(*this, FIX::PartyID);
      FIELD_SET(*this, FIX::PartyIDSource);
      FIELD_SET(*this, FIX::PartyRole);
    };
  };

}

< C > Email

resp_C__Email.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* C  */
void Application::onMessage(const FIX44::Email& message, const FIX::SessionID& sessionID )
{
  std::cout << "<C> Email: " << std::endl << message.toXML() << std::endl;
}

< N > ListStatus

resp_N__ListStatus.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* N  */
void Application::onMessage(const FIX44::ListStatus& message, const FIX::SessionID& sessionID )
{
  std::cout << "<N> ListStatus: " << std::endl << message.toXML() << std::endl;
}

< PU > OrderRateUpdate

resp_PU_OrderRateUpdate.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* PU */
void Application::onMessage(const FIX44::OrderRateUpdate& message, const FIX::SessionID& sessionID )
{
  std::cout << "<PU> OrderRateUpdate: " << std::endl << message.toXML() << std::endl;
}
resp_PU_OrderRateUpdate.h
#include "quickfix/Message.h"

namespace FIX44
{

  class OrderRateUpdate : public Message
  {
  public:
    OrderRateUpdate() : Message(MsgType()) {}
    OrderRateUpdate(const FIX::Message& m) : Message(m) {}
    OrderRateUpdate(const Message& m) : Message(m) {}
    OrderRateUpdate(const OrderRateUpdate& m) : Message(m) {}
    static FIX::MsgType MsgType() { return FIX::MsgType("PU"); }

    OrderRateUpdate(
      const FIX::OrderID& aOrderID ,
      const FIX::ClOrdID& aClOrdID ,
      const FIX::OrigClOrdID& aOrigClOrdID ,
      const FIX::OrdType& aOrdType )
    : Message(MsgType())
    {
      set(aOrderID);
      set(aClOrdID);
      set(aOrigClOrdID);
      set(aOrdType);
    }

    FIELD_SET(*this, FIX::OrderID);
    FIELD_SET(*this, FIX::ClOrdID);
    FIELD_SET(*this, FIX::OrigClOrdID);
    FIELD_SET(*this, FIX::OrdType);
    FIELD_SET(*this, FIX::StopPx);
    FIELD_SET(*this, FIX::NoPartyIDs);
    class NoPartyIDs: public FIX::Group
    {
    public:
    NoPartyIDs() : FIX::Group(453,448,FIX::message_order(448,452,0)) {}
      FIELD_SET(*this, FIX::PartyID);
      FIELD_SET(*this, FIX::PartyRole);
    };
  };

}

< X > MarketDataIncrementalRefresh

resp_X__MarketDataIncrementalRefresh.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* X  */
void Application::onMessage(const FIX44::MarketDataIncrementalRefresh& message, const FIX::SessionID& sessionID )
{
  std::cout << "<X> MarketDataIncrementalRefresh: " << std::endl << message.toXML() << std::endl;
}

< Y > MarketDataRequestReject

resp_Y__MarketDataRequestReject.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* Y  */
void Application::onMessage(const FIX44::MarketDataRequestReject& message, const FIX::SessionID& sessionID )
{
  std::cout << "<Y> MarketDataRequestReject: " << std::endl << message.toXML() << std::endl;
}

< h > TradingSessionStatus

resp_h__TradingSessionStatus.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* h  */
void Application::onMessage(const FIX44::TradingSessionStatus& message, const FIX::SessionID& sessionID )
{
  std::cout << "<h> TradingSessionStatus: " << std::endl << message.toXML() << std::endl;
}

< j > BusinessMessageReject

resp_j__BusinessMessageReject.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* j  */
void Application::onMessage(const FIX44::BusinessMessageReject& message, const FIX::SessionID& sessionID )
{
  std::cout << "<j> BusinessMessageReject: " << std::endl << message.toXML() << std::endl;
}

< r > OrderMassCancelReport

resp_r__OrderMassCancelReport.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* r  */
void Application::onMessage(const FIX44::OrderMassCancelReport& message, const FIX::SessionID& sessionID )
{
  std::cout << "<r> OrderMassCancelReport: " << std::endl << message.toXML() << std::endl;
}

< y > SecurityList

resp_y__SecurityList.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* y  */
void Application::onMessage(const FIX44::SecurityList& message, const FIX::SessionID& sessionID )
{
  std::cout << "<y> SecurityList: " << std::endl << message.toXML() << std::endl;
}

追加メッセージ送信用(枠だけ)

< 1 > TestRequest

send_1__TestRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* 1  */
void Application::TestRequest( const char* sessionType )
{
  FIX44::TestRequest message;
  SetMessageHeader( message, sessionType );
  FIX::Session::sendToTarget( message );
  std::cout << "<1> TestRequest: " << std::endl << message.toXML() << std::endl;
}

TestRequest は唯一 取引用 と レート用の両方で呼ばれる命令のため、セッションタイプを引数にとれるようにしています

< AF > OrderMassStatusRequest

send_AF_OrderMassStatusRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* AF */
void Application::OrderMassStatusRequest()
{
  FIX44::OrderMassStatusRequest message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<AF> OrderMassStatusRequest: " << std::endl << message.toXML() << std::endl;
}

< AN > RequestForPositions

send_AN_RequestForPositions.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* AN */
void Application::RequestForPositions()
{
  FIX44::RequestForPositions message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<ANx> RequestforPositions: " << std::endl << message.toXML() << std::endl;
}

< D > NewOrderSingle

send_D__NewOrderSingle.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* D  */
void Application::NewOrderSingle()
{
  FIX44::NewOrderSingle message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<D> NewOrderSingle: " << std::endl << message.toXML() << std::endl;
}

< F > OrderCancelRequest

send_F__OrderCancelRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* F  */
void Application::OrderCancelRequest()
{
  FIX44::OrderCancelRequest message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<F> OrderCancelRequest: " << std::endl << message.toXML() << std::endl;
}

< G > OrderCancelReplaceRequest

send_G__OrderCancelReplaceRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* G  */
void Application::OrderCancelReplaceRequest()
{
  FIX44::OrderCancelReplaceRequest message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<G> OrderCancelReplaceRequest: " << std::endl << message.toXML() << std::endl;
}

< H > OrderStatusRequest

send_H__OrderStatusRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* H  */
void Application::OrderStatusRequest()
{
  FIX44::OrderStatusRequest message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<H> OrderStatusRequest: " << std::endl << message.toXML() << std::endl;
}

< V > MarketDataRequest

send_V__MarketDataRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* V  */
void Application::MarketDataRequest()
{
  FIX44::MarketDataRequest message;
  SetMessageHeader( message, SessionTypeRatefeed );
  FIX::Session::sendToTarget( message );
  std::cout << "<V> MarketDataRequest: " << std::endl << message.toXML() << std::endl;
}

MarketDataRequest はレート情報取得なので、メッセージヘッダにレート用のセッションタイプを指定
(デフォルトのセッションタイプは取引用なので)

< q > OrderMassCancelRequest

send_q__OrderMassCancelRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* q  */
void Application::OrderMassCancelRequest()
{
  FIX44::OrderMassCancelRequest message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<q> OrderMassCancelRequest: " << std::endl << message.toXML() << std::endl;
}

< x > SecurityListRequest

send_x__SecurityListRequest.cpp
#include "config.h"

#include "Application.h"
#include "quickfix/Session.h"
#include <iostream>

/* x  */
void Application::SecurityListRequest()
{
  FIX44::SecurityListRequest message;
  SetMessageHeader( message );
  FIX::Session::sendToTarget( message );
  std::cout << "<x> SecurityListRequest: " << std::endl << message.toXML() << std::endl;
}

<前 【QuickFIX】04 情報保存用にMySQLコネクションを保持..他
次> 【QuickFIX】06 独自メッセージ仕様


一覧

01 サンプルのコンパイル
02 ログイン時にPassword(554)を送信
03 送受信ログをMySQLに保存
04 情報保存用にMySQLコネクションを保持..他
05 各種メッセージの枠を作成
06 独自メッセージ仕様
07 セッション開始 TradingSessionStatus
08 通貨ペア要求 SecurityListRequest
09 通貨ペア取得 SecurityList
10 デモ環境サーバへ接続
11 ログ出力設定
12 マーケット情報要求 < V > MarketDataRequest
13 マーケット情報受信 < X > MarketDataIncrementalRefresh
14 口座情報要求 < AN > RequestForPositions
15 口座情報取得 < AZ > CollateralResponse


nobu-maple
元Oracleマスター/いまは普通のシステム屋/JavascriptやPHPからCやC++まで言語はなんでも/中学でMSXのBASICプログラムをはじめてからいく年月/最近はUiPathでRPAなことも楽しい
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away