To simplify development and testing, the Handler's SDK includes the Gateway Emulator. The Emulator simulates the CME Gateway. It can accept a connection, establish a FIXP session, and send/receive session-level/application-level messages. To receive notifications about incoming message, there are corresponding callbacks declared in OnixS::CME::iLink3::Testing::ClientMessageListener and OnixS::CME::iLink3::Testing::ClientSessionMessageListener classes. One can inherit from the corresponding class, override corresponding virtual methods, and implement the necessary logic.
To simplify running and testing, most of the samples from the distribution package use the Gateway Emulator by default. Therefore, one can see in detail how to use the Gateway Emulator.
- Note
- The Gateway Emulator is supported in C++11 or higher codebase only.
Example
{
public:
{
std::clog << msg << std::endl;
}
};
{
public:
{
updateReport(order);
report_->setUuId(gateway->
uuid());
gateway->
send(report_, ++reportsCounter_);
}
private:
{
report_->setClOrdId(order.
clOrdId())
.setExecId(std::to_string(reportsCounter_))
.setOrderId(reportsCounter_)
.setTransactTime(sinchEpoch)
.setSendingTimeEpoch(sinchEpoch)
report_->setTimeInForce(timeInForce);
report_->setPrice(price);
else
report_->setPrice(
PRICE9(10));
}
};
const std::string CounterpartyHost = "Localhost";
const int CounterpartyPort = 64124;
Testing::Gateway gateway(licenseStores, CounterpartyPort, CounterpartyHost.c_str());
std::promise<void> emulatorTaskPromise;
std::future<void> emulatorTaskDone = emulatorTaskPromise.get_future();
std::thread(
std::bind(
[&](std::promise<void>& p)
{
try
{
GatewayListener clientMessageListener;
gateway.
run(clientMessageListener);
p.set_value();
}
catch (...)
{
std::cerr << "Exception in Emulator's thread." << std::endl;
p.set_exception(
std::current_exception());
}
},
std::move(emulatorTaskPromise)))
.detach();
.secretKey("secretKey")
.accessKey("accessKey")
.firmId("firmId");
MyListener listener;
const int MarketSegmentId = 54;
Session session(settings, MarketSegmentId, &listener);
session.
connect(CounterpartyHost, CounterpartyPort);
NewOrderSingle order;
emulatorTaskDone.get();