Search code examples
quickfixn

One acceptor and several dynamic initiators


I just started my acquaintance with the FIX protocol. For this I use the QuickFIX/n library version 1.11.0. Also QuickFIXn.FIX5.0SP2 and QuickFIXn.FIXT1.1 (all versions 1.11.0) There is an acceptor configuration.

[DEFAULT]
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2
HeartBtInt=20
AppDataDictionary=../../../ApplicationData/FIXRTv1.xml
TransportDataDictionary=../../../ApplicationData/FIXT11.xml

FileLogPath=log
SocketAcceptPort=9823 
SocketAcceptHost = 127.0.0.1
ConnectionType=acceptor
UseDataDictionary=Y
ResetOnLogon=Y
ResetOnLogout=Y
ResetOnDisconnect=Y

SenderCompID=TEST
StartTime=00:00:00
EndTime=23:59:00
FileStorePath=store

There is an initiator configuration.

[DEFAULT]
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2
ConnectionType=initiator
HeartBtInt=20
AppDataDictionary=../../spec/fix/FIXRTv1.xml
TransportDataDictionary=../../spec/fix/FIXT11.xml
UseDataDictionary=Y

ResetOnLogon=Y
ResetOnLogout=Y
ResetOnDisconnect=Y
FileStorePath=store
FileLogPath=log

[SESSION]
SenderCompID=USER
TargetCompID=TEST
SocketConnectHost=127.0.0.1 
SocketConnectPort=9823 

StartTime=00:00:00
EndTime=23:59:00

As you can see in the acceptor configuration, only DEFAULT is defined. If you add it SESSION indicating for the initiator, then everything works. Otherwise, the initiator issues an error Connection failed: The connection was not established because The destination computer rejected the connection request. 127.0.0.1:9823

Is it possible to connect initiators unknown to it in advance to the acceptor and dynamically create sessions for them?


Solution

  • Thanks @Christoph John .Link to comment: One acceptor and several dynamic initiators

    Simple code that can add dynamic sessions when the acceptor is running:

    var HttpServerPrefix = "http://127.0.0.1:5080/";
    SessionSettings settings = new SessionSettings(pathToConfig);
    IApplication executorApp = new MyAcceptor();
    IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
    ILogFactory logFactory = new FileLogFactory(settings);
    ThreadedSocketAcceptor acceptor = new ThreadedSocketAcceptor(executorApp, storeFactory, settings, logFactory);
    HttpServer srv = new HttpServer(HttpServerPrefix, settings);
    
    acceptor.Start();
    srv.Start();
    
    while (true)
    {
        Console.WriteLine("Add session?");
        var answer = Console.ReadLine();
    
        if(answer == "Y")
        {
            Console.WriteLine("Input comp:");
            var comp = Console.ReadLine();
            var dictSettings = new Dictionary();
            var sessionId = new SessionID("FIXT.1.1", "MyAcceptor", comp);
            acceptor.AddSession(sessionId, dictSettings);
        }
    }
    
    srv.Stop();
    acceptor.Stop();
    

    You can view the sessions created by the HttpServerPrefix link.