如何硬编码设置

时间:2012-11-19 18:11:47

标签: c++ settings quickfix hardcode

如何硬编码启动器和接受器的设置,以便我不需要外部设置文件?

这是我到目前为止所尝试的:

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);

我认为我走的是正确的道路,但我收到了这个错误:Configuration failed: BeginString must be FIX.4.0 to FIX.4.4 or FIXT.1.1

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

经过多次努力,我终于成功地做到了这一点。以下是对接受器中的设置进行硬编码的功能代码,也可以应用于启动器:

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;
}