开发者

QuickFix login problem

I am using QuickFix(C#) to create Fix initiator. I try to logon FXCM server using a username and passwod. But my onLogon method is never triggered. When SocketInitior is started, onCreate method is running then onLogout methot is calling. After onCreate method, the onLogon method should be running but it is not running. So always initiator.isLoggedOn() method return false. How can I logon successfully?

My QuickFix.Application interface implemented application is as follows:

After initiator.start(); the onLogon method is not running.

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)
    {

开发者_如何学JAVA    }

    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;
    }
}

The main program is as follows:

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


Here is my solution for initiating a FIX session with FXCM.

1- Use the QuickFix Examples.TradeClient project.

2- Ensure your fix.cfg file is present in TradeClient/bin/Debug directory.

3- Ensure your dictionary (FIXFXCM10.XML) is present in TradeClient/bin/Debug directory.

4- Your main Program.cs should look something like this;

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

and replace

public void ToAdmin(Message message, SessionID sessionID) {}

with this

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 require the account number (tag 1=) to be sent with every message to be valid.

I hope this helps someone out there trying to initiate a FIX session with FXCM!


I'm not sure on how it's done with FXCM, but I know onLogon method is triggered in response to a successful log on to the server. Hence you should add the username and password before you send the logon request. Try moving the password and username addition to toAdmin method. If they are correct, and you have a successful logon to server - onLogon will be triggered.

Any way, you can get more specific help from FXCM FIX API support forum: http://forexforums.dailyfx.com/fix-api-support/


This is very old, but perhaps the answer would benefit someone, as I was recently trying to do the same thing in c#. You have to override this

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

See details here: Implementing custom logons


You have to add a method in your MyApp2 class to send your FIX message with your header ,otherwise your server would not be able to respond you properly .

Add this method :

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

and call it in toAdmin and toApp methods.Never forget to check your config file for TargetSubID.If you dont have it just add SUBID in your cfg file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