2011-09-07 166 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會話的人!