I'm trying to build my fix application with quickfix, but when starting it, it first sends a logout message before logging in, and raises Session not Found.
class Application(quickfix.Application):
def __init__(self, session, logger):
super(Application, self).__init__()
self.session = session
self.logger = logger
def onCreate(self, sessionID):
self.logger.info("Created session {}.".format(sessionID))
return
def onLogon(self, sessionID):
self.logger.info("Logon session {}.".format(sessionID))
return
def onLogout(self, sessionID):
self.logger.info("Logout session {}.".format(sessionID))
return
def toAdmin(self, message, sessionID):
msgType = quickfix.MsgType()
message.getHeader().getField(msgType)
if msgType.getValue() == quickfix.MsgType_Logon:
self.logger.info('LOGON SessionID {}'.format(sessionID))
elif msgType.getValue() == quickfix.MsgType_Logout:
self.logger.info('LOGOUT SessionID {}'.format(sessionID))
self.logger.info('to Admin session {} send {}'.format(sessionID, self.messageToString(message)))
self.session.sendToTarget(message)
return
def toApp(self, message, sessionID):
self.logger.info('to App: {}'.format(message))
self.session.sendToTarget(message)
return
def fromApp(self, message, sessionID):
self.logger.info('from App: {}'.format(message))
return
logger = create_logger(config)
settings = quickfix.SessionSettings(client_config)
application = Application(quickfix.Session, logger)
storeFactory = quickfix.FileStoreFactory(settings)
logFactory = quickfix.ScreenLogFactory(settings)
initiator = quickfix.SocketInitiator(application, storeFactory, settings, logFactory)
initiator.start()
I get the following:
LOGOUT SessionID FIX44:Client->Server to Admin session FIX44:Client->Server send 8=FIX.4.4|9=62|35=5|34=26|49=Client|52=20200608-12:26:03|56=Server|10=168
File "FIx.py", line 42, in toAdmin self.session.sendToTarget(message) SessionNotFound: Session Not Found
Any idea why it raises the message please?
Thank you folks!
The from/toApp
or from/toAdmin
methods are callbacks and you should NOT send the passed message by yourself via Session.sendToTarget
.
Instead the message will be sent by quickfix when the callback returns.