0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【QuickFIX】03 送受信ログをMySQLに保存

Last updated at Posted at 2017-04-14

<前 【QuickFIX】02 ログイン時にPassword(554)を送信
次> 【QuickFIX】04 情報保存用にMySQLコネクションを保持..他

サーバとの通信内容をDBに保存できるようにします。
(デフォルトではローカルファイルに出力してました)

##クライアントソースファイル

tradeclient.cpp
@@ -1,9 +1,9 @@
 #include "config.h"

-#include "quickfix/FileStore.h"
 #include "quickfix/SocketInitiator.h"
 #include "quickfix/SessionSettings.h"
-#include "quickfix/Log.h"
+#include "quickfix/MySQLStore.h"
+#include "quickfix/MySQLLog.h"
 #include "Application.h"
 #include <string>
 #include <iostream>
@@ -26,8 +26,8 @@ int main( int argc, char** argv )
     FIX::SessionSettings settings( file );

     Application application( settings );
-    FIX::FileStoreFactory storeFactory( settings );
-    FIX::ScreenLogFactory logFactory( settings );
+    FIX::MySQLStoreFactory storeFactory( settings );
+    FIX::MySQLLogFactory logFactory( settings );
     FIX::SocketInitiator initiator( application, storeFactory, settings, logFactory );

     initiator.start();

保存先をMySQLに変更

##設定ファイルにMySQLログイン設定を追加

tradeclient.cfg
[DEFAULT]
ConnectionType=initiator
ReconnectInterval=60
FileStorePath=store
FileLogPath=log
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
DataDictionary=FIX44.xml
HttpAcceptPort=9911

ValidateUserDefinedFields=N
ResetOnLogout=Y
ResetOnLogon=Y

# -- MySQL Store ----
MySQLStoreDatabase=Quick
MySQLStoreUser=QuickUSER
MySQLStorePassword=QuickPASS
MySQLStoreHost=localhost

# -- MySQL Log ------
MySQLLogDatabase=Quick
MySQLLogUser=QuickUSER
MySQLLogPassword=QuickPASS
MySQLLogHost=localhost

[SESSION]
BeginString=FIX.4.4
SenderCompID=CAXDemo_Account_Trd
TargetCompID=CNX
SocketConnectHost=127.0.0.1
SocketConnectPort=9999
HeartBtInt=30
Password=Pass1234
SessionType=Trade

[SESSION]
BeginString=FIX.4.4
SenderCompID=CAXDemo_Account_Str
TargetCompID=CNX
SocketConnectHost=127.0.0.1
SocketConnectPort=9999
HeartBtInt=30
Password=Pass1234
SessionType=Ratefeed

##MySQLLOGヘッダーファイル

tradeclient]$ cd ../../src/C++/

quickfix 本体側で保存するログの「送信」と「受信」の見分けがつくように改造しときます
送信と受信を同じテーブルに保存する場合、見分けがつかなくなっちゃうんですよね。。
困るので改造です(フラグ立てて見分けがつくようにしときます)

MySQLLog.h
@@ -63,15 +63,15 @@ public:
   { m_eventTable = eventTable; }

   void onIncoming( const std::string& value )
-  { insert( m_incomingTable, value ); }
+  { insert( m_incomingTable, value, false ); }
   void onOutgoing( const std::string& value )
-  { insert( m_outgoingTable, value ); }
+  { insert( m_outgoingTable, value, true ); }
   void onEvent( const std::string& value )
-  { insert( m_eventTable, value ); }
+  { insert( m_eventTable, value, true ); }

 private:
   void init();
-  void insert( const std::string& table, const std::string value );
+  void insert( const std::string& table, const std::string value, const int io );

   std::string m_incomingTable;
   std::string m_outgoingTable;

##MySQLLOGソースファイル

保存時にフラグを見て Sender とTarget を入れ替えるだけです

MySQLLog.cpp
@@ -227,7 +227,7 @@ void MySQLLog::backup()
 {
 }

-void MySQLLog::insert( const std::string& table, const std::string value )
+void MySQLLog::insert( const std::string& table, const std::string value, const int io )
 {
   UtcTimeStamp time;
   int year, month, day, hour, minute, second, millis;
@@ -249,10 +249,16 @@ void MySQLLog::insert( const std::string& table, const std::string value )

   if( m_pSessionID )
   {
-    queryString
-    << "\"" << m_pSessionID->getBeginString().getValue() << "\","
-    << "\"" << m_pSessionID->getSenderCompID().getValue() << "\","
-    << "\"" << m_pSessionID->getTargetCompID().getValue() << "\",";
+    if( io )
+      queryString
+      << "\"" << m_pSessionID->getBeginString().getValue() << "\","
+      << "\"" << m_pSessionID->getSenderCompID().getValue() << "\","
+      << "\"" << m_pSessionID->getTargetCompID().getValue() << "\",";
+    else
+      queryString
+      << "\"" << m_pSessionID->getBeginString().getValue() << "\","
+      << "\"" << m_pSessionID->getTargetCompID().getValue() << "\","
+      << "\"" << m_pSessionID->getSenderCompID().getValue() << "\",";
     if( m_pSessionID->getSessionQualifier() == "" )
       queryString << "NULL" << ",";
     else

##コンパイル

C++]$ cd ../..
quickfix]$ make
quickfix]$ sudo  make  install
quickfix]$ sudo  echo /usr/local/lib > /etc/ld.so.conf.d/user-local-lib.conf
quickfix]$ sudo  ldconfig
quickfix]$ sudo  ldconfig -v | grep quick
        libquickfix.so.16 -> libquickfix.so.16.0.1

エラーなくコンパイルできること

<前 【QuickFIX】02 ログイン時にPassword(554)を送信
次> 【QuickFIX】04 情報保存用にMySQLコネクションを保持..他


一覧

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


0
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?