22 #include <unordered_map> 47 template <
typename book_type>
48 void record_event_depth(
74 int main(
int argc,
char* argv[])
try {
77 argc, argv, std::string(
"itch5eventdepth.yaml"),
"JB_ROOT");
80 boost::iostreams::filtering_istream in;
83 boost::iostreams::filtering_ostream out;
86 std::map<jb::itch5::stock_t, jb::book_depth_statistics> per_symbol;
95 record_event_depth(aggregate_stats, header, updated_book, update);
98 if (cfg.enable_symbol_stats()) {
101 chain = [&per_symbol, symcfg, cb](
105 cb(header, book, update);
106 auto location = per_symbol.find(update.
stock);
107 if (location == per_symbol.end()) {
108 auto p = per_symbol.emplace(
112 record_event_depth(location->second, header, book, update);
114 cb = std::move(chain);
119 std::move(cb), cfg_bk);
123 for (
auto const& i : per_symbol) {
124 i.second.print_csv(i.first.c_str(), out);
126 aggregate_stats.print_csv(
"__aggregate__", out);
130 std::cerr << u.what() << std::endl;
132 }
catch (std::exception
const& ex) {
133 std::cerr <<
"Standard exception raised: " << ex.what() << std::endl;
136 std::cerr <<
"Unknown exception raised" << std::endl;
143 #ifndef JB_ITCH5EVENTDEPTH_DEFAULT_per_symbol_max_book_depth 144 #define JB_ITCH5EVENTDEPTH_DEFAULT_per_symbol_max_book_depth 5000 145 #endif // JB_ITCH5EVENTDEPTH_DEFAULT_per_symbol_max_book_depth 155 desc(
"input-file").help(
"An input file with ITCH-5.0 messages."),
159 .help(
"The name of the file where to store the statistics." 160 " By default output to stdout." 161 " Files ending in .gz are automatically compressed."),
163 , log(
desc(
"log",
"logging"),
this)
164 , stats(
desc(
"stats",
"event-depth-statistics"),
this)
166 desc(
"symbol-stats",
"event-depth-statistics-per-symbol"),
this,
167 default_per_symbol_stats())
168 , enable_symbol_stats(
169 desc(
"enable-symbol-stats")
170 .help(
"If set, enable per-symbol statistics." 171 " Collecting per-symbol statistics is expensive in both" 172 " memory and execution time, enable only if needed."),
176 void config::validate()
const {
177 if (input_file() ==
"") {
179 "Missing input-file setting." 180 " The program needs an input file to read ITCH-5.0 data from.",
183 if (output_file() ==
"") {
185 "Missing output-file setting." 186 " Use 'stdout' if you want to print to the standard output.",
191 symbol_stats().validate();
Compute the book and call a user-defined callback on each change.
Base class for all configuration objects.
void sample(book_depth_t book_depth)
Record a sample, that is book depth value after the event.
virtual void validate() const
Validate the settings.
static void print_csv_header(std::ostream &os)
Print a CSV header.
void open_output_file(boost::iostreams::filtering_ostream &out, std::string const &filename)
Open a file for writing.
void process_iostream(std::istream &in, message_handler &handler)
Process an iostream of ITCH-5.0 messages.
Keep statistics about a feed and its book depth.
void init(config const &cfg)
Initialize the logging functions using the configuration provided.
#define config_object_constructors(NAME)
Helper class to easily define configuration attributes.
std::function< void(message_header const &header, order_book< book_type > const &updated_book, book_update const &update)> callback_type
Define the callback type.
jb::config_attribute< config, book_depth_t > max_book_depth
No more than this value is recorded.
Configure a book_depth_statistics object.
half_quote best_bid() const
buy_sell_indicator_t buy_sell_indicator
What side of the book is being updated.
stock_t stock
The security updated by this order.
A simple class to communicate the result of parsing the options.
A flat struct to represent updates to an order book.
void open_input_file(boost::iostreams::filtering_istream &in, std::string const &filename)
Open a file for reading.
static attribute_descriptor desc(std::string const &name)
Convenience function to create attribute descriptors with less typing.
Configure an map_based_order_book config object.
std::size_t price_levels(price_field_t lo, price_field_t hi)
Compute the number of price levels between two prices.
Maintain the ITCH-5.0 order book for a single security.
#define JB_ITCH5EVENTDEPTH_DEFAULT_per_symbol_max_book_depth
Limit the amount of memory used on each per-symbol statistics.
int main(int argc, char *argv[])
half_quote best_offer() const
price4_t px
What price level is being updated.