2

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

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

在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();
4

4 回答 4

2

这是我与 FXCM 发起 FIX 会话的解决方案。

1- 使用 QuickFix Examples.TradeClient 项目。

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

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

4- 你的主 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 会话的人有所帮助!

于 2017-01-14T07:13:31.917 回答
0

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

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

于 2011-09-13T17:35:29.220 回答
0

这已经很老了,但也许答案会让某人受益,因为我最近试图在 c# 中做同样的事情。你必须覆盖这个

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

在此处查看详细信息:实现自定义登录

于 2012-02-23T19:27:26.093 回答
0

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

添加此方法:

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

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

于 2012-04-03T10:00:03.390 回答