Search code examples
pythonquickfixfix-protocol

Unable to logon FIX server with python using quickfix


I´m trying to connect to an available FIX server using quickfix in python and I´m facing some problems I cannot resolve. I´ve checked this question which looks pretty similar what I´m facing, but no clue about how to fix the problem. Apparently it´s a problem related with my configuration file, but I´ve double checked and still not lucky.

I´m using this ini file.

[DEFAULT]
PersistMessages=Y
ConnectionType=initiator
UseDataDictionary=Y
StartTime=00:00:00
EndTime=23:59:00
FileStorePath=incoming 
FileLogPath=outgoing 

[SESSION]
StartTime=00:00:00
SenderCompID=8826
SenderSubID=350
EndTime=00:00:00
ConnectionType=initiator
ApplVerID=9
BeginString=FIXT.1.1
DefaultApplVerID=9
TransportDataDictionary=FIXT11.xml
AppDataDictionary=FIX50SP2.xml
TargetCompID=XMEF
TargetSubID=M3
SocketConnectPort=8238
SocketConnectHost=10.166.0.2
SocketUseSSL=Y
SSLEnable=Y
HeartBtInt=20
ReconnectInterval=30
SSLValidateCertificates=Y

When I´m trying to connect I get next result in console

Logon msg to Admin
<20211014-14:31:56.000000000, FIXT.1.1:8826->XMEF, outgoing>
  (8=FIXT.1.19=12035=A34=149=882650=35052=20211014-14:31:56.00056=BMEX57=EQ1408=T5.1098=0108=20553=8826350554=*****1137=910=253)
<20211014-14:31:56.000000000, FIXT.1.1:8826->XMEF, event>
  (Initiated logon request)
<20211014-14:31:57.000000000, FIXT.1.1:8826->XMEF, incoming>
  (8=FIXT.1.19=12935=A34=152=20211014-14:31:57.14315949=BMEX50=EQ56=882657=35098=0108=201137=91408=T5.10464=Y21504=100021505=2021072110=245)
<20211014-14:31:57.000000000, FIXT.1.1:8826->XMEF, event>
  (Message 1 Rejected: CompID problem)
<20211014-14:31:57.000000000, FIXT.1.1:8826->XMEF, event>
  (Tried to send a reject while not logged on)
<20211014-14:31:57.000000000, FIXT.1.1:8826->XMEF, event>
  (Disconnecting)

My toAdmin method in application class is this

def toAdmin(self, message, sessionID):
        msg_type = fix.MsgType()
        message.getHeader().getField(msg_type)
        if msg_type.getString() is fix.MsgType_Logon:
            message.getHeader().setField(fix.StringField(34, "1"))
            message.getHeader().setField(fix.SenderCompID("8826"))
            message.getHeader().setField(fix.SenderSubID("350"))
            message.getHeader().setField(fix.StringField(1408, "T5.10"))
            message.getHeader().setField(fix.TargetCompID("BMEX"))
            message.getHeader().setField(fix.TargetSubID("EQ"))
            message.setField(fix.Username("8826350"))
            message.setField(fix.Password("******"))
            print("Logon msg to Admin") 

And I've also modified FIXT1.1 Logon message in this way, but I think that's ok

<message msgcat='admin' msgtype='A' name='Logon'>
      <field name='EncryptMethod' required='Y'/>
      <field name='HeartBtInt' required='Y'/>
      <field name='RawDataLength' required='N'/>
      <field name='RawData' required='N'/>
      <field name='ResetSeqNumFlag' required='N'/>
      <field name='NextExpectedMsgSeqNum' required='N'/>
      <field name='MaxMessageSize' required='N'/>
      <field name='TestMessageIndicator' required='N'/>
      <field name='Username' required='N'/>
      <field name='Password' required='N'/>
      <field name='DefaultCstmApplVerID' required='N'/>
      <field name='BusinessSessionDate' required='N'/>
      <field name='MaxMsgPerSecond' required='N'/>    
      <field name='DefaultApplVerID' required='Y'/>
      <component name='MsgTypeGrp' required='N'/>
    </message>
  </messages>
  <components>
    <component name='MsgTypeGrp'>
      <group name='NoMsgTypes' required='N'>
        <field name='RefMsgType' required='N'/>
        <field name='MsgDirection' required='N'/>
        <field name='RefApplVerID' required='N'/>
        <field name='RefCstmApplVerID' required='N'/>
      </group>
    </component>
  </components>
  <fields>
    <field number='1408' name='DefaultCstmApplVerID' type='STRING'/>
    <field name='MaxMsgPerSecond' number='21504' type='INT'/>
    <field name='BusinessSessionDate' number='21505' type='LOCALMKTDATE'/>

I´ve double checked FIX message I´m sending or receiving using Wireshark and I´m just sending a Logon message (MsgType=A) and receiving a Logon msg, a Network Status Response (MsgType=BD) and several Registration Instructions Response (MsgType=p) in an endless loop. I assume this is due to ReconnectInterval sets to 30 in my ini file. But mystery here is my machine is not sending any RejectMsg (MsgType=3 I guess), reject information is just displayed in console, but not sent to the network. I think tunnel itself is being cut off from quickfix as default behavior when something is wrong, but not even sure.

My question is, what I'm doing wrong? I think quickfix is interrumpting a conexion which is accepted and pertectly ok from server, but I don't know why, so I cannot fix it.

Any idea?

Thanks a lot for your help


Solution

  • I think I´ve found the problem. Config file info referring to TargetCompID and TargetSubID are not being considered to create Logon message but apparently they are considered to double check server response. I had different values in ini file and in toAdmin method. Modifying these values in ini file in order to they are aligned with the ones provided in toAdmin seems to fix the problem.

    Thanks for reading me :_)