首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QuickFix登录问题

QuickFix登录问题
EN

Stack Overflow用户
提问于 2011-09-07 20:28:16
回答 4查看 6.1K关注 0票数 2

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

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

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

代码语言:javascript
复制
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;
    }
}

主程序如下:

代码语言:javascript
复制
            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();
EN

回答 4

Stack Overflow用户

发布于 2017-01-14 15:13:32

以下是我使用FXCM启动修复会话的解决方案。

1-使用QuickFix Examples.TradeClient项目。

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

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

4-你的主Program.cs应该看起来像这样;

代码语言:javascript
复制
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();

并替换

代码语言:javascript
复制
public void ToAdmin(Message message, SessionID sessionID) {}

有了这个

代码语言:javascript
复制
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启动修复会话的人有所帮助!

票数 2
EN

Stack Overflow用户

发布于 2011-09-14 01:35:29

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

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

票数 0
EN

Stack Overflow用户

发布于 2012-02-24 03:27:26

这是非常古老的,但也许答案会对某些人有益,因为我最近正试图在c#中做同样的事情。您必须覆盖此选项

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

详情请看这里:Implementing custom logons

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7333893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档