1

I have been experimenting with QuickFix but I am getting a "AttributeError:SessionID". I honestly have no idea why it's happening, I tinkered with the code a bit but problem remains. Also , google has failed me big on this one so I hope you guys can help me.

Code :

import sys
import time
import thread
import argparse
from datetime import datetime
import quickfix as fix

class Application(fix.Application):
    orderID = 0
    execID = 0
    def gen_ord_id(self):
        global orderID
        orderID+=1
        return orderID


    def onCreate(self, sessionID):
            return
    def onLogon(self, sessionID):
            self.sessionID = sessionID
            print ("Successful Logon to session '%s'." % sessionID.toString())
            return

    def onLogout(self, sessionID): return

    def toAdmin(self, sessionID, message):
        return

    def fromAdmin(self, sessionID, message):
        return


    def toApp(self, sessionID, message):
        print "Sent the following message: %s" % message.toString()
        return

    def fromApp(self, message, sessionID):
        print "Received the following message: %s" % message.toString()
        return

    def genOrderID(self):
        self.orderID = self.orderID+1
        return `self.orderID`

    def genExecID(self):
        self.execID = self.execID+1
        return `self.execID`
    def put_order(self):
        print("Creating the following order: ")
        trade = fix.Message()
        trade.getHeader().setField(fix.BeginString(fix.BeginString_FIX50)) #
        trade.getHeader().setField(fix.MsgType(fix.MsgType_NewOrderSingle)) #39=D
        trade.setField(fix.ClOrdID(self.genExecID())) #11=Unique order

        trade.setField(fix.HandlInst(fix.HandlInst_MANUAL_ORDER_BEST_EXECUTION)) #21=3 (Manual order, best executiona)
        trade.setField(fix.Symbol('SMBL')) #55=SMBL ?
        trade.setField(fix.Side(fix.Side_BUY)) #43=1 Buy
        trade.setField(fix.OrdType(fix.OrdType_LIMIT)) #40=2 Limit order
        trade.setField(fix.OrderQty(100)) #38=100
        trade.setField(fix.Price(10))
        print trade.toString()
        fix.Session.sendToTarget(trade, self.sessionID)


def main(config_file):
    try:
        settings = fix.SessionSettings("initiatorsettings.cfg")
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(application, storeFactory, settings, logFactory)
        initiator.start()

        while 1:
                input = raw_input()
                if input == '1':
                    print "Putin Order"
                    application.put_order()
                if input == '2':
                    sys.exit(0)
                if input == 'd':
                    import pdb
                    pdb.set_trace()
                else:
                    print "Valid input is 1 for order, 2 for exit"
                    continue
    except (fix.ConfigError, fix.RuntimeError), e:
        print e

if __name__=='__main__':
    parser = argparse.ArgumentParser(description='FIX Client')
    parser.add_argument('file_name', type=str, help='Name of configuration file')
    args = parser.parse_args()
    main(args.file_name)

I get the following error message :

Traceback (most recent call last): 
File "initiator.py", line 97, in main application.put_order()   
File "initiator.py", line 80, in put_order fix.Session.sendToTarget(trade, self.sessionID)   
File "C:\Users\gribeiro\Anaconda\lib\site-packages\quickfix.py", line 30939, in <lambda>__getattr__ = lambda self, name: _swig_getattr(self, Application, name)   
File "C:\Users\gribeiro\Anaconda\lib\site-packages\quickfix.py", line 57, in _swig_getattr raise AttributeError(name) 
AttributeError: sessionID

------------------------------------------------------------


Update :

Code producing the error:

import sys
import time
import thread
import argparse
from datetime import datetime
import quickfix as fix

class Application(fix.Application):
    orderID = 0
    execID = 0
    def gen_ord_id(self):
        global orderID
        orderID+=1
        return orderID


def onCreate(self, sessionID):
        return
def onLogon(self, sessionID):
        # self.sessionID = sessionID
        # print ("Successful Logon to session '%s'." % sessionID.toString())
        return

def onLogout(self, sessionID): return

def toAdmin(self, sessionID, message):
    return

def fromAdmin(self, sessionID, message):
    return


def toApp(self, sessionID, message):
    print "Sent the following message: %s" % message.toString()
    return

def fromApp(self, message, sessionID):
    print "Received the following message: %s" % message.toString()
    return

def genOrderID(self):
    self.orderID = self.orderID+1
    return `self.orderID`

def genExecID(self):
    self.execID = self.execID+1
    return `self.execID`
def put_order(self):
    print("Creating the following order: ")
    trade = fix.Message()
    trade.getHeader().setField(fix.BeginString(fix.BeginString_FIX50)) #
    trade.getHeader().setField(fix.MsgType(fix.MsgType_NewOrderSingle)) #39=D
    trade.setField(fix.ClOrdID(self.genExecID())) #11=Unique order

    trade.setField(fix.HandlInst(fix.HandlInst_MANUAL_ORDER_BEST_EXECUTION)) #21=3 (Manual order, best executiona)
    trade.setField(fix.Symbol('SMBL')) #55=SMBL ?
    trade.setField(fix.Side(fix.Side_BUY)) #43=1 Buy
    trade.setField(fix.OrdType(fix.OrdType_LIMIT)) #40=2 Limit order
    trade.setField(fix.OrderQty(100)) #38=100
    trade.setField(fix.Price(10))
    print trade.toString()
    fix.Session_sendToTarget(trade)


