由于密码丢失,QuickFix登录失败

QuickFix Login Failed due to password missing

本文关键字:QuickFix 登录 失败 于密码 密码      更新时间:2023-10-16

我正在使用quickfix C++实现连接到FIX服务器,除了当我尝试连接时,它说字段缺少用户名之外,一切都很好。为了纠正这一点,我在toAdmin方法中添加了以下代码

void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
    if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
    {
        FIX44::Logon & logon_message = dynamic_cast<FIX44::Logon&>(message);
        logon_message.setField(FIX::Username("username"));
        logon_message.setField(FIX::Password("password"));
    }
 std::cout<<message.toString();
 }
}

但is会导致异常。为了检查它是否工作,还尝试使用std::cout<<message.ToString(); 打印消息

但什么都没用。

我想你差不多到了。以下是我在C#中用FXCM启动FIX会话的解决方案(移植C++实现应该很容易)。

1-使用QuickFix Examples.TradeClient项目。

2-确保您的fix.cfg文件存在于TradeClient/bin/Debug目录中。

3-确保您的字典(FIXFXCM10.XML)存在于TradeClient/bin/Debug目录中。

4-你的主程序.cs应该是这样的;

var settings = new QuickFix.SessionSettings("fix.cfg");
var client = new QuickFixClient();
var storeFactory = new QuickFix.FileStoreFactory(settings);
var logFactory = new QuickFix.ScreenLogFactory(settings);
var initiator = new QuickFix.Transport.SocketInitiator(client, storeFactory, settings, logFactory); 
initiator.Start();
client.Run();
initiator.Stop();

并替换

public void ToAdmin(Message message, SessionID sessionID) {}

用这个

public void ToAdmin(Message message, SessionID sessionID)
{
    if (message.GetType() == typeof(QuickFix.FIX44.Logon))
        {
            message.SetField(new Username("YOUR_USERNAME"));
            message.SetField(new Password("YOUR_PASSWORD"));                             
        }          
    message.SetField(new QuickFix.Fields.Account("YOUR_ACCOUNT_NUMBER"));
}

FXCM要求每个消息发送的账号(标签1=)都是有效的。如果不存在,也可能会阻止成功登录。

希望这能有所帮助!

这就是我添加密码的方式:

void toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
    // put password in the logon message
    if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
    {
        FIX::Password fixpasswd = ConfigSingleton::getInstance().CurrenexConfig.FIXPassword; //use your std::string password here.
        message.getHeader().setField(FIX::Password(fixpasswd)); //also add username here.
    }
}

如果你能看到你的用户名和密码,那么这意味着已经可以了。关于例外,我以前也遇到过。对我来说,它来自toApp功能,我将其更改如下,效果良好:

void 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& e) 
    {
        //std::cout <<  e.what() << " " << message.toString() << ENDLINE;
    }
}

事实上,也不例外。

顺便说一句,如果你没有为某些消息类型定义自己的函数,这些消息将被拒绝。

希望这会有所帮助。