Warm tip: This article is reproduced from serverfault.com, please click

Using Python's quickfix package, how can I forcibly logout of the FIX connection?

发布于 2017-06-09 19:13:11

I have a small block of code where I establish the FIX connection and am able to connect successfully.

file         = sys.argv[1]
settings     = fix.SessionSettings(file)
application  = FIX_IO(1)
storeFactory = fix.FileStoreFactory(settings)
initiator    = fix.SocketInitiator(application, storeFactory, settings)

initiator.start()
application.run()
# initiator.stop()

I want to logout of the FIX session whenever I close my program. I also defined the quickfix class functions here

import quickfix as fix

class FIX_IO(fix.Application):
    def onCreate(self, sessionID):
        self.sessionID = sessionID
        print("FIX Thread started now > \n")

    def onLogon(self, sessionID):
        print("We are live now > \n")

    def onLogout(self, sessionID):
        print("Disconnected..")

    def toAdmin(self, message, sessionID):
        msgType = fix.MsgType()
        message.getHeader().getField(msgType)
        msgType = msgType.getValue()

    def toApp(self, message, sessionID):
        self.handle_incoming_message(message)

    def fromApp(self, message, sessionID):
        self.handle_incoming_message(message)

    def send_message(self, message):
        fix.Session.sendToTarget(message, self.sessionID)

    def handle_income_message(self, msg):
        pass

I tried calling the line initiator.stop() but my function FIX_IO.onLogout wasn't called. Is there a way to invoke a logout of the FIX session anywhere in my program with just access to the quickfix.application object I used to connect?

Questioner
Alex F
Viewed
0
rupweb 2017-06-10 19:24:37

In QuickFixJ for your Initiator i you can use something like

SessionID id = i.getSessions().get(0);
Session.lookupSession(id).logout();