2011-09-07 126 views
1

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

我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(); 

回答

0

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

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

0

这是很老,但也许答案将有利于一个人,因为我最近试图做同样的事情在C#。 你要在这里覆盖这个

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

查看详情:Implementing custom logons

0

你必须在你的MyApp2类添加一个方法来与 你的头发送您的FIX消息,否则你的服务器将无法正确回复你。

添加这个方法:

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

,并呼吁它在toAdmin和toApp methods.Never忘记检查你的配置文件 为TargetSubID。如果你没有,它只是在你的CFG文件中添加SUBID。

1

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

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),以与每一个消息中发送是有效的。

我希望这可以帮助那些试图与FXCM发起FIX会话的人!