使用Python的quickfix包,如何强行注销FIX连接?

时间:2017-06-09 19:13:11

标签: python quickfix

我有一小段代码,我建立了FIX连接,并且能够成功连接。

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

每当我关闭程序时,我想注销FIX会话。我还在这里定义了quickfix类函数

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

我尝试拨打专线initiator.stop(),但我的函数FIX_IO.onLogout未被调用。有没有办法在我的程序中的任何地方调用FIX会话的注销,只需访问我用来连接的quickfix.application对象?

2 个答案:

答案 0 :(得分:1)

Initiator i的QuickFixJ中,您可以使用类似

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

答案 1 :(得分:0)

python 实现是:

quickfix .Session.lookupSession(sessionID).logout()