This sample shows how to use Handler replay functional.
#include <iostream>
class MyListener
{
public:
void onError(ErrorCode::Enum code, const std::string& description) final
{
std::clog
<< "Error occurred, errorCode = "
<< ". Description: '"
<< description
<< "'"
<< std::endl;
}
void onWarning(const std::string& description) final
{
std::clog
<< "Warning occurred. Description: '"
<< description
<< "'"
<< std::endl;
};
void onReplayError(const std::string& errorDescription) final
{
std::clog << "Replay error: " << errorDescription << std::endl;
replaySemaphore_.release();
}
void onReplayFinished() final
{
replaySemaphore_.release();
}
void waitUntilReplayFinished()
{
replaySemaphore_.acquire();
}
void onSequenceReset_1(const Messaging::SequenceReset_1 msg, const DataSource&) final
{
std::clog << msg << std::endl;
}
void onSequence_2(const Messaging::Sequence_2 msg, const DataSource&) final
{
std::clog << msg << std::endl;
}
void onEmptyBook_9(const Messaging::EmptyBook_9 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onChannelReset_11(const Messaging::ChannelReset_11 msg, const DataSource&) final
{
std::clog << msg << std::endl;
}
void onSecurityStatus_3(const Messaging::SecurityStatus_3 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onSecurityGroupPhase_10(const Messaging::SecurityGroupPhase_10 msg, const DataSource&) final
{
std::clog << msg << std::endl;
}
void onSecurityDefinition_12(const Messaging::SecurityDefinition_12 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onSnapshotFullRefresh_Header_30(const Messaging::SnapshotFullRefresh_Header_30 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onSnapshotFullRefresh_Orders_MBO_71(const Messaging::SnapshotFullRefresh_Orders_MBO_71 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onNews_5(const Messaging::News_5 msg, const DataSource&) final
{
std::clog << msg << std::endl;
}
void onClosingPrice_17(const Messaging::ClosingPrice_17 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onQuantityBand_21(const Messaging::QuantityBand_21 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onPriceBand_22(const Messaging::PriceBand_22 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onOpeningPrice_15(const Messaging::OpeningPrice_15 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onTheoreticalOpeningPrice_16(const Messaging::TheoreticalOpeningPrice_16 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onAuctionImbalance_19(const Messaging::AuctionImbalance_19 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onHighPrice_24(const Messaging::HighPrice_24 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onLowPrice_25(const Messaging::LowPrice_25 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onLastTradePrice_27(const Messaging::LastTradePrice_27 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onSettlementPrice_28(const Messaging::SettlementPrice_28 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onOpenInterest_29(const Messaging::OpenInterest_29 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onOrder_MBO_50(const Messaging::Order_MBO_50 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onDeleteOrder_MBO_51(const Messaging::DeleteOrder_MBO_51 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onMassDeleteOrders_MBO_52(const Messaging::MassDeleteOrders_MBO_52 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onTrade_53(const Messaging::Trade_53 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onForwardTrade_54(const Messaging::ForwardTrade_54 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onExecutionSummary_55(const Messaging::ExecutionSummary_55 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onExecutionStatistics_56(const Messaging::ExecutionStatistics_56 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
void onTradeBust_57(const Messaging::TradeBust_57 msg, const DataSource&, SecurityContext&) final
{
std::clog << msg << std::endl;
}
private:
System::Semaphore replaySemaphore_;
};
{
MyListener listener;
handler.registerMessageListener(&listener);
replayOptions.
files.push_back (
"data/log.log.gz");
handler.replayLogs(replayOptions);
listener.waitUntilReplayFinished();
}
{
MyListener listener;
handler.registerMessageListener(&listener);
replayOptions.
files.push_back(
"data/Incrementals.pcap.gz");
handler.replayPcap(replayOptions, {"data/Instruments.pcap.gz"}, {"data/Snapshots.pcap.gz"});
listener.waitUntilReplayFinished();
}
int main ()
{
std::clog
<< "OnixS C++ B3 Binary UMDF Market Data Handler Backtesting sample, version "
<< '.'
<< std::endl
<< std::endl;
try
{
std::clog << "Will start the Handler in replay mode ..." << std::endl;
std::clog << "Replay finished" << std::endl;
}
catch (const std::exception& ex)
{
std::cerr << "EXCEPTION: " << ex.what() << std::endl;
}
catch (...)
{
std::cerr << "UNKNOWN EXCEPTION" << std::endl;
}
return 0;
}