我正在使用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();