3 #include <boost/test/unit_test.hpp> 12 template <
typename book_type>
16 auto actual = tested.best_bid();
17 BOOST_CHECK_EQUAL(actual.first,
price4_t(0));
18 BOOST_CHECK_EQUAL(actual.second, 0);
19 actual = tested.worst_bid();
20 BOOST_CHECK_EQUAL(actual.first,
price4_t(0));
21 BOOST_CHECK_EQUAL(actual.second, 0);
22 actual = tested.best_offer();
23 BOOST_CHECK_EQUAL(actual.first,
price4_t(200000UL * 10000));
24 BOOST_CHECK_EQUAL(actual.second, 0);
25 actual = tested.worst_offer();
26 BOOST_CHECK_EQUAL(actual.first,
price4_t(200000UL * 10000));
27 BOOST_CHECK_EQUAL(actual.second, 0);
29 BOOST_CHECK_EQUAL(tested.get_book_depth(), 0);
35 template <
typename book_type>
42 auto r = tested.handle_add_order(BUY,
price4_t(100000), 100);
44 auto actual = tested.best_offer();
45 BOOST_CHECK_EQUAL(actual.first,
price4_t(200000UL * 10000));
46 BOOST_CHECK_EQUAL(actual.second, 0);
47 actual = tested.worst_offer();
48 BOOST_CHECK_EQUAL(actual.first,
price4_t(200000UL * 10000));
49 BOOST_CHECK_EQUAL(actual.second, 0);
51 actual = tested.best_bid();
52 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
53 BOOST_CHECK_EQUAL(actual.second, 100);
54 actual = tested.worst_bid();
55 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
56 BOOST_CHECK_EQUAL(actual.second, 100);
58 BOOST_CHECK_EQUAL(r,
true);
60 BOOST_CHECK_EQUAL(tested.get_book_depth(), 1);
63 r = tested.handle_add_order(BUY,
price4_t(99900), 300);
64 actual = tested.best_bid();
65 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
66 BOOST_CHECK_EQUAL(actual.second, 100);
67 actual = tested.worst_bid();
68 BOOST_CHECK_EQUAL(actual.first,
price4_t(99900));
69 BOOST_CHECK_EQUAL(actual.second, 300);
71 BOOST_CHECK_EQUAL(r,
false);
73 BOOST_CHECK_EQUAL(tested.get_book_depth(), 2);
76 r = tested.handle_add_order(BUY,
price4_t(100000), 400);
77 actual = tested.best_bid();
78 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
79 BOOST_CHECK_EQUAL(actual.second, 500);
81 BOOST_CHECK_EQUAL(r,
true);
83 BOOST_CHECK_EQUAL(tested.get_book_depth(), 2);
86 r = tested.handle_add_order(BUY,
price4_t(100100), 200);
87 actual = tested.best_bid();
88 BOOST_CHECK_EQUAL(actual.first,
price4_t(100100));
89 BOOST_CHECK_EQUAL(actual.second, 200);
91 BOOST_CHECK_EQUAL(r,
true);
93 BOOST_CHECK_EQUAL(tested.get_book_depth(), 3);
96 r = tested.handle_order_reduced(BUY,
price4_t(100000), 400);
97 actual = tested.best_bid();
98 BOOST_CHECK_EQUAL(actual.first,
price4_t(100100));
99 BOOST_CHECK_EQUAL(actual.second, 200);
101 BOOST_CHECK_EQUAL(r,
false);
103 BOOST_CHECK_EQUAL(tested.get_book_depth(), 3);
106 r = tested.handle_order_reduced(BUY,
price4_t(100000), 200);
107 actual = tested.best_bid();
108 BOOST_CHECK_EQUAL(actual.first,
price4_t(100100));
109 BOOST_CHECK_EQUAL(actual.second, 200);
111 BOOST_CHECK_EQUAL(r,
false);
113 BOOST_CHECK_EQUAL(tested.get_book_depth(), 2);
116 r = tested.handle_order_reduced(BUY,
price4_t(100100), 200);
117 actual = tested.best_bid();
118 BOOST_CHECK_EQUAL(actual.first,
price4_t(99900));
119 BOOST_CHECK_EQUAL(actual.second, 300);
121 BOOST_CHECK_EQUAL(r,
true);
123 BOOST_CHECK_EQUAL(tested.get_book_depth(), 1);
126 r = tested.handle_order_reduced(BUY,
price4_t(99900), 300);
127 actual = tested.best_bid();
128 BOOST_CHECK_EQUAL(actual.first,
price4_t(0));
129 BOOST_CHECK_EQUAL(actual.second, 0);
131 BOOST_CHECK_EQUAL(r,
true);
133 BOOST_CHECK_EQUAL(tested.get_book_depth(), 0);
139 template <
typename book_type>
146 auto r = tested.handle_add_order(SELL,
price4_t(100000), 100);
148 auto actual = tested.best_bid();
149 BOOST_CHECK_EQUAL(actual.first,
price4_t(0));
150 BOOST_CHECK_EQUAL(actual.second, 0);
151 actual = tested.worst_bid();
152 BOOST_CHECK_EQUAL(actual.first,
price4_t(0));
153 BOOST_CHECK_EQUAL(actual.second, 0);
155 actual = tested.best_offer();
156 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
157 BOOST_CHECK_EQUAL(actual.second, 100);
158 actual = tested.worst_offer();
159 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
160 BOOST_CHECK_EQUAL(actual.second, 100);
162 BOOST_CHECK_EQUAL(r,
true);
164 BOOST_CHECK_EQUAL(tested.get_book_depth(), 1);
167 r = tested.handle_add_order(SELL,
price4_t(100100), 300);
168 actual = tested.best_offer();
169 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
170 BOOST_CHECK_EQUAL(actual.second, 100);
172 actual = tested.worst_offer();
173 BOOST_CHECK_EQUAL(actual.first,
price4_t(100100));
174 BOOST_CHECK_EQUAL(actual.second, 300);
176 BOOST_CHECK_EQUAL(r,
false);
178 BOOST_CHECK_EQUAL(tested.get_book_depth(), 2);
181 r = tested.handle_add_order(SELL,
price4_t(100000), 400);
182 actual = tested.best_offer();
183 BOOST_CHECK_EQUAL(actual.first,
price4_t(100000));
184 BOOST_CHECK_EQUAL(actual.second, 500);
186 BOOST_CHECK_EQUAL(r,
true);
188 BOOST_CHECK_EQUAL(tested.get_book_depth(), 2);
191 r = tested.handle_add_order(SELL,
price4_t(99900), 200);
192 actual = tested.best_offer();
193 BOOST_CHECK_EQUAL(actual.first,
price4_t(99900));
194 BOOST_CHECK_EQUAL(actual.second, 200);
196 BOOST_CHECK_EQUAL(r,
true);
198 BOOST_CHECK_EQUAL(tested.get_book_depth(), 3);
201 r = tested.handle_order_reduced(SELL,
price4_t(100000), 400);
202 actual = tested.best_offer();
203 BOOST_CHECK_EQUAL(actual.first,
price4_t(99900));
204 BOOST_CHECK_EQUAL(actual.second, 200);
206 BOOST_CHECK_EQUAL(r,
false);
208 BOOST_CHECK_EQUAL(tested.get_book_depth(), 3);
211 r = tested.handle_order_reduced(SELL,
price4_t(100000), 200);
212 actual = tested.best_offer();
213 BOOST_CHECK_EQUAL(actual.first,
price4_t(99900));
214 BOOST_CHECK_EQUAL(actual.second, 200);
216 BOOST_CHECK_EQUAL(r,
false);
218 BOOST_CHECK_EQUAL(tested.get_book_depth(), 2);
221 r = tested.handle_order_reduced(SELL,
price4_t(99900), 200);
222 actual = tested.best_offer();
223 BOOST_CHECK_EQUAL(actual.first,
price4_t(100100));
224 BOOST_CHECK_EQUAL(actual.second, 300);
226 BOOST_CHECK_EQUAL(r,
true);
228 BOOST_CHECK_EQUAL(tested.get_book_depth(), 1);
231 r = tested.handle_order_reduced(SELL,
price4_t(100100), 300);
232 actual = tested.best_offer();
233 BOOST_CHECK_EQUAL(actual.first,
price4_t(200000UL * 10000));
234 BOOST_CHECK_EQUAL(actual.second, 0);
236 BOOST_CHECK_EQUAL(r,
true);
238 BOOST_CHECK_EQUAL(tested.get_book_depth(), 0);
244 template <
typename book_type>
252 (void)tested.handle_add_order(BUY,
price4_t(100000), 100);
253 (void)tested.handle_add_order(BUY,
price4_t(110000), 200);
256 auto actual = tested.best_bid();
257 BOOST_CHECK_EQUAL(actual.first,
price4_t(110000));
258 BOOST_CHECK_EQUAL(actual.second, 200);
262 tested.handle_order_reduced(BUY,
price4_t(100000), 100);
264 tested.handle_order_reduced(BUY,
price4_t(100000), 100), std::exception);
267 actual = tested.best_bid();
268 BOOST_CHECK_EQUAL(actual.first,
price4_t(110000));
269 BOOST_CHECK_EQUAL(actual.second, 200);
272 (void)tested.handle_add_order(SELL,
price4_t(120000), 100);
273 (void)tested.handle_add_order(SELL,
price4_t(110000), 200);
276 actual = tested.best_offer();
277 BOOST_CHECK_EQUAL(actual.first,
price4_t(110000));
278 BOOST_CHECK_EQUAL(actual.second, 200);
282 tested.handle_order_reduced(SELL,
price4_t(120000), 100);
284 tested.handle_order_reduced(SELL,
price4_t(120000), 100), std::exception);
287 actual = tested.best_offer();
288 BOOST_CHECK_EQUAL(actual.first,
price4_t(110000));
289 BOOST_CHECK_EQUAL(actual.second, 200);
305 map_book_type map_tested(map_cfg);
310 array_book_type array_tested(array_cfg);
323 map_book_type map_tested(map_cfg);
329 array_book_type array_tested(array_cfg);
333 array_book_type sh_array_tested(
347 map_book_type map_tested(map_cfg);
353 array_book_type array_tested(array_cfg);
357 array_book_type sh_array_tested(
370 map_book_type map_tested(map_cfg);
375 array_book_type array_tested(array_cfg);
Contains classes and functions to parse NASDAQ ITCH-5.0 messages, more information about ITCH-5...
void test_order_book_errors(book_type &tested)
Test order book error conditions.
void test_order_book_buy_order_handling(book_type &tested)
Test order book buy side order handling.
buy_sell_indicator_t const SELL(u 'S')
void test_order_book_trivial(book_type &tested)
Test order book trivial members.
Configure an array_based_order_book config object.
buy_sell_indicator_t const BUY(u 'B')
Configure an map_based_order_book config object.
price_field< std::uint32_t, 10000 > price4_t
Convenience definition for Price(4) fields.
BOOST_AUTO_TEST_CASE(order_book_trivial)
void test_order_book_sell_order_handling(book_type &tested)
Test order book sell side order handling.
Maintain the ITCH-5.0 order book for a single security.
The top-level namespace for the JayBeams library.