4

After reading the config file:

f = "excfg.cfg"
settings = fix.SessionSettings(f)

Is it possible to modify the settings of a particular session dynamically? For example modifying the TargetCompID or the SocketAcceptPort.

I am pretty much looking for an alternative to this:

dictionary = settings.get()
id1 = fix.SessionID(dictionary.getString(fix.BEGINSTRING),
                    dictionary.getString(fix.SENDERCOMPID), "EX1")

dictionary.setInt(fix.SOCKET_ACCEPT_PORT, 7001)
settings.set(id1, dictionary)

Where I don't create a new SessionID but modify the existing one from the config file, before the SocketAcceptor/SocketInitiator function is called.

dgouder
  • 339
  • 2
  • 11
  • `particular session dynamically` Oh no don't do that, you will open a can of worms. Better just have fail safe mechanism like switching over to different IPs which Quickfix does for you. Dynamically changing means your connection can be hijacked, very difficult but not impossibel. – DumbCoder May 20 '16 at 17:18
  • Our purpose is a localized testing framework so there would be no external connections for that matter. – dgouder May 22 '16 at 16:52
  • 1
    I believe once you apply `dictionary.set*` the change is applied to the settings as well since `dictionary` is just a reference and not a copy (i.e. no need to call `settings.set` with the modified dictionary). Not sure you tried that. – sirfz Jul 01 '16 at 17:28

1 Answers1

2

You don't need to execute settings.set, since the dictionary returned by settings.get contains references (instead of copies) to the sessions settings:

import quickfix as fix

# print the current port 
settings = fix.SessionSettings('/opt/robotfx/etc/fxgo-config/config.txt', True)
session_settings = settings.get(fix.SessionID('FIX.4.4','SENDER','TARGET'))  
print('current port=', session_settings.getString('SocketConnectPort'))

# updates the port value, get the session settings again and print the current port
session_settings.setString('SocketConnectPort', '1234')
session_settings = settings.get(fix.SessionID('FIX.4.4','SENDER','TARGET'))  
print('current port=', session_settings.getString('SocketConnectPort'))

output:

current port=31337
current port=1234
Hugo Corrá
  • 14,546
  • 3
  • 27
  • 39