21 #define BOOST_TEST_MODULE isimud_tests
22 #include <boost/test/included/unit_test.hpp>
24 #include <boost/mpl/list.hpp>
26 #include "../exchanges/MIT/BIT/bit.hpp"
27 #include "../exchanges/MIT/BIT/bit_sim.hpp"
28 #include "../exchanges/MIT/JSE/jse.hpp"
29 #include "../exchanges/MIT/JSE/jse_sim.hpp"
30 #include "../exchanges/MIT/LSE/lse.hpp"
31 #include "../exchanges/MIT/LSE/lse_sim.hpp"
32 #include "../exchanges/MIT/OSLO/oslo.hpp"
33 #include "../exchanges/MIT/OSLO/oslo_sim.hpp"
34 #include "../exchanges/MIT/TRQ/trq.hpp"
35 #include "../exchanges/MIT/TRQ/trq_sim.hpp"
37 using namespace libjmmcg;
38 using namespace libisimud;
49 typedef boost::mpl::list<
50 std::pair<exchanges::MIT::BIT::connection_t, exchanges::MIT::BIT::simulator_t>,
51 std::pair<exchanges::MIT::JSE::connection_t, exchanges::MIT::JSE::simulator_t>,
52 std::pair<exchanges::MIT::LSE::connection_t, exchanges::MIT::LSE::simulator_t>,
53 std::pair<exchanges::MIT::OSLO::connection_t, exchanges::MIT::OSLO::simulator_t>,
54 std::pair<exchanges::MIT::TRQ::connection_t, exchanges::MIT::TRQ::simulator_t>
57 template<
class exchg_t>
59 using connection_t=
typename exchg_t::first_type;
60 using simulator_t=
typename exchg_t::second_type;
61 using conn_pol_t=
typename connection_t::conn_pol_t;
80 template<
class exchg_t>
83 using simulator_t=
typename base_t::simulator_t;
86 no_latency_timestamps
ts{0
};
90 simulator_t::socket_t::socket_priority::high,
91 api_thread_traits::processor_mask_type(exchanges::common::thread_traits::exchange_simulator_thread.core),
92 exchanges::common::thread_traits::exchange_simulator_thread.priority,
99 template<
class exchg_t>
102 using connection_t=
typename base_t::connection_t;
103 using link_t=
typename exchg_t::first_type;
107 link_t::skt_mgr_t::socket_t::socket_priority::low,
112 template<
class exchg_t>
115 using connection_t=
typename base_t::connection_t;
116 using simulator_t=
typename base_t::simulator_t;
119 const typename connection_t::msg_details_t::LogonRequest msg(
120 typename connection_t::msg_details_t::LogonRequest::logon_args_t::UserName_t(
this->conn_pol.logon_args.username),
121 typename connection_t::msg_details_t::LogonRequest::logon_args_t::Password_t(
this->conn_pol.logon_args.password),
122 typename connection_t::msg_details_t::LogonRequest::logon_args_t::Password_t(
this->conn_pol.logon_args.new_password)
124 BOOST_REQUIRE_NO_THROW(
this->link.send(msg));
125 typename connection_t::msg_details_t::LogonReply reply;
126 BOOST_REQUIRE_NO_THROW(
this->link.receive(reply));
127 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
128 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::LogonReply));
129 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::LogonReply));
130 BOOST_CHECK_EQUAL(reply.rejectCode(), connection_t::msg_details_t::LogonReply::logon_success);
133 const typename connection_t::msg_details_t::LogoutRequest msg(exchanges::MIT::common::Reason_t{
"fubar"});
134 BOOST_REQUIRE_NO_THROW(
this->link.send(msg));
135 typename connection_t::msg_details_t::Logout reply;
136 BOOST_REQUIRE_NO_THROW(
this->link.receive(reply));
137 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
138 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::Logout));
139 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::LogoutRequest));
140 BOOST_CHECK_EQUAL(reply.reason(),
this->conn_pol.logoff_args.reason);
144 BOOST_AUTO_TEST_SUITE(exchange_gateways)
146 BOOST_AUTO_TEST_SUITE(links)
154 BOOST_AUTO_TEST_CASE_TEMPLATE(both_gateways_unavailable, exchg_t, exchg_t_types) {
158 auto const &begin=
std::chrono::system_clock::now();
160 typename exchg_t::first_type link(
162 exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::low,
167 auto const &end=
std::chrono::system_clock::now();
168 BOOST_CHECK_GE(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), (fixture_t::conn_pol_t::max_attempts*fixture_t::conn_pol_t::min_timeout*2).count());
177 BOOST_AUTO_TEST_CASE_TEMPLATE(primary_gateway_available, exchg_t, exchg_t_types) {
181 auto const &begin=
std::chrono::system_clock::now();
182 BOOST_REQUIRE_NO_THROW(
183 typename exchg_t::first_type link(
185 exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::low,
186 exchanges::common::thread_traits::client_to_exchange_thread.core
189 auto const &end=
std::chrono::system_clock::now();
190 BOOST_CHECK_LT(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), fixture_t::conn_pol_t::min_timeout.count());
199 BOOST_AUTO_TEST_CASE_TEMPLATE(re_connnect, exchg_t, exchg_t_types) {
203 BOOST_REQUIRE_NO_THROW(
204 typename exchg_t::first_type link(
206 exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::low,
207 exchanges::common::thread_traits::client_to_exchange_thread.core
210 auto const &begin=
std::chrono::system_clock::now();
211 BOOST_REQUIRE_NO_THROW(
212 typename exchg_t::first_type link(
214 exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::low,
215 exchanges::common::thread_traits::client_to_exchange_thread.core
218 auto const &end=
std::chrono::system_clock::now();
219 BOOST_CHECK_LT(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), fixture_t::conn_pol_t::min_timeout.count());
228 BOOST_AUTO_TEST_CASE_TEMPLATE(secondary_gateway_available, exchg_t, exchg_t_types) {
232 typename fixture_t::simulator_t::proc_rules_t proc_rules;
233 no_latency_timestamps ts
{0
};
234 typename fixture_t::simulator_t svr(
237 fixture_t::simulator_t::socket_t::socket_priority::high,
238 api_thread_traits::processor_mask_type(exchanges::common::thread_traits::exchange_simulator_thread.core),
239 exchanges::common::thread_traits::exchange_simulator_thread.priority,
245 auto const &begin=
std::chrono::system_clock::now();
246 BOOST_REQUIRE_NO_THROW(
247 typename exchg_t::first_type link(
249 exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::low,
250 exchanges::common::thread_traits::client_to_exchange_thread.core
253 auto const &end=
std::chrono::system_clock::now();
254 BOOST_CHECK_GE(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), (fixture_t::conn_pol_t::max_attempts*fixture_t::conn_pol_t::min_timeout).count());
257 BOOST_AUTO_TEST_SUITE_END()
259 BOOST_AUTO_TEST_SUITE(admin)
267 BOOST_AUTO_TEST_CASE_TEMPLATE(logon, exchg_t, exchg_t_types) {
269 using connection_t=
typename fixture_t::connection_t;
272 const typename connection_t::msg_details_t::LogonRequest msg(
273 typename connection_t::msg_details_t::LogonRequest::logon_args_t::UserName_t(f.conn_pol.logon_args.username),
274 typename connection_t::msg_details_t::LogonRequest::logon_args_t::Password_t(f.conn_pol.logon_args.password),
275 typename connection_t::msg_details_t::LogonRequest::logon_args_t::Password_t(f.conn_pol.logon_args.new_password)
277 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
278 typename connection_t::msg_details_t::LogonReply reply;
279 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
280 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
281 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::LogonReply));
282 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::LogonReply));
283 BOOST_CHECK_EQUAL(reply.rejectCode(), connection_t::msg_details_t::LogonReply::logon_success);
292 BOOST_AUTO_TEST_CASE_TEMPLATE(client_heartbeat, exchg_t, exchg_t_types) {
294 using connection_t=
typename fixture_t::connection_t;
297 const typename connection_t::msg_details_t::ClientHeartbeat msg;
298 BOOST_CHECK_NO_THROW(f.link.send(msg));
307 BOOST_AUTO_TEST_CASE_TEMPLATE(server_heartbeat, exchg_t, exchg_t_types) {
309 using connection_t=
typename fixture_t::connection_t;
312 const auto start=
std::chrono::high_resolution_clock::now();
313 typename exchg_t::first_type link(
315 exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::low,
318 typename connection_t::msg_details_t::ClientHeartbeat msg;
319 BOOST_REQUIRE_NO_THROW(link.receive(msg));
320 const auto got_hb=
std::chrono::high_resolution_clock::now();
321 BOOST_CHECK_EQUAL(msg.start_of_message, 2);
322 BOOST_CHECK_EQUAL(msg.length(),
sizeof(
typename connection_t::msg_details_t::ClientHeartbeat));
323 BOOST_CHECK_EQUAL(msg.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::Heartbeat));
325 static_cast<
float>(std::chrono::duration_cast<std::chrono::milliseconds>(got_hb - start).count()),
327 std::chrono::duration_cast<std::chrono::milliseconds>(
328 fixture_t::simulator_t::svr_mgr_t::heartbeats_t::heartbeat_interval
341 BOOST_AUTO_TEST_CASE_TEMPLATE(logout, exchg_t, exchg_t_types) {
343 using connection_t=
typename fixture_t::connection_t;
346 const typename connection_t::msg_details_t::LogoutRequest msg(exchanges::MIT::common::Reason_t{
"fubar"});
347 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
348 typename connection_t::msg_details_t::Logout reply;
349 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
350 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
351 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::Logout));
352 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::LogoutRequest));
353 BOOST_CHECK_EQUAL(reply.reason(), f.conn_pol.logoff_args.reason);
362 BOOST_AUTO_TEST_CASE_TEMPLATE(logon_logout, exchg_t, exchg_t_types) {
364 using connection_t=
typename fixture_t::connection_t;
367 const typename connection_t::msg_details_t::LogonRequest logon_msg(
368 typename connection_t::msg_details_t::LogonRequest::logon_args_t::UserName_t(f.conn_pol.logon_args.username),
369 typename connection_t::msg_details_t::LogonRequest::logon_args_t::Password_t(f.conn_pol.logon_args.password),
370 typename connection_t::msg_details_t::LogonRequest::logon_args_t::Password_t(f.conn_pol.logon_args.new_password)
372 BOOST_REQUIRE_NO_THROW(f.link.send(logon_msg));
373 typename connection_t::msg_details_t::LogonReply logon_reply;
374 BOOST_REQUIRE_NO_THROW(f.link.receive(logon_reply));
375 BOOST_CHECK_EQUAL(logon_reply.start_of_message, 2);
376 BOOST_CHECK_EQUAL(logon_reply.length(),
sizeof(
typename connection_t::msg_details_t::LogonReply));
377 BOOST_CHECK_EQUAL(logon_reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::LogonReply));
378 BOOST_CHECK_EQUAL(logon_reply.rejectCode(), connection_t::msg_details_t::LogonReply::logon_success);
379 const typename connection_t::msg_details_t::LogoutRequest logout_msg(exchanges::MIT::common::Reason_t{
"fubar"});
380 BOOST_REQUIRE_NO_THROW(f.link.send(logout_msg));
381 typename connection_t::msg_details_t::Logout logout_reply;
382 BOOST_REQUIRE_NO_THROW(f.link.receive(logout_reply));
383 BOOST_CHECK_EQUAL(logout_reply.start_of_message, 2);
384 BOOST_CHECK_EQUAL(logout_reply.length(),
sizeof(
typename connection_t::msg_details_t::Logout));
385 BOOST_CHECK_EQUAL(logout_reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::AdminMsgType::LogoutRequest));
386 BOOST_CHECK_EQUAL(logout_reply.reason(), f.conn_pol.logoff_args.reason);
449 BOOST_AUTO_TEST_SUITE_END()
451 BOOST_AUTO_TEST_SUITE(client_initiated)
459 BOOST_AUTO_TEST_CASE_TEMPLATE(reject, exchg_t, exchg_t_types) {
461 using connection_t=
typename fixture_t::connection_t;
464 const typename connection_t::msg_details_t::NewOrder_t msg(
467 exchg_t::first_type::msg_details_t::OrderType::Market,
468 exchanges::MIT::common::TIF::Day,
469 exchg_t::first_type::msg_details_t::Side::Buy,
470 exchg_t::second_type::proc_rules_t::invalidInstrumentID,
471 exchg_t::second_type::proc_rules_t::quantity_limit-1,
472 exchg_t::second_type::proc_rules_t::scaled_price
474 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
475 typename connection_t::msg_details_t::BusinessReject reply;
476 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
477 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
478 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::BusinessReject));
479 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::BusinessMessageReject));
480 BOOST_CHECK_EQUAL(reply.clientOrderID().begin(), msg.clientOrderID().begin());
481 BOOST_CHECK_EQUAL(reply.rejectCode(), connection_t::msg_details_t::BusinessReject::unknown_instrument);
490 BOOST_AUTO_TEST_CASE_TEMPLATE(cancel_reject, exchg_t, exchg_t_types) {
492 using connection_t=
typename fixture_t::connection_t;
495 const typename connection_t::msg_details_t::OrderCancelRequest msg(
498 exchg_t::second_type::proc_rules_t::invalidInstrumentID,
499 exchg_t::first_type::msg_details_t::Side::Buy
501 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
502 typename connection_t::msg_details_t::OrderCancelReject reply;
503 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
504 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
505 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::OrderCancelReject));
506 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::OrderCancelReject));
507 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.originalClientOrderID());
516 BOOST_AUTO_TEST_CASE_TEMPLATE(cancel_accept, exchg_t, exchg_t_types) {
518 using connection_t=
typename fixture_t::connection_t;
521 const typename connection_t::msg_details_t::NewOrder_t msg(
524 exchg_t::first_type::msg_details_t::OrderType::Limit,
525 exchanges::MIT::common::TIF::Day,
526 exchg_t::first_type::msg_details_t::Side::Buy,
527 exchg_t::second_type::proc_rules_t::instrumentID,
528 exchg_t::second_type::proc_rules_t::quantity_limit-1,
529 exchg_t::second_type::proc_rules_t::scaled_price+1
531 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
532 const typename connection_t::msg_details_t::OrderCancelRequest msg1(
535 exchg_t::second_type::proc_rules_t::invalidInstrumentID,
536 exchg_t::first_type::msg_details_t::Side::Buy
538 BOOST_REQUIRE_NO_THROW(f.link.send(msg1));
539 typename connection_t::msg_details_t::ExecutionReport reply;
540 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
541 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
542 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
543 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
544 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.clientOrderID());
545 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::New);
546 BOOST_CHECK_EQUAL(reply.executedPrice(), 0);
547 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
548 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
549 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::New);
550 BOOST_CHECK_EQUAL(reply.executedQty(), 0);
551 BOOST_CHECK_EQUAL(reply.leavesQty(), msg.orderQty());
552 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
553 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
554 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
555 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
556 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.clientOrderID());
557 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::Cancelled);
558 BOOST_CHECK_EQUAL(reply.executedPrice(), msg.limitPrice());
559 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
560 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
561 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Cancelled);
562 BOOST_CHECK_EQUAL(reply.executedQty(), 0);
563 BOOST_CHECK_EQUAL(reply.leavesQty(), msg.orderQty());
572 BOOST_AUTO_TEST_CASE_TEMPLATE(modify_reject, exchg_t, exchg_t_types) {
574 using connection_t=
typename fixture_t::connection_t;
577 const typename connection_t::msg_details_t::OrderCancelReplaceRequest msg(
580 exchg_t::second_type::proc_rules_t::instrumentID,
581 exchg_t::second_type::proc_rules_t::quantity_limit,
582 exchg_t::second_type::proc_rules_t::scaled_price,
583 exchanges::MIT::common::TIF::Day,
584 exchg_t::first_type::msg_details_t::Side::Sell
586 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
587 typename connection_t::msg_details_t::OrderCancelReject reply;
588 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
589 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
590 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::OrderCancelReject));
591 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::OrderCancelReject));
592 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.originalClientOrderID());
601 BOOST_AUTO_TEST_CASE_TEMPLATE(modify_accept, exchg_t, exchg_t_types) {
603 using connection_t=
typename fixture_t::connection_t;
606 const typename connection_t::msg_details_t::NewOrder_t msg(
609 exchg_t::first_type::msg_details_t::OrderType::Limit,
610 exchanges::MIT::common::TIF::Day,
611 exchg_t::first_type::msg_details_t::Side::Buy,
612 exchg_t::second_type::proc_rules_t::instrumentID,
613 exchg_t::second_type::proc_rules_t::quantity_limit-1,
614 exchg_t::second_type::proc_rules_t::scaled_price+1
616 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
617 const typename connection_t::msg_details_t::OrderCancelReplaceRequest msg1(
621 exchg_t::second_type::proc_rules_t::quantity_limit,
624 exchg_t::first_type::msg_details_t::Side::Sell
626 BOOST_REQUIRE_NO_THROW(f.link.send(msg1));
627 typename connection_t::msg_details_t::ExecutionReport reply;
628 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
629 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
630 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
631 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
632 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.clientOrderID());
633 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::New);
634 BOOST_CHECK_EQUAL(reply.executedPrice(), 0);
635 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
636 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
637 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::New);
638 BOOST_CHECK_EQUAL(reply.executedQty(), 0);
639 BOOST_CHECK_EQUAL(reply.leavesQty(), msg.orderQty());
640 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
641 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
642 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
643 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
644 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.clientOrderID());
645 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::Replaced);
646 BOOST_CHECK_EQUAL(reply.executedPrice(), msg1.limitPrice());
647 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
648 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Sell);
649 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Cancelled);
650 BOOST_CHECK_EQUAL(reply.executedQty(), 0);
651 BOOST_CHECK_EQUAL(reply.leavesQty(), msg1.orderQty());
654 BOOST_AUTO_TEST_SUITE(new_order)
656 BOOST_AUTO_TEST_SUITE(buy)
658 BOOST_AUTO_TEST_SUITE(day)
660 BOOST_AUTO_TEST_SUITE(market)
668 BOOST_AUTO_TEST_CASE_TEMPLATE(new_order, exchg_t, exchg_t_types) {
670 using connection_t=
typename fixture_t::connection_t;
673 const typename connection_t::msg_details_t::NewOrder_t msg(
676 exchg_t::first_type::msg_details_t::OrderType::Market,
677 exchanges::MIT::common::TIF::Day,
678 exchg_t::first_type::msg_details_t::Side::Buy,
679 exchg_t::second_type::proc_rules_t::instrumentID,
680 exchg_t::second_type::proc_rules_t::quantity_limit-1,
681 exchg_t::second_type::proc_rules_t::scaled_price
683 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
684 typename connection_t::msg_details_t::ExecutionReport reply;
685 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
686 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
687 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
688 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
689 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.clientOrderID());
690 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::New);
691 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
692 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
693 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Filled);
694 BOOST_CHECK_EQUAL(reply.executedQty(), msg.orderQty());
695 BOOST_CHECK_EQUAL(reply.leavesQty(), 0);
696 BOOST_CHECK_EQUAL(reply.executedPrice(), msg.limitPrice());
705 BOOST_AUTO_TEST_CASE_TEMPLATE(partial_fill, exchg_t, exchg_t_types) {
707 using connection_t=
typename fixture_t::connection_t;
710 const typename connection_t::msg_details_t::NewOrder_t msg(
713 exchg_t::first_type::msg_details_t::OrderType::Market,
714 exchanges::MIT::common::TIF::Day,
715 exchg_t::first_type::msg_details_t::Side::Buy,
716 exchg_t::second_type::proc_rules_t::instrumentID,
717 exchg_t::second_type::proc_rules_t::quantity_limit+1,
718 exchg_t::second_type::proc_rules_t::scaled_price
720 BOOST_REQUIRE_NO_THROW(f.link.send(msg));
721 typename connection_t::msg_details_t::ExecutionReport reply;
722 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
723 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
724 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
725 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
726 BOOST_CHECK_EQUAL(reply.clientOrderID(), msg.clientOrderID());
727 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::New);
728 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
729 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
730 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Partiallyfilled);
731 BOOST_CHECK_EQUAL(reply.executedQty(), exchg_t::second_type::proc_rules_t::quantity_limit);
732 BOOST_CHECK_EQUAL(reply.leavesQty(), msg.orderQty()-exchg_t::second_type::proc_rules_t::quantity_limit);
733 BOOST_CHECK_EQUAL(reply.executedPrice(), msg.limitPrice());
742 BOOST_AUTO_TEST_CASE_TEMPLATE(partial_fill_cancel, exchg_t, exchg_t_types) {
744 using connection_t=
typename fixture_t::connection_t;
747 const typename connection_t::msg_details_t::NewOrder_t new_order(
750 exchg_t::first_type::msg_details_t::OrderType::Market,
751 exchanges::MIT::common::TIF::Day,
752 exchg_t::first_type::msg_details_t::Side::Buy,
753 exchg_t::second_type::proc_rules_t::instrumentID,
754 exchg_t::second_type::proc_rules_t::quantity_limit+1,
755 exchg_t::second_type::proc_rules_t::scaled_price
757 BOOST_REQUIRE_NO_THROW(f.link.send(new_order));
758 typename connection_t::msg_details_t::ExecutionReport partial_fill;
759 BOOST_REQUIRE_NO_THROW(f.link.receive(partial_fill));
760 const typename connection_t::msg_details_t::OrderCancelRequest cancel(
763 exchg_t::second_type::proc_rules_t::instrumentID,
764 exchg_t::first_type::msg_details_t::Side::Buy
766 BOOST_REQUIRE_NO_THROW(f.link.send(cancel));
767 typename connection_t::msg_details_t::ExecutionReport reply;
768 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
769 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
770 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
771 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
772 BOOST_CHECK_EQUAL(reply.clientOrderID(), new_order.clientOrderID());
773 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::Cancelled);
774 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
775 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
776 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Cancelled);
777 BOOST_CHECK_EQUAL(reply.executedQty(), 0);
778 BOOST_CHECK_EQUAL(reply.leavesQty(), new_order.orderQty()-exchg_t::second_type::proc_rules_t::quantity_limit);
779 BOOST_CHECK_EQUAL(reply.executedPrice(), new_order.limitPrice());
788 BOOST_AUTO_TEST_CASE_TEMPLATE(partial_fill_replace, exchg_t, exchg_t_types) {
790 using connection_t=
typename fixture_t::connection_t;
793 const typename connection_t::msg_details_t::NewOrder_t new_order(
796 exchg_t::first_type::msg_details_t::OrderType::Market,
797 exchanges::MIT::common::TIF::Day,
798 exchg_t::first_type::msg_details_t::Side::Buy,
799 exchg_t::second_type::proc_rules_t::instrumentID,
800 exchg_t::second_type::proc_rules_t::quantity_limit+1,
801 exchg_t::second_type::proc_rules_t::scaled_price
803 BOOST_REQUIRE_NO_THROW(f.link.send(new_order));
804 typename connection_t::msg_details_t::ExecutionReport partial_fill;
805 BOOST_REQUIRE_NO_THROW(f.link.receive(partial_fill));
806 const typename connection_t::msg_details_t::OrderCancelReplaceRequest replace(
809 exchg_t::second_type::proc_rules_t::instrumentID,
810 partial_fill.leavesQty()+1,
811 exchg_t::second_type::proc_rules_t::scaled_price*2,
812 exchanges::MIT::common::TIF::Day,
813 exchg_t::first_type::msg_details_t::Side::Sell
815 BOOST_REQUIRE_NO_THROW(f.link.send(replace));
816 typename connection_t::msg_details_t::ExecutionReport reply;
817 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
818 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
819 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
820 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
821 BOOST_CHECK_EQUAL(reply.clientOrderID(), new_order.clientOrderID());
822 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::Replaced);
823 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
824 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Sell);
825 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Cancelled);
826 BOOST_CHECK_EQUAL(reply.executedQty(), 0);
827 BOOST_CHECK_EQUAL(reply.leavesQty(), partial_fill.leavesQty()+1);
828 BOOST_CHECK_EQUAL(reply.executedPrice(), new_order.limitPrice()*2);
831 BOOST_AUTO_TEST_SUITE_END()
833 BOOST_AUTO_TEST_SUITE(limit)
841 BOOST_AUTO_TEST_CASE_TEMPLATE(new_order, exchg_t, exchg_t_types) {
843 using connection_t=
typename fixture_t::connection_t;
846 const typename connection_t::msg_details_t::NewOrder_t new_order(
849 exchg_t::first_type::msg_details_t::OrderType::Limit,
850 exchanges::MIT::common::TIF::Day,
851 exchg_t::first_type::msg_details_t::Side::Buy,
852 exchg_t::second_type::proc_rules_t::instrumentID,
853 exchg_t::second_type::proc_rules_t::quantity_limit-1,
854 exchg_t::second_type::proc_rules_t::scaled_price-1
856 BOOST_REQUIRE_NO_THROW(f.link.send(new_order));
857 typename connection_t::msg_details_t::ExecutionReport reply;
858 BOOST_REQUIRE_NO_THROW(f.link.receive(reply));
859 BOOST_CHECK_EQUAL(reply.start_of_message, 2);
860 BOOST_CHECK_EQUAL(reply.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
861 BOOST_CHECK_EQUAL(reply.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
862 BOOST_CHECK_EQUAL(reply.clientOrderID(), new_order.clientOrderID());
863 BOOST_CHECK_EQUAL(reply.execType(), exchanges::MIT::common::ExecType::New);
864 BOOST_CHECK_EQUAL(reply.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
865 BOOST_CHECK_EQUAL(reply.side(), exchg_t::first_type::msg_details_t::Side::Buy);
866 BOOST_CHECK_EQUAL(reply.orderStatus(), exchanges::MIT::common::OrderStatus::Filled);
867 BOOST_CHECK_EQUAL(reply.executedQty(), new_order.orderQty());
868 BOOST_CHECK_EQUAL(reply.leavesQty(), 0);
869 BOOST_CHECK_EQUAL(reply.executedPrice(), new_order.limitPrice());
878 BOOST_AUTO_TEST_CASE_TEMPLATE(open_cancelled, exchg_t, exchg_t_types) {
880 using connection_t=
typename fixture_t::connection_t;
883 const typename connection_t::msg_details_t::NewOrder_t new_order(
886 exchg_t::first_type::msg_details_t::OrderType::Limit,
887 exchanges::MIT::common::TIF::Day,
888 exchg_t::first_type::msg_details_t::Side::Buy,
889 exchg_t::second_type::proc_rules_t::instrumentID,
890 exchg_t::second_type::proc_rules_t::quantity_limit-1,
891 fixture_t::simulator_t::proc_rules_t::scaled_price+1
893 BOOST_REQUIRE_NO_THROW(f.link.send(new_order));
894 const typename connection_t::msg_details_t::OrderCancelRequest cancel(
897 exchg_t::second_type::proc_rules_t::instrumentID,
898 exchg_t::first_type::msg_details_t::Side::Buy
900 BOOST_REQUIRE_NO_THROW(f.link.send(cancel));
901 typename connection_t::msg_details_t::ExecutionReport cancelled;
902 BOOST_REQUIRE_NO_THROW(f.link.receive(cancelled));
903 BOOST_CHECK_EQUAL(cancelled.start_of_message, 2);
904 BOOST_CHECK_EQUAL(cancelled.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
905 BOOST_CHECK_EQUAL(cancelled.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
906 BOOST_CHECK_EQUAL(cancelled.clientOrderID(), new_order.clientOrderID());
907 BOOST_CHECK_EQUAL(cancelled.execType(), exchanges::MIT::common::ExecType::New);
908 BOOST_CHECK_EQUAL(cancelled.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
909 BOOST_CHECK_EQUAL(cancelled.side(), exchg_t::first_type::msg_details_t::Side::Buy);
910 BOOST_CHECK_EQUAL(cancelled.orderStatus(), exchanges::MIT::common::OrderStatus::New);
911 BOOST_CHECK_EQUAL(cancelled.executedQty(), 0);
912 BOOST_CHECK_EQUAL(cancelled.leavesQty(), new_order.orderQty());
913 BOOST_CHECK_EQUAL(cancelled.executedPrice(), 0);
914 BOOST_REQUIRE_NO_THROW(f.link.receive(cancelled));
915 BOOST_CHECK_EQUAL(cancelled.start_of_message, 2);
916 BOOST_CHECK_EQUAL(cancelled.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
917 BOOST_CHECK_EQUAL(cancelled.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
918 BOOST_CHECK_EQUAL(cancelled.clientOrderID(), new_order.clientOrderID());
919 BOOST_CHECK_EQUAL(cancelled.execType(), exchanges::MIT::common::ExecType::Cancelled);
920 BOOST_CHECK_EQUAL(cancelled.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
921 BOOST_CHECK_EQUAL(cancelled.side(), exchg_t::first_type::msg_details_t::Side::Buy);
922 BOOST_CHECK_EQUAL(cancelled.orderStatus(), exchanges::MIT::common::OrderStatus::Cancelled);
923 BOOST_CHECK_EQUAL(cancelled.executedQty(), 0);
924 BOOST_CHECK_EQUAL(cancelled.leavesQty(), new_order.orderQty());
925 BOOST_CHECK_EQUAL(cancelled.executedPrice(), new_order.limitPrice());
934 BOOST_AUTO_TEST_CASE_TEMPLATE(open_modified, exchg_t, exchg_t_types) {
936 using connection_t=
typename fixture_t::connection_t;
939 const typename connection_t::msg_details_t::NewOrder_t new_order(
942 exchg_t::first_type::msg_details_t::OrderType::Limit,
943 exchanges::MIT::common::TIF::Day,
944 exchg_t::first_type::msg_details_t::Side::Buy,
945 exchg_t::second_type::proc_rules_t::instrumentID,
946 exchg_t::second_type::proc_rules_t::quantity_limit-1,
947 fixture_t::simulator_t::proc_rules_t::scaled_price+1
949 BOOST_REQUIRE_NO_THROW(f.link.send(new_order));
950 const typename connection_t::msg_details_t::OrderCancelReplaceRequest replace(
953 new_order.instrumentID(),
954 exchg_t::second_type::proc_rules_t::quantity_limit,
955 new_order.limitPrice()+2,
957 exchg_t::first_type::msg_details_t::Side::Sell
959 BOOST_REQUIRE_NO_THROW(f.link.send(replace));
960 typename connection_t::msg_details_t::ExecutionReport cancelled;
961 BOOST_REQUIRE_NO_THROW(f.link.receive(cancelled));
962 BOOST_CHECK_EQUAL(cancelled.start_of_message, 2);
963 BOOST_CHECK_EQUAL(cancelled.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
964 BOOST_CHECK_EQUAL(cancelled.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
965 BOOST_CHECK_EQUAL(cancelled.clientOrderID(), new_order.clientOrderID());
966 BOOST_CHECK_EQUAL(cancelled.execType(), exchanges::MIT::common::ExecType::New);
967 BOOST_CHECK_EQUAL(cancelled.executedPrice(), 0);
968 BOOST_CHECK_EQUAL(cancelled.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
969 BOOST_CHECK_EQUAL(cancelled.side(), exchg_t::first_type::msg_details_t::Side::Buy);
970 BOOST_CHECK_EQUAL(cancelled.orderStatus(), exchanges::MIT::common::OrderStatus::New);
971 BOOST_CHECK_EQUAL(cancelled.executedQty(), 0);
972 BOOST_CHECK_EQUAL(cancelled.leavesQty(), new_order.orderQty());
973 BOOST_REQUIRE_NO_THROW(f.link.receive(cancelled));
974 BOOST_CHECK_EQUAL(cancelled.start_of_message, 2);
975 BOOST_CHECK_EQUAL(cancelled.length(),
sizeof(
typename connection_t::msg_details_t::ExecutionReport));
976 BOOST_CHECK_EQUAL(cancelled.type(),
static_cast<exchanges::MIT::common::MsgType_t>(exchanges::MIT::common::ServerMsgType::ExecutionReport));
977 BOOST_CHECK_EQUAL(cancelled.clientOrderID(), new_order.clientOrderID());
978 BOOST_CHECK_EQUAL(cancelled.execType(), exchanges::MIT::common::ExecType::Replaced);
979 BOOST_CHECK_EQUAL(cancelled.executedPrice(), replace.limitPrice());
980 BOOST_CHECK_EQUAL(cancelled.instrumentID(), exchg_t::second_type::proc_rules_t::instrumentID);
981 BOOST_CHECK_EQUAL(cancelled.side(), exchg_t::first_type::msg_details_t::Side::Sell);
982 BOOST_CHECK_EQUAL(cancelled.orderStatus(), exchanges::MIT::common::OrderStatus::Cancelled);
983 BOOST_CHECK_EQUAL(cancelled.executedQty(), 0);
984 BOOST_CHECK_EQUAL(cancelled.leavesQty(), replace.orderQty());
987 BOOST_AUTO_TEST_SUITE_END()
989 BOOST_AUTO_TEST_SUITE_END()
991 BOOST_AUTO_TEST_SUITE_END()
993 BOOST_AUTO_TEST_SUITE_END()
995 BOOST_AUTO_TEST_SUITE_END()
997 BOOST_AUTO_TEST_SUITE_END()