-
Notifications
You must be signed in to change notification settings - Fork 254
/
itch_handler.cpp
110 lines (89 loc) · 4.29 KB
/
itch_handler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// Created by Ivan Shynkarenka on 24.07.2017
//
#include "trader/providers/nasdaq/itch_handler.h"
#include "benchmark/reporter_console.h"
#include "filesystem/file.h"
#include "system/stream.h"
#include "time/timestamp.h"
#include <OptionParser.h>
using namespace CppCommon;
using namespace CppTrader::ITCH;
class MyITCHHandler : public ITCHHandler
{
public:
MyITCHHandler()
: _messages(0),
_errors(0)
{}
size_t messages() const { return _messages; }
size_t errors() const { return _errors; }
protected:
bool onMessage(const SystemEventMessage& message) override { ++_messages; return true; }
bool onMessage(const StockDirectoryMessage& message) override { ++_messages; return true; }
bool onMessage(const StockTradingActionMessage& message) override { ++_messages; return true; }
bool onMessage(const RegSHOMessage& message) override { ++_messages; return true; }
bool onMessage(const MarketParticipantPositionMessage& message) override { ++_messages; return true; }
bool onMessage(const MWCBDeclineMessage& message) override { ++_messages; return true; }
bool onMessage(const MWCBStatusMessage& message) override { ++_messages; return true; }
bool onMessage(const IPOQuotingMessage& message) override { ++_messages; return true; }
bool onMessage(const AddOrderMessage& message) override { ++_messages; return true; }
bool onMessage(const AddOrderMPIDMessage& message) override { ++_messages; return true; }
bool onMessage(const OrderExecutedMessage& message) override { ++_messages; return true; }
bool onMessage(const OrderExecutedWithPriceMessage& message) override { ++_messages; return true; }
bool onMessage(const OrderCancelMessage& message) override { ++_messages; return true; }
bool onMessage(const OrderDeleteMessage& message) override { ++_messages; return true; }
bool onMessage(const OrderReplaceMessage& message) override { ++_messages; return true; }
bool onMessage(const TradeMessage& message) override { ++_messages; return true; }
bool onMessage(const CrossTradeMessage& message) override { ++_messages; return true; }
bool onMessage(const BrokenTradeMessage& message) override { ++_messages; return true; }
bool onMessage(const NOIIMessage& message) override { ++_messages; return true; }
bool onMessage(const RPIIMessage& message) override { ++_messages; return true; }
bool onMessage(const LULDAuctionCollarMessage& message) override { ++_messages; return true; }
bool onMessage(const UnknownMessage& message) override { ++_errors; return true; }
private:
size_t _messages;
size_t _errors;
};
int main(int argc, char** argv)
{
auto parser = optparse::OptionParser().version("1.0.0.0");
parser.add_option("-i", "--input").dest("input").help("Input file name");
optparse::Values options = parser.parse_args(argc, argv);
// Print help
if (options.get("help"))
{
parser.print_help();
return 0;
}
MyITCHHandler itch_handler;
// Open the input file or stdin
std::unique_ptr<Reader> input(new StdInput());
if (options.is_set("input"))
{
File* file = new File(Path(options.get("input")));
file->Open(true, false);
input.reset(file);
}
// Perform input
size_t size;
uint8_t buffer[8192];
std::cout << "ITCH processing...";
uint64_t timestamp_start = Timestamp::nano();
while ((size = input->Read(buffer, sizeof(buffer))) > 0)
{
// Process the buffer
itch_handler.Process(buffer, size);
}
uint64_t timestamp_stop = Timestamp::nano();
std::cout << "Done!" << std::endl;
std::cout << std::endl;
std::cout << "Errors: " << itch_handler.errors() << std::endl;
std::cout << std::endl;
size_t total_messages = itch_handler.messages();
std::cout << "Processing time: " << CppBenchmark::ReporterConsole::GenerateTimePeriod(timestamp_stop - timestamp_start) << std::endl;
std::cout << "Total ITCH messages: " << total_messages << std::endl;
std::cout << "ITCH message latency: " << CppBenchmark::ReporterConsole::GenerateTimePeriod((timestamp_stop - timestamp_start) / total_messages) << std::endl;
std::cout << "ITCH message throughput: " << total_messages * 1000000000 / (timestamp_stop - timestamp_start) << " msg/s" << std::endl;
return 0;
}