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