To simplify development and testing, the Handler's SDK includes the Gateway Emulator. The Emulator simulates the Gateway. It can accept a connection, establish a session, and send/receive session-level/application-level messages. To receive notifications about incoming message, there are corresponding callbacks declared in OnixS::ICE::BOE::Testing::ClientMessageListener and OnixS::ICE::BOE::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.
Example
{
public:
void onExecutionReport_New(const ExecutionReport_New msg, Session* ) override
{
std::clog << msg << std::endl;
}
};
{
public:
void onNewOrderRequest(const NewOrderRequest& order, Testing::Gateway* gateway) override
{
updateReport(order);
gateway->
send(report_, ++reportsCounter_);
}
private:
void updateReport(const NewOrderRequest& order)
{
const auto sinchEpoch = UtcWatch::now().sinceEpoch();
constexpr static auto sid = 123;
const OrderExecID id{sid, reportsCounter_, sinchEpoch};
report_->clOrdId(order.
clOrdId()).execId(
id);
}
MessageHolder<ExecutionReport_New> report_;
Int32 reportsCounter_{ 0 };
};
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();
.rawData("rawData")
.ipSessionToken("ipSessionToken")
.clientId(1);
MyListener listener;
session.connect(host, port);
NewOrderSingle order;
session.send(order).disconnect();
emulatorTaskDone.get();