8 #include <boost/test/unit_test.hpp> 22 int buy_count,
int offer_count));
29 template <
typename based_order_book>
33 ::testing::StrictMock<mock_book_callback> callback;
35 auto cb = [&callback](
39 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
42 typename based_order_book::config cfg;
43 compute_type tested(cb, cfg);
60 tested.handle_message(
70 auto symbols = tested.symbols();
71 BOOST_REQUIRE_EQUAL(symbols.size(), std::size_t(1));
72 BOOST_CHECK_EQUAL(symbols[0], stock);
83 tested.handle_message(
101 tested.handle_message(
116 template <
typename based_order_book>
121 ::testing::StrictMock<mock_book_callback> callback;
122 auto cb = [&callback](
126 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
129 typename based_order_book::config cfg;
131 compute_type tested(cb, cfg);
138 std::uint64_t
id = 2;
148 tested.handle_message(
158 auto symbols = tested.symbols();
159 BOOST_REQUIRE_EQUAL(symbols.size(), std::size_t(1));
160 BOOST_CHECK_EQUAL(symbols[0], stock);
170 tested.handle_message(
189 tested.handle_message(
204 template <
typename based_order_book>
212 typename compute_type::callback_type
const tmp(cb);
213 typename based_order_book::config cfg;
215 compute_type tested(tmp, cfg);
217 auto symbols = tested.symbols();
218 BOOST_REQUIRE_EQUAL(symbols.size(), std::size_t(0));
223 u
'a',
timestamp{std::chrono::nanoseconds(10)}, 128);
224 tested.handle_unknown(
225 now,
unknown_message{std::uint32_t(123), std::size_t(1000000), buf.size(),
231 std::uint64_t
id = 2;
235 tested.handle_message(
250 template <
typename based_order_book>
255 using namespace ::testing;
256 ::testing::StrictMock<mock_book_callback> callback;
257 auto cb = [&callback](
261 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
265 typename based_order_book::config cfg;
267 compute_type tested(cb, cfg);
275 std::uint64_t
id = 2;
279 using namespace ::testing;
280 EXPECT_CALL(callback, exec(_, _, _, _, _)).Times(1);
281 tested.handle_message(
292 tested.handle_message(
307 template <
typename based_order_book>
312 using namespace ::testing;
313 ::testing::StrictMock<mock_book_callback> callback;
314 auto cb = [&callback](
318 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
322 typename based_order_book::config cfg;
324 compute_type tested(cb, cfg);
331 std::uint64_t
id = 2;
332 auto const id_buy = ++id;
336 using namespace ::testing;
337 EXPECT_CALL(callback, exec(_, _, _, _, _)).Times(1);
339 tested.handle_message(
352 tested.handle_message(
361 EXPECT_CALL(callback, exec(_, _, _, _, _)).Times(1);
362 tested.handle_message(
370 tested.handle_message(
378 EXPECT_CALL(callback, exec(_, _, _, _, _)).Times(1);
379 auto const id_sell = ++id;
381 tested.handle_message(
398 tested.handle_message(
410 template <
typename based_order_book>
415 ::testing::StrictMock<mock_book_callback> callback;
416 auto cb = [&callback](
420 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
423 typename based_order_book::config cfg;
425 compute_type tested(cb, cfg);
433 std::uint64_t
id = 2;
434 auto const id_buy_1 = ++id;
435 auto const id_buy_2 = ++id;
436 auto const id_buy_3 = ++id;
440 using namespace ::testing;
441 EXPECT_CALL(callback, exec(_, _, _, _, _)).Times(1);
442 tested.handle_message(
454 tested.handle_message(
465 EXPECT_CALL(callback, exec(_, _, _, _, _)).Times(1);
466 tested.handle_message(
478 tested.handle_message(
492 template <
typename based_order_book>
497 using namespace ::testing;
498 ::testing::StrictMock<mock_book_callback> callback;
499 auto cb = [&callback](
503 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
506 typename based_order_book::config cfg;
508 compute_type tested(cb, cfg);
516 std::uint64_t
id = 2;
517 auto const id_buy = ++id;
527 tested.handle_message(
538 auto symbols = tested.symbols();
539 BOOST_REQUIRE_EQUAL(symbols.size(), std::size_t(1));
540 BOOST_CHECK_EQUAL(symbols[0], stock);
544 auto const id_sell = ++id;
552 tested.handle_message(
570 tested.handle_message(
585 tested.handle_message(
600 tested.handle_message(
617 tested.handle_message(
634 tested.handle_message(
649 tested.handle_message(
662 template <
typename based_order_book>
667 using namespace ::testing;
668 ::testing::StrictMock<mock_book_callback> callback;
669 auto cb = [&callback](
673 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
676 typename based_order_book::config cfg;
678 compute_type tested(cb, cfg);
687 std::uint64_t
id = 2;
688 auto const id_buy = ++id;
698 tested.handle_message(
709 auto symbols = tested.symbols();
710 BOOST_REQUIRE_EQUAL(symbols.size(), std::size_t(1));
711 BOOST_CHECK_EQUAL(symbols[0], stock);
722 auto const id_sell = ++id;
723 tested.handle_message(
736 auto id_sell_replx = ++id;
742 tested.handle_message(
753 auto id_buy_replx = ++id;
759 tested.handle_message(
773 template <
typename based_order_book>
778 using namespace ::testing;
779 ::testing::StrictMock<mock_book_callback> callback;
780 auto cb = [&callback](
784 update, b.best_bid(), b.best_offer(), b.buy_count(), b.sell_count());
787 typename based_order_book::config cfg;
788 compute_type tested(cb, cfg);
796 std::uint64_t
id = 2;
797 auto const id_buy = ++id;
807 tested.handle_message(
818 auto symbols = tested.symbols();
819 BOOST_REQUIRE_EQUAL(symbols.size(), std::size_t(1));
820 BOOST_CHECK_EQUAL(symbols[0], stock);
826 auto const id_sell = ++id;
832 tested.handle_message(
850 tested.handle_message(
864 tested.handle_message(
878 tested.handle_message(
891 tested.handle_message(
902 template <
typename based_order_book>
910 typename based_order_book::config cfg;
912 compute_type tested(cb, cfg);
921 auto actual = tested.symbols();
924 std::sort(expected.begin(), expected.end());
925 std::sort(actual.begin(), actual.end());
926 BOOST_CHECK_EQUAL_COLLECTIONS(
927 expected.begin(), expected.end(), actual.begin(), actual.end());
931 actual = tested.symbols();
932 std::sort(expected.begin(), expected.end());
933 std::sort(actual.begin(), actual.end());
934 BOOST_CHECK_EQUAL_COLLECTIONS(
935 expected.begin(), expected.end(), actual.begin(), actual.end());
949 t::test_compute_book_add_order_message_buy<map_based_order_book>();
950 t::test_compute_book_add_order_message_sell<map_based_order_book>();
952 t::test_compute_book_add_order_message_buy<array_based_order_book>();
953 t::test_compute_book_add_order_message_sell<array_based_order_book>();
962 t::test_compute_book_increase_coverage<map_based_order_book>();
963 t::test_compute_book_increase_coverage<array_based_order_book>();
973 t::test_compute_book_edge_cases<map_based_order_book>();
974 t::test_compute_book_edge_cases<array_based_order_book>();
984 t::test_compute_book_reduction_edge_cases<map_based_order_book>();
985 t::test_compute_book_reduction_edge_cases<array_based_order_book>();
994 t::test_compute_book_replace_edge_cases<map_based_order_book>();
995 t::test_compute_book_replace_edge_cases<array_based_order_book>();
1005 t::test_compute_book_order_executed_message<map_based_order_book>();
1006 t::test_compute_book_order_executed_message<array_based_order_book>();
1016 t::test_compute_book_order_replace_message<map_based_order_book>();
1017 t::test_compute_book_order_replace_message<array_based_order_book>();
1027 t::test_compute_book_order_cancel_message<map_based_order_book>();
1028 t::test_compute_book_order_cancel_message<array_based_order_book>();
1038 t::test_compute_book_stock_directory_message<map_based_order_book>();
1039 t::test_compute_book_stock_directory_message<array_based_order_book>();
1050 auto const ts0 = clock_type::now();
1051 std::this_thread::sleep_for(std::chrono::milliseconds(20));
1052 auto const ts1 = clock_type::now();
1073 std::ostringstream os;
1075 BOOST_CHECK_EQUAL(os.str(),
"{A,B,0.1000,300}");
static constexpr int message_type
void test_compute_book_add_order_message_buy()
Test compute book based on book type.
static constexpr int message_type
Compute the book and call a user-defined callback on each change.
void test_compute_book_order_replace_message()
Test compute book order replace message.
Contains classes and functions to parse NASDAQ ITCH-5.0 messages, more information about ITCH-5...
clock_type::time_point time_point
A convenience alias for clock_type::time_point.
Represent an 'Order Executed' message in the ITCH-5.0 protocol.
static constexpr int message_type
half_quote empty_bid()
The value used to represent an empty bid.
char_list_field< u 'S', u 'B'> buy_sell_indicator_t
Represent the 'Buy/Sell Indicator' field on several messages.
buy_sell_indicator_t const SELL(u 'S')
void test_compute_book_replace_edge_cases()
Test compute book replace edge cases.
void test_compute_book_add_order_message_sell()
Test compute book based on book type.
jb::itch5::short_string_field< 4 > mpid_t
Define the type used to represent the 'MPID' field in many messages.
char_list_field< u 'Y', u 'N'> printable_t
Represent the 'Printable' field on a 'Order Executed with Price' message.
void test_compute_book_reduction_edge_cases()
Test compute book reduction edge cases.
Represent an 'Order Delete' message in the ITCH-5.0 protocol.
static constexpr int message_type
Represent an 'Order Executed with Price' message in the ITCH-5.0 protocol.
static constexpr int message_type
stock_directory_message create_stock_directory(char const *symbol)
Create a dummy jb::itch5::stock_directory_message for testing.
Represent an 'Add Order with MPID' message in the ITCH-5.0 protocol.
MOCK_METHOD5(exec, void(book_update update, half_quote best_bid, half_quote best_offer, int buy_count, int offer_count))
void test_compute_book_order_executed_message()
Test compute book order execute message.
std::pair< price4_t, int > half_quote
A simple representation for price + quantity.
jb::itch5::short_string_field< 8 > stock_t
Define the type used to represent the 'Stock' field in many messages.
static constexpr int message_type
Represent a ITCH-5.0 timestamp.
std::vector< char > create_message(int message_type, jb::itch5::timestamp ts, std::size_t total_size)
Generate test messages with a more-or-less valid header.
static constexpr int message_type
Represent an 'Trade (non-Cross)' message in the ITCH-5.0 protocol.
Initialize GMock to work with Boost.Test.
void test_compute_book_increase_coverage()
Test compute book increase coverage.
A flat struct to represent updates to an order book.
buy_sell_indicator_t const BUY(u 'B')
half_quote empty_offer()
The value used to represent an empty offer.
Represent an 'Order Replace' message in the ITCH-5.0 protocol.
BOOST_AUTO_TEST_CASE(compute_book_add_order_message)
void test_compute_book_stock_directory_message()
Test compute book stock directory message.
price_field< std::uint32_t, 10000 > price4_t
Convenience definition for Price(4) fields.
static constexpr int message_type
Maintain the ITCH-5.0 order book for a single security.
void test_compute_book_edge_cases()
Test compute book edge cases.
void test_compute_book_order_cancel_message()
Test compute book order cancel message.
Functions used in testing jb::itch5 entities.
Represent an 'Add Order' message in the ITCH-5.0 protocol.
The top-level namespace for the JayBeams library.
Represent an 'Order Cancel' message in the ITCH-5.0 protocol.