libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
batsboe_us_to_fix.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2015 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "stdafx.h"
20 
21 #define BOOST_TEST_MODULE isimud_tests
22 #include <boost/test/included/unit_test.hpp>
23 
24 #include <boost/mpl/list.hpp>
25 
26 #include "../exchanges/conversions/batsboe_us_to_fix_conversions.hpp"
27 
28 using namespace libjmmcg;
29 using namespace libisimud;
30 
31 const int32_t seqNum=1;
32 const exchanges::BATSBOE::common::ClientOrderID_t clientOrderId1{"abcdefghijklm0test1"};
33 const exchanges::BATSBOE::common::Price_t price=42*exchanges::BATSBOE::common::implied_decimal_places;
34 const exchanges::BATSBOE::common::SecurityID_t instID{"GB00BH4HKS39"};
35 const exchanges::BATSBOE::common::Side s=exchanges::BATSBOE::common::Side::Buy;
36 
37 typedef boost::mpl::list<
39 // TODO exchanges::BATSBOE::US::v2::MsgTypes
41 
42 BOOST_AUTO_TEST_SUITE(exchange_gateways)
43 
44 BOOST_AUTO_TEST_CASE_TEMPLATE(OrderExecution, msg, msg_types) {
45  typename msg::OrderExecution exchg_msg(seqNum, clientOrderId1, price, instID, s);
46  exchg_msg.executedQty(0);
47  exchg_msg.leavesQty(0);
48  exchanges::FIX::v5_0sp2::MsgTypes::ExecutionReport fix_msg(exchg_msg);
49  BOOST_CHECK(fix_msg.is_valid());
50  auto const client_order_id=fix_msg.find<exchanges::FIX::common::FieldsFast::ClOrdID>();
51  BOOST_CHECK_EQUAL(std::string(client_order_id.first, client_order_id.second), clientOrderId1.begin());
52  auto const fix_price=fix_msg.find<exchanges::FIX::common::FieldsFast::Price>();
53  BOOST_CHECK_EQUAL(static_cast<exchanges::BATSBOE::common::Price_t>(fromstring<double>(fix_price.first, fix_price.second-fix_price.first)), price/exchanges::BATSBOE::common::implied_decimal_places);
54  auto const sec_id_type=fix_msg.find<exchanges::FIX::common::FieldsFast::SecurityIDSource>();
55  BOOST_CHECK_EQUAL(std::string(sec_id_type.first, sec_id_type.second), "4");
56  auto const symbol=fix_msg.find<exchanges::FIX::common::FieldsFast::SecurityID>();
57  BOOST_CHECK_EQUAL(std::string(symbol.first), instID.begin());
58  auto const orderQty=fix_msg.find<exchanges::FIX::common::FieldsFast::OrderQty>();
59  BOOST_CHECK_EQUAL(std::string(orderQty.first, orderQty.second), "0");
60  auto const leavesQty=fix_msg.find<exchanges::FIX::common::FieldsFast::LeavesQty>();
61  BOOST_CHECK_EQUAL(std::string(leavesQty.first, leavesQty.second), "0");
62  auto const side=fix_msg.find<exchanges::FIX::common::FieldsFast::Side>();
63  BOOST_CHECK_EQUAL(std::string(side.first, side.second), "1");
64 }
65 
66 BOOST_AUTO_TEST_CASE_TEMPLATE(OrderRejected, msg, msg_types) {
67  typename msg::OrderRejected exchg_msg(seqNum, clientOrderId1, exchanges::BATSBOE::common::OrderRejectReason::Admin);
68  exchanges::FIX::v5_0sp2::MsgTypes::OrderRejected fix_msg(exchg_msg);
69  BOOST_CHECK(fix_msg.is_valid());
70  auto const client_order_id=fix_msg.find<exchanges::FIX::common::FieldsFast::ClOrdID>();
71  BOOST_CHECK_EQUAL(std::string(client_order_id.first, client_order_id.second), clientOrderId1.begin());
72 }
73 
74 BOOST_AUTO_TEST_CASE_TEMPLATE(CancelRejected, msg, msg_types) {
75  typename msg::CancelRejected exchg_msg(seqNum, clientOrderId1, exchanges::BATSBOE::common::OrderRejectReason::Admin);
76  exchanges::FIX::v5_0sp2::MsgTypes::CancelRejected fix_msg(exchg_msg);
77  BOOST_CHECK(fix_msg.is_valid());
78  auto const client_order_id=fix_msg.find<exchanges::FIX::common::FieldsFast::ClOrdID>();
79  BOOST_CHECK_EQUAL(std::string(client_order_id.first, client_order_id.second), clientOrderId1.begin());
80 }
81 
82 BOOST_AUTO_TEST_CASE_TEMPLATE(UserModifyRejected, msg, msg_types) {
83  typename msg::UserModifyRejected exchg_msg(seqNum, clientOrderId1, exchanges::BATSBOE::common::OrderRejectReason::Admin);
84  const exchanges::FIX::v5_0sp2::MsgTypes::BusinessMessageReject fix_msg(exchg_msg);
85  BOOST_CHECK(fix_msg.is_valid());
86  auto const ref_seq_num=fix_msg.find<exchanges::FIX::common::FieldsFast::RefSeqNum>();
87  BOOST_CHECK_EQUAL(std::string(ref_seq_num.first, ref_seq_num.second), "1");
88 }
89 
90 BOOST_AUTO_TEST_CASE_TEMPLATE(OrderCancelled, msg, msg_types) {
91  typename msg::OrderCancelled exchg_msg(seqNum, clientOrderId1, exchanges::BATSBOE::common::OrderRejectReason::Admin, price, s, 0, 0);
92  exchanges::FIX::v5_0sp2::MsgTypes::ExecutionReport fix_msg(exchg_msg);
93  BOOST_CHECK(fix_msg.is_valid());
94  auto const client_order_id=fix_msg.find<exchanges::FIX::common::FieldsFast::ClOrdID>();
95  BOOST_CHECK_EQUAL(std::string(client_order_id.first, client_order_id.second), clientOrderId1.begin());
96  auto const fix_price=fix_msg.find<exchanges::FIX::common::FieldsFast::Price>();
97  BOOST_CHECK_EQUAL(static_cast<exchanges::BATSBOE::common::Price_t>(fromstring<double>(fix_price.first, fix_price.second-fix_price.first)), price/exchanges::BATSBOE::common::implied_decimal_places);
98  auto const orderQty=fix_msg.find<exchanges::FIX::common::FieldsFast::OrderQty>();
99  BOOST_CHECK_EQUAL(std::string(orderQty.first, orderQty.second), "0");
100  auto const leavesQty=fix_msg.find<exchanges::FIX::common::FieldsFast::LeavesQty>();
101  BOOST_CHECK_EQUAL(std::string(leavesQty.first, leavesQty.second), "0");
102  auto const side=fix_msg.find<exchanges::FIX::common::FieldsFast::Side>();
103  BOOST_CHECK_EQUAL(std::string(side.first, side.second), "1");
104 }
105 
106 BOOST_AUTO_TEST_SUITE_END()