Search code examples
quickfixquickfixn

Quickfixn OnLogout not triggered when logging out


I wrote a trading app on the example Tradeclient that was on the quickfixn github page. It is now heavily modified, but regarding logging on and off it hasn't been changed. I now have the issue that when the logout button is pressed, it calls the Initiator.Stop, but it doesn't enter into OnLogout as it's supposed to do. When logging on it does everything right, initiator.start and then the OnCreate and then OnLogon, but when logging out, the OnLogout isn't triggered. Any ideas what could be the issue?

    private void Disconnect(object ignored)
    {
        Trace.WriteLine("ConnectionViewModel::Disconnect called");
        _qfapp.Stop();
    }

    public void Stop()
    {
        Trace.WriteLine("QFApp::Stop() called");
        Initiator.Stop(true);
    }

    public void OnLogout(QuickFix.SessionID sessionID)
    {
        // not sure how ActiveSessionID could ever be null, but it happened.
        string a = (this.ActiveSessionID == null) ? "null" : this.ActiveSessionID.ToString();
        Trace.WriteLine(String.Format("==OnLogout: {0}==", a));

        if (LogoutEvent != null)
        {
            LogoutEvent();
        }
    }

Solution

  • It's the same answer as DumbCoder here. The Initiator.Stop(true); stops the initiator engine so all sessions are disconnected. That means there are no more sessions to log out of.

    Per this answer you want to first of all logout of the session(s) using

    Session.lookupSession(sessionID).logout();
    

    However, per Grant's comment there, that's an unusual thing to do. My guess is that onLogout() functionality is really to capture when client sessions log out of an acceptor, but the acceptor itself stays running. It's not really for the initiator side.