0

How can I hardcode the settings of the initiator and the acceptor, so that I don't need an external settings file?

This is what I've tried so far:

FIX::SessionSettings serverSettings;
FIX::Dictionary serverDictionary;

serverDictionary.setString("BeginString", "FIX.4.4");
serverDictionary.setString("UseDataDictionary", "Y");
serverDictionary.setString("DataDictionary", "../../../spec/FIX.4.4.xml");
serverDictionary.setString("SenderCompID", "SRVR");
serverDictionary.setString("TargetCompID", "CLNT");
serverDictionary.setString("SocketAcceptHost", "localhost");
serverDictionary.setLong("SocketAcceptPort", 2024);

FIX::SessionID serverSessionID;
serverSettings.set(serverSessionID, serverDictionary);

Server server; // Extends FIX::Application

FIX::FileStoreFactory serverStoreFactory("server/fileStore/");
FIX::FileLogFactory serverLogFactory("server/logs/");

FIX::SocketAcceptor acceptor(server, serverStoreFactory, serverSettings, serverLogFactory);

I think I'm on the right path but I get this error: Configuration failed: BeginString must be FIX.4.0 to FIX.4.4 or FIXT.1.1

Any ideas?

Qsiris
  • 1,143
  • 1
  • 13
  • 27

2 Answers2

1

It has nothing to do with the value of "FIX.4.4" it's about setStrings definition which is;

void Dictionary::setString( const std::string& key, const std::string& value )

It's taking those strings by reference and you're passing it a temporary variable which is freed by the time setString tries to access the value. Since you can't change the functions definition you need to do;

std::string key = "current key";
std::string value = "current value";
serverDictionary.setString(key, value);

for all setString calls in order for this to work. Which, to me at least, would stop me from going this route.

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
  • 4.4 is an accepted value. It works if I use an external settings file. – Qsiris Nov 19 '12 at 18:44
  • @ovidiub13 If you can read from the file and it works, set a break point before you call `serverDictionary.setString("BeginString", "FIX.4.4");` and inspect the value that you're passing where "FIX.4.4" is. Whatever that value is is what you need to pass in place of "FIX.4.4". – evanmcdonnal Nov 19 '12 at 18:49
  • I've tried that. The value set is the right one. The question is: is this the right way to set up the settings? – Qsiris Nov 19 '12 at 19:08
  • I've tried it. The value set is correct. But if that value gets in the right place, that I don't know. – Qsiris Nov 19 '12 at 23:17
  • I've tried to set the strings in `const std::string`s and I've got the same result. It doesn't work. – Qsiris Nov 20 '12 at 16:01
1

After lot's of struggle I've finally managed to get this right. Here is the functional code to hardcode the settings in the acceptor, can also be applied in the initiator:

try {
    FIX::SessionSettings serverSettings;
    FIX::Dictionary serverDictionary;

    serverDictionary.setString("ConnectionType", "acceptor");
    serverDictionary.setString("DataDictionary", "FIX.4.4.xml");
    serverDictionary.setString("StartTime", "00:00:00");
    serverDictionary.setString("EndTime", "00:00:00");
    serverDictionary.setString("SocketAcceptHost", "localhost");
    serverDictionary.setString("SocketAcceptPort", "2024");

    FIX::SessionID serverSessionID("FIX.4.4", "SRVR", "CLNT");
    serverSettings.set(serverSessionID, serverDictionary);

    Server server;
    FIX::FileStoreFactory serverStoreFactory("server/fileStore/");
    FIX::FileLogFactory serverLogFactory("server/logs/");
    FIX::SocketAcceptor acceptor(server, serverStoreFactory, serverSettings, serverLogFactory);
    acceptor.start();
    // do something
    acceptor.stop();

    return 0;
} catch (FIX::ConfigError& e) {
    std::cout << e.what() << std::endl;
    return 1;
}
Qsiris
  • 1,143
  • 1
  • 13
  • 27