快速修复登录问题

本文关键字:登录 问题 | 更新日期: 2023-09-27 18:07:56

我正在使用QuickFix(c#)创建Fix启动器。我尝试使用用户名和密码登录FXCM服务器。但是我的onLogon方法从未被触发。当SocketInitior启动时,onCreate方法正在运行,然后onLogout方法正在调用。在onCreate方法之后,onLogon方法应该正在运行,但它没有运行。所以initiator.isLoggedOn()方法总是返回false。我怎样才能成功登录?

我的QuickFix。应用程序接口实现应用程序如下:

initiator.start后();onLogon方法未运行。

class MyApp2 : QuickFix44.MessageCracker, QuickFix.Application
{
    public SessionID sessionId;
    private SessionSettings settings;
    private string userName, password, userPin;
    private CollInquiryID colInquiryId;
    private DateTime startDate;
    private const int REQUEST_LIST_OF_TRADING_SESSIONS = 5;
    private object requestID = 1;
    public MyApp2(QuickFix.SessionSettings setting)
    {
        long temp = 0;
        this.requestID = temp;
        this.settings = setting;
    }
    public void fromAdmin(Message message, SessionID sessionId)
    {
        try
        {
            crack(message, sessionId);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void fromApp(Message message, SessionID sessionId)
    {
        try
        {
            crack(message, sessionId);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void onCreate(SessionID sessionId)
    {
        this.sessionId = sessionId;
        this.userName = this.settings.get(this.sessionId).getString("username");
        this.password = this.settings.get(this.sessionId).getString("password");
    }
    public void onLogon(SessionID sessionId)
    {
        Console.WriteLine("Login for :{0}", this.userName);
        this.startDate = new DateTime();
        this.SendUserRequest();
        this.SendUserRequest();
    }
    public void onLogout(SessionID sessionId)
    {
    }
    public void toAdmin(Message message, SessionID sessionId)
    {
    }
    public void toApp(Message message, SessionID sessionId)
    {
    }
    public void SendUserRequest()
    {
        QuickFix44.UserRequest userRequest = new QuickFix44.UserRequest();
        userRequest.setString(UserRequestID.FIELD, this.NextId().ToString());
        userRequest.setString(QuickFix.Username.FIELD, this.userName);
        userRequest.setString(QuickFix.Password.FIELD, this.password);
        userRequest.setInt(QuickFix.UserRequestType.FIELD, REQUEST_LIST_OF_TRADING_SESSIONS);
        this.Send(userRequest);
    }
    public void Send(Message message)
    {
        try
        {
            bool isSent = QuickFix.Session.sendToTarget(message, this.sessionId);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private long NextId()
    {
        lock (this.requestID)
        {
            long temp = (long)this.requestID;
            this.requestID = ++temp;
            if (temp > 0x7FFFFFF0)
            {
                temp = 1;
                this.requestID = temp;
            }
        }
        return (long)this.requestID;
    }
}

主程序如下:

            string path = "quickfix.cfg";
            FileStream reader = new FileStream(path,FileMode.Open);
            SessionSettings settings = new SessionSettings(reader);
            reader.Close();
            MyApp2 application = new MyApp2(settings);
            MessageStoreFactory storeFactory = new FileStoreFactory(settings);
            LogFactory logFactory = new FileLogFactory(settings);
            MessageFactory messageFactory = new DefaultMessageFactory();
            SocketInitiator initiator = new SocketInitiator(application, storeFactory, settings, logFactory, messageFactory);
            initiator.start();

快速修复登录问题

这是我用FXCM启动FIX会话的解决方案。

1-使用快速修复示例。TradeClient项目。

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

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

4-你的main Program.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=)是有效的。

我希望这能帮助那些试图与FXCM启动FIX会话的人!

我不确定FXCM是如何做到的,但我知道成功登录服务器后触发onLogon方法。因此,您应该在发送登录请求之前添加usernamepassword。尝试将密码和用户名添加到toAdmin方法。如果它们是正确的,并且您已经成功登录到服务器- onLogon将被触发。

无论如何,你可以从FXCM FIX API支持论坛获得更具体的帮助:http://forexforums.dailyfx.com/fix-api-support/

这是一个非常古老的问题,但也许这个答案会对某些人有益,因为我最近正试图用c#做同样的事情。你必须重写这个

public void toAdmin(Message message, SessionID sessionId){ }

实现自定义登录

您必须在MyApp2类中添加一个方法来发送FIX消息您的报头,否则您的服务器将无法正确响应您。

添加这个方法:

    private void setHeader(QuickFix.Message message)
    {
        message.getHeader().setField(new QuickFix.TargetSubID(settings.get(sessionID).getString("TargetSubID")));
    }

并在toAdmin和toApp方法中调用它。永远不要忘记检查配置文件对 TargetSubID 。如果你没有,只需在你的cfg文件中添加SUBID。