Help us understand the problem. What is going on with this article?

【QuickFIX】02 ログイン時にPassword(554)を送信

More than 1 year has passed since last update.

<前 【QuickFIX】01 サンプルのコンパイル
次> 【QuickFIX】03 送受信ログをMySQLに保存

ログイン時の toAdmin メッセージにパスワード(554)を追加して送信します
パスワードは設定ファイルから取得

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

tradeclient.cpp
        #include "config.h"

        #include "quickfix/FileStore.h"
        #include "quickfix/SocketInitiator.h"
        #include "quickfix/SessionSettings.h"
        #include "quickfix/Log.h"
        #include "Application.h"
        #include <string>
        #include <iostream>
        #include <fstream>

        #include "../../src/getopt-repl.h"

        int main( int argc, char** argv )
        {
          if ( argc != 2 )
          {
            std::cout << "usage: " << argv[ 0 ]
            << " FILE." << std::endl;
            return 0;
          }
          std::string file = argv[ 1 ];

          try
          {
            FIX::SessionSettings settings( file );

          Application application( settings );
            FIX::FileStoreFactory storeFactory( settings );
            FIX::ScreenLogFactory logFactory( settings );
            FIX::SocketInitiator initiator( application, storeFactory, settings, logFactory );

            initiator.start();
            application.run();
            initiator.stop();

            return 0;
          }
          catch ( std::exception & e )
          {
            std::cout << e.what();
            return 1;
          }
        }

Application application の引数に読み込んだ設定情報(settings)を追加
他、余分なところはバッサリ削除

Applicationヘッダーファイル

Application.h
        #ifndef TRADECLIENT_APPLICATION_H
        #define TRADECLIENT_APPLICATION_H

        #include "quickfix/Application.h"
        #include "quickfix/MessageCracker.h"
        #include "quickfix/Values.h"
        #include "quickfix/Mutex.h"

        #include <queue>

        class Application :
              public FIX::Application,
              public FIX::MessageCracker
        {
        public:
        Application( const FIX::SessionSettings& settings )
          : m_settings( settings ) {}

          void run();

        private:
        FIX::SessionSettings m_settings;

          void onCreate( const FIX::SessionID& ) {}
          void onLogon( const FIX::SessionID& sessionID );
          void onLogout( const FIX::SessionID& sessionID );
        void toAdmin( FIX::Message&, const FIX::SessionID& );
          void toApp( FIX::Message&, const FIX::SessionID& )
          throw( FIX::DoNotSend );
          void fromAdmin( const FIX::Message&, const FIX::SessionID& )
          throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::RejectLogon ) {}
          void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
          throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType );

        };

        #endif

設定情報を受け取れるように変更
あとはパスワードを送信するための toAdminの実体書くために {} を削除しました
んで、不要部分はバッサリ削除

Applicationソースファイル

Application.cpp
        #include "config.h"

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

        void Application::onLogon( const FIX::SessionID& sessionID )
        {
          std::cout << std::endl << "Logon - " << sessionID << std::endl;
        }

        void Application::onLogout( const FIX::SessionID& sessionID )
        {
          std::cout << std::endl << "Logout - " << sessionID << std::endl;
        }

        void Application::fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
        throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType )
        {
          crack( message, sessionID );
          std::cout << std::endl << "IN: " << message << std::endl;
        }

      void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID )
      {
        if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
        {
          const FIX::Dictionary& dic = m_settings.get( sessionID );
          if (dic.has("Password"))
            message.getHeader().setField(FIX::Password(dic.getString("Password")));
        }
      }

        void Application::toApp( FIX::Message& message, const FIX::SessionID& sessionID )
        throw( FIX::DoNotSend )
        {
          try
          {
            FIX::PossDupFlag possDupFlag;
            message.getHeader().getField( possDupFlag );
            if ( possDupFlag ) throw FIX::DoNotSend();
          }
          catch ( FIX::FieldNotFound& ) {}

          std::cout << std::endl
          << "OUT: " << message << std::endl;
        }

        void Application::run()
        {
          while ( true )
          {
            try
            {
            std::string action;
            std::cout << std::endl
              << "quit) Quit" << std::endl
              << "Action: ";
            std::cin >> action;

            if ( action == "quit" )
              break;
            }
            catch ( std::exception & e )
            {
              std::cout << "Message Not Sent: " << e.what();
            }
          }
        }

toAdmin の実体を追記
パスワードは設定ファイルから取り出して送信メッセージに含めるようにしてます
ついでに不要部分をバッサリ削除して、削除した影響で run の中身も変えてます

コンパイル

tradeclient]$ make clean
tradeclient]$ make 

エラーが出ないこと
正常にコンパイルできること

設定ファイルにユーザとパスワードを設定

レート情報取得用のユーザと、発注やら口座情報取得やらの取引用のユーザをそれぞれ追加しときます

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

[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

vimの着色

余談ですがvimで開発するときの着色設定
使える設定ファイルの確認

$ ls  /usr/share/vim/vim74/colors/
README.txt  darkblue.vim  delek.vim   elflord.vim  koehler.vim  murphy.vim  peachpuff.vim  shine.vim  torte.vim
blue.vim    default.vim   desert.vim  evening.vim  morning.vim  pablo.vim   ron.vim        slate.vim  zellner.vim

環境によって違うと思います
これを利用する設定

~/.vimrc
:colorscheme delek

<前 【QuickFIX】01 サンプルのコンパイル
次> 【QuickFIX】03 送受信ログをMySQLに保存

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした