21 #include <unordered_map> 45 template <
typename book_type>
46 void record_book_depth(
50 auto buy_price_levels =
54 stats.
sample(buy_price_levels + sell_price_levels);
59 int main(
int argc,
char* argv[])
try {
61 cfg.load_overrides(argc, argv, std::string(
"itch5bookdepth.yaml"),
"JB_ROOT");
64 boost::iostreams::filtering_istream in;
67 boost::iostreams::filtering_ostream out;
70 std::map<jb::itch5::stock_t, jb::book_depth_statistics> per_symbol;
79 record_book_depth(stats, header, updated_book, update);
82 if (cfg.enable_symbol_stats()) {
85 chain = [&per_symbol, symcfg, cb](
89 cb(header, book, update);
90 auto location = per_symbol.find(update.
stock);
91 if (location == per_symbol.end()) {
92 auto p = per_symbol.emplace(
96 record_book_depth(location->second, header, book, update);
98 cb = std::move(chain);
103 std::move(cb), cfg_bk);
107 for (
auto const& i : per_symbol) {
108 i.second.print_csv(i.first.c_str(), out);
114 std::cerr << u.what() << std::endl;
116 }
catch (std::exception
const& ex) {
117 std::cerr <<
"Standard exception raised: " << ex.what() << std::endl;
120 std::cerr <<
"Unknown exception raised" << std::endl;
127 #ifndef JB_ITCH5BOOKDEPTH_DEFAULT_per_symbol_max_book_depth 128 #define JB_ITCH5BOOKDEPTH_DEFAULT_per_symbol_max_book_depth 5000 129 #endif // JB_ITCH5BOOKDEPTH_DEFAULT_per_symbol_max_book_depth 139 desc(
"input-file").help(
"An input file with ITCH-5.0 messages."),
143 .help(
"The name of the file where to store the statistics." 144 " By default output to stdout." 145 " Files ending in .gz are automatically compressed."),
147 , log(
desc(
"log",
"logging"),
this)
148 , stats(
desc(
"stats",
"book-depth-statistics"),
this)
150 desc(
"symbol-stats",
"book-depth-statistics-per-symbol"),
this,
151 default_per_symbol_stats())
152 , enable_symbol_stats(
153 desc(
"enable-symbol-stats")
154 .help(
"If set, enable per-symbol statistics." 155 " Collecting per-symbol statistics is expensive in both" 156 " memory and execution time, enable only if needed."),
160 void config::validate()
const {
161 if (input_file() ==
"") {
163 "Missing input-file setting." 164 " The program needs an input file to read ITCH-5.0 data from.",
167 if (output_file() ==
"") {
169 "Missing output-file setting." 170 " Use 'stdout' if you want to print to the standard output.",
175 symbol_stats().validate();
Compute the book and call a user-defined callback on each change.
half_quote worst_bid() const
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 print_csv(std::string const &name, std::ostream &os) const
Print all the measurements in CSV format.
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
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.
#define JB_ITCH5BOOKDEPTH_DEFAULT_per_symbol_max_book_depth
Limit the amount of memory used on each per-symbol statistics.
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.
half_quote worst_offer() const
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.
int main(int argc, char *argv[])
half_quote best_offer() const