def main(config_file):
    try:
        settings = fix.SessionSettings(config_file)
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(application, storeFactory, settings, logFactory)
        initiator.start()

    while 1:
            input = raw_input()
            if input == '1':
                print "Putin Order"
                application.put_order()
            if input == '2':
                sys.exit(0)
            if input == 'd':
                import pdb
                pdb.set_trace()
            else:
                print "Valid input is 1 for order, 2 for exit"
                continue
except (fix.ConfigError, fix.RuntimeError), e:
    print e

if __name__=='__main__':
    parser = argparse.ArgumentParser(description='FIX Client')
    parser.add_argument('file_name', type=str, help='Name of configuration file')
    args = parser.parse_args()
    main(args.file_name)

Config file :

[DEFAULT]
ConnectionType=initiator
ReconnectInterval=60
FileStorePath=store
FileLogPath=log
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
DataDictionary=spec/FIX42.xml
HttpAcceptPort=9911
ValidateUserDefinedFields=N
ResetOnLogout=Y
ResetOnLogon=Y
ValidateFieldsOutOfOrder=N
DefaultApplVerID=FIX.5.0SP2

# standard config elements

[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
BeginString=FIX.4.2
SenderCompID=BRANZOL
TargetCompID=FIXSIM
SocketConnectHost=host
SocketConnectPort=port
HeartBtInt=30 

Output from ScreenLogFactory >

<20151216-17:09:43.426, FIX.4.2:BRANZOL->FIXSIM, event>
  (Created session)
<20151216-17:09:43.434, FIX.4.2:BRANZOL->FIXSIM, event>
  (Connecting to hostX on port Y)
<20151216-17:09:44.159, FIX.4.2:BRANZOL->FIXSIM, outgoing>
  (8=FIX.4.29=7435=A34=149=BRANZOL52=20151216-17:09:43.88256=FIXSIM98=0108=30141=Y10=032)
<20151216-17:09:44.159, FIX.4.2:BRANZOL->FIXSIM, event>
  (Initiated logon request)
<20151216-17:09:44.264, FIX.4.2:BRANZOL->FIXSIM, event>
  (Socket Error: Connection reset by peer.)
<20151216-17:09:44.264, FIX.4.2:BRANZOL->FIXSIM, event>
  (Disconnecting)
Valid input is 1 for order, 2 for exit
Putin Order
Creating the following order: 
8=FIX.5.09=4635=D11=121=338=10040=244=1054=155=SMBL10=081
2
  • Does initiatorsettings.cfg exist in the same folder you launched your script from? You setup argparse to pass in the location of a config file to main(), but it seems you don't actually use config_file parameter anywhere in your code. Instead you hardcoded in initiatorsettings.cfg as your config file. Commented Nov 24, 2015 at 15:47
  • @JoeYoung True, my bad but initiatorsettings.cfg is in the same location so the issue is not there. I am now using the configfile variable but the problem remains. Commented Nov 24, 2015 at 15:55

1 Answer 1

1

Try cutting this line entirely self.sessionID = sessionID

EDIT -- OKay, thanks for including the traceback. You should replace the line fix.Session.sendToTarget(trade, self.sessionID) with the line fix.Session_sendToTarget(trade) and let me know how that goes.

Sign up to request clarification or add additional context in comments.

17 Comments

I tried but the error is still there. The traceback is as follow : Traceback (most recent call last): File "initiator.py", line 97, in main application.put_order() File "initiator.py", line 80, in put_order fix.Session.sendToTarget(trade, self.sessionID) File "C:\Users\gribeiro\Anaconda\lib\site-packages\quickfix.py", line 30939, in <lambda> getattr = lambda self, name: _swig_getattr(self, Application, name) File "C:\Users\gribeiro\Anaconda\lib\site-packages\quickfix.py", line 57, in _swig_getattr raise AttributeError(name) AttributeError: sessionID
Sorry for the late response . No , it didnt. I got a quickfix.SessionNotFound : Session Not Found error .
include the traceback please -- this is progress
thank you for the help , here follows the traceback : Traceback (most recent call last): File "initiator.py", line 88, in main application.put_order() File "initiator.py", line 71, in put_order fix.Session.sendToTarget(trade) SessionNotFound: Session Not Found DEBUG:root:This message should go to the log file ERROR:root:Got exception on main handler Traceback (most recent call last): File "initiator.py", line 88, in main application.put_order() File "initiator.py", line 71, in put_order fix.Session.sendToTarget(trade) SessionNotFound: Session Not Found
You did not follow my instructions. You must include the underscore. The call should be fix.Session_sendToTarget(trade).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.