0

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

这是我迄今为止尝试过的:

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

有任何想法吗?

4

2 回答 2

1

它与“FIX.4.4”的值无关,它与setStrings的定义有关;

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

它通过引用获取这些字符串,并且您将其传递给它一个临时变量,该变量在setString尝试访问该值时被释放。因为你不能改变你需要做的函数定义;

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

为所有setString呼叫,以便此工作。至少对我来说,这会阻止我走这条路。

于 2012-11-19T18:16:42.400 回答
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;
}
于 2012-11-20T18:27:32.423 回答