21 #include <unordered_map> 47 #define KNOWN_ITCH5_MESSAGES \ 48 jb::itch5::add_order_message, jb::itch5::add_order_mpid_message, \ 49 jb::itch5::broken_trade_message, jb::itch5::cross_trade_message, \ 50 jb::itch5::ipo_quoting_period_update_message, \ 51 jb::itch5::market_participant_position_message, \ 52 jb::itch5::mwcb_breach_message, jb::itch5::mwcb_decline_level_message, \ 53 jb::itch5::net_order_imbalance_indicator_message, \ 54 jb::itch5::order_cancel_message, jb::itch5::order_delete_message, \ 55 jb::itch5::order_executed_message, \ 56 jb::itch5::order_executed_price_message, \ 57 jb::itch5::order_replace_message, \ 58 jb::itch5::reg_sho_restriction_message, \ 59 jb::itch5::stock_directory_message, \ 60 jb::itch5::stock_trading_action_message, \ 61 jb::itch5::system_event_message, jb::itch5::trade_message 63 int main(
int argc,
char* argv[])
try {
65 cfg.load_overrides(argc, argv, std::string(
"mold2inside.yaml"),
"JB_ROOT");
68 boost::asio::io_service io_service;
70 boost::iostreams::filtering_ostream out;
73 std::map<jb::itch5::stock_t, jb::offline_feed_statistics> per_symbol;
82 auto pl = std::chrono::steady_clock::now() - update.recvts;
84 stats, out, header, updated_book, update, pl);
86 if (cfg.enable_symbol_stats()) {
90 cb = [&stats, &out, &per_symbol, symcfg](
95 auto pl = std::chrono::steady_clock::now() - update.recvts;
97 stats, out, header, updated_book, update, pl)) {
100 auto location = per_symbol.find(update.stock);
101 if (location == per_symbol.end()) {
102 auto p = per_symbol.emplace(
106 location->second.sample(header.timestamp.ts, pl);
112 auto process_buffer = [&handler](
114 std::size_t msgoffset,
char const* msgbuf, std::size_t msglen) {
118 process(handler, recv_ts, msgcnt, msgoffset, msgbuf, msglen);
122 io_service, std::move(process_buffer), cfg.receiver());
127 for (
auto const& i : per_symbol) {
128 i.second.print_csv(i.first.c_str(), std::cout);
130 stats.print_csv(
"__aggregate__", std::cout);
134 std::cerr << u.what() << std::endl;
136 }
catch (std::exception
const& ex) {
137 std::cerr <<
"Standard exception raised: " << ex.what() << std::endl;
140 std::cerr <<
"Unknown exception raised" << std::endl;
151 .max_processing_latency_nanoseconds(10000)
152 .max_interarrival_time_nanoseconds(10000)
153 .max_messages_per_microsecond(1000)
154 .max_messages_per_millisecond(10000)
155 .max_messages_per_second(10000)
159 std::string
const local_address =
"";
160 std::string
const address =
"::1";
161 int const port = 50000;
167 .port(defaults::port)
168 .local_address(defaults::local_address)
169 .address(defaults::address))
172 .help(
"The name of the file where to store the inside data." 173 " Files ending in .gz are automatically compressed."),
175 , log(desc(
"log",
"logging"),
this)
176 , stats(desc(
"stats",
"offline-feed-statistics"),
this)
178 desc(
"symbol-stats",
"offline-feed-statistics"),
this,
179 defaults::per_symbol_stats())
180 , enable_symbol_stats(
181 desc(
"enable-symbol-stats")
183 "If set, enable per-symbol statistics." 184 " Collecting per-symbol statistics is expensive in both" 185 " memory and execution time, so it is disabled by default."),
189 void config::validate()
const {
191 if (output_file() ==
"") {
193 "Missing output-file setting." 194 " You must specify an output file.",
199 symbol_stats().validate();
jb::config_attribute< config, int > reporting_interval_seconds
Compute the book and call a user-defined callback on each change.
Define defaults for program parameters.
clock_type::time_point time_point
A convenience alias for clock_type::time_point.
Base class for all configuration objects.
virtual void validate() const
Validate the settings.
Keep statistics about a feed and its offline processor.
void open_output_file(boost::iostreams::filtering_ostream &out, std::string const &filename)
Open a file for writing.
int main(int argc, char *argv[])
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.
A simple class to communicate the result of parsing the options.
A flat struct to represent updates to an order book.
bool generate_inside(jb::offline_feed_statistics &stats, std::ostream &out, jb::itch5::message_header const &header, jb::itch5::order_book< book_type > const &book, jb::itch5::book_update const &update, duration_t processing_latency)
Determine if this event changes the inside, if so, record the statistics and output the result...
Process a buffer with a single message: parse it and call the handler.
Configure an map_based_order_book config object.
static void print_csv_header(std::ostream &os)
Print a CSV header.
#define KNOWN_ITCH5_MESSAGES
Maintain the ITCH-5.0 order book for a single security.
Configure an offline_feed_statistics object.
A configuration object for UDP receivers.
Create and manage a socket to receive MoldUDP64 packets.