libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_to_mit.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/fix_to_mit_conversions.hpp"
27 
28 using namespace libjmmcg;
29 using namespace libisimud;
30 
31 typedef boost::mpl::list<
38 
39 BOOST_AUTO_TEST_SUITE(exchange_gateways)
40 
41 BOOST_AUTO_TEST_SUITE(admin)
42 
43 BOOST_AUTO_TEST_CASE_TEMPLATE(LogonRequest, msg, msg_types) {
44  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
45  "8=FIX.5.0\0019=099\00135=A\00149=SENDER\00156=TARGET\00134=1\00152=20000426-12:05:06\00198=0\001108=30\001553=USER\001554=PASSWORD\001925=NEWPASSWD\00110=238\001"
46  };
47  exchanges::FIX::v5_0sp2::MsgTypes::LogonRequest const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::LogonRequest const &>(*fix_buffer.begin());
48  BOOST_CHECK(fix_msg.is_valid());
49  typename msg::first_type::LogonRequest exchg_msg(fix_msg);
50  BOOST_CHECK_EQUAL(exchg_msg.start_of_message, 2);
51  BOOST_CHECK_EQUAL(std::string(exchg_msg.userName.begin()), "USER");
52  BOOST_CHECK_EQUAL(std::string(exchg_msg.password.begin()), "PASSWORD");
53  BOOST_CHECK_EQUAL(std::string(exchg_msg.newPassword.begin()), "NEWPASSWD");
54 }
55 
56 BOOST_AUTO_TEST_CASE_TEMPLATE(Logout, msg, msg_types) {
57  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
58  "8=FIX.5.0\0019=005\00135=5\00110=005\001"
59  };
60  exchanges::FIX::v5_0sp2::MsgTypes::LogoutRequest const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::LogoutRequest const &>(*fix_buffer.begin());
61  BOOST_CHECK(fix_msg.is_valid());
62  typename msg::first_type::LogoutRequest exchg_msg(fix_msg, exchanges::MIT::common::Reason_t{'U', 's', 'e', 'r', ' ', 'l', 'o', 'g', 'o', 'u', 't', ' ', 'r', 'e', 'c', 'e', 'i', 'v', 'e', 'd'});
63  BOOST_CHECK_EQUAL(exchg_msg.start_of_message, 2);
64 }
65 
66 BOOST_AUTO_TEST_CASE_TEMPLATE(ClientHeartbeat, msg, msg_types) {
67  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
68  "8=FIX.5.0\0019=005\00135=0\00110=000\001"
69  };
70  exchanges::FIX::v5_0sp2::MsgTypes::ClientHeartbeat const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::ClientHeartbeat const &>(*fix_buffer.begin());
71  BOOST_CHECK(fix_msg.is_valid());
72  typename msg::first_type::ClientHeartbeat exchg_msg(fix_msg);
73  BOOST_CHECK_EQUAL(exchg_msg.start_of_message, 2);
74 }
75 
76 BOOST_AUTO_TEST_SUITE_END()
77 
78 BOOST_AUTO_TEST_SUITE(conversions)
79 
80 BOOST_AUTO_TEST_CASE_TEMPLATE(NewOrderSingle, msg, msg_types) {
81  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
82  "8=FIX.5.0\0019=154\00135=D\00134=10\00143=N\00149=VENDOR\00150=CUSTOME\00156=BROKER\00160=19980930-09:25:58\0011=XQCCFUND\00111=10\00121=1\00155=69\00148=GB0000595859\00122=4\00154=1\00138=10000\00140=2\00144=76.750000\00159=0\00110=059\001"
83  };
84  exchanges::FIX::v5_0sp2::MsgTypes::NewOrderSingle const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::NewOrderSingle const &>(*fix_buffer.begin());
85  BOOST_CHECK(fix_msg.is_valid());
86  BOOST_CHECK_EQUAL(exchanges::MIT::common::convert<exchanges::MIT::common::OrderType>(fix_msg.find<exchanges::FIX::common::FieldsFast::OrdType>()), exchanges::MIT::common::OrderType::Limit);
87  BOOST_CHECK_EQUAL(exchanges::MIT::common::convert<exchanges::MIT::common::TIF>(fix_msg.find<exchanges::FIX::common::FieldsFast::TimeInForce>()), exchanges::MIT::common::TIF::Day);
88  BOOST_CHECK_EQUAL(exchanges::MIT::common::convert<exchanges::MIT::common::Side>(fix_msg.find<exchanges::FIX::common::FieldsFast::Side>()), exchanges::MIT::common::Side::Buy);
89  BOOST_CHECK_EQUAL(tostring(exchanges::FIX::common::convert<exchanges::FIX::common::SecurityID_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::Symbol>())), "69");
90  BOOST_CHECK_EQUAL(exchanges::FIX::common::convert<exchanges::FIX::common::Quantity_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::OrderQty>()), 10000);
91  BOOST_CHECK_CLOSE(exchanges::MIT::common::convert<exchanges::MIT::common::Price_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::Price>()), exchanges::MIT::common::implied_decimal_places*76.75, 0.01);
92 }
93 
94 BOOST_AUTO_TEST_SUITE_END()
95 
96 BOOST_AUTO_TEST_SUITE(trade)
97 
98 BOOST_AUTO_TEST_CASE_TEMPLATE(NewOrderSingle, msg, msg_types) {
99  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
100  "8=FIX.5.0\0019=154\00135=D\00134=10\00143=N\00149=VENDOR\00150=CUSTOME\00156=BROKER\00160=19980930-09:25:58\0011=XQCCFUND\00111=10\00121=1\00155=EK\00148=GB00BH4HKS39\00122=4\00154=1\00138=10000\00140=2\00144=76.750000\00159=0\00110=195\001"
101  };
102  exchanges::FIX::v5_0sp2::MsgTypes::NewOrderSingle const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::NewOrderSingle const &>(*fix_buffer.begin());
103  BOOST_CHECK(fix_msg.is_valid());
104  const std::string ref_data_file("133215;FTSE100;SET0;PT_T;TP_1;GB00BH4HKS39;;20060731;0;1;10000;42467000;1;;1;DE;VOD;VODAFONE GRP.;BH4HKS3;15225662730;GBX;1;Y;0023;VOVOD;VODAFONE GROUP PLC;0;;;15000;ORD USD0.20 20/21;;1;1;5;GB;;;FE00;1;;;;1;A;;;;;;");
105  std::stringstream ss;
106  ss<<ref_data_file;
107  const typename msg::second_type ref_data(ss);
108  typename msg::first_type::NewOrder_t exchg_msg(fix_msg, ref_data);
109  BOOST_CHECK_EQUAL(exchg_msg.start_of_message, 2);
110  BOOST_CHECK_EQUAL(std::string(exchg_msg.clientOrderID().begin()), "10");
111  BOOST_CHECK_EQUAL(exchg_msg.orderQty(), exchanges::FIX::common::convert<exchanges::FIX::common::Quantity_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::OrderQty>()));
112  BOOST_CHECK_EQUAL(exchg_msg.orderType(), exchanges::MIT::common::convert<exchanges::MIT::common::OrderType>(fix_msg.find<exchanges::FIX::common::FieldsFast::OrdType>()));
113  BOOST_CHECK_EQUAL(exchg_msg.side(), exchanges::MIT::common::convert<exchanges::MIT::common::Side>(fix_msg.find<exchanges::FIX::common::FieldsFast::Side>()));
114  BOOST_CHECK_EQUAL(exchg_msg.instrumentID(), 133215);
115  BOOST_CHECK_EQUAL(exchg_msg.limitPrice(), exchanges::MIT::common::convert<exchanges::MIT::common::Price_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::Price>()));
116  BOOST_CHECK_EQUAL(exchg_msg.tif(), exchanges::MIT::common::convert<exchanges::MIT::common::TIF>(fix_msg.find<exchanges::FIX::common::FieldsFast::TimeInForce>()));
117 }
118 
119 BOOST_AUTO_TEST_CASE_TEMPLATE(OrderCancelRequest, msg, msg_types) {
120  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
121  "8=FIX.5.0\0019=079\00135=F\00111=10\00141=10\00148=GB00BH4HKS39\00155=CUSTOME\00154=1\00160=19980930-09:25:58\00138=10000\00110=044\001"
122  };
123  exchanges::FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &>(*fix_buffer.begin());
124  BOOST_CHECK(fix_msg.is_valid());
125  const std::string ref_data_file("133215;FTSE100;SET0;PT_T;TP_1;GB00BH4HKS39;;20060731;0;1;10000;42467000;1;;1;DE;VOD;VODAFONE GRP.;BH4HKS3;15225662730;GBX;1;Y;0023;VOVOD;VODAFONE GROUP PLC;0;;;15000;ORD USD0.20 20/21;;1;1;5;GB;;;FE00;1;;;;1;A;;;;;;");
126  std::stringstream ss;
127  ss<<ref_data_file;
128  const typename msg::second_type ref_data(ss);
129  typename msg::first_type::OrderCancelRequest exchg_msg(fix_msg, ref_data);
130  BOOST_CHECK_EQUAL(exchg_msg.start_of_message, 2);
131  BOOST_CHECK_EQUAL(std::string(exchg_msg.originalClientOrderID().begin()), "10");
132  BOOST_CHECK_EQUAL(exchg_msg.side(), exchanges::MIT::common::convert<exchanges::MIT::common::Side>(fix_msg.find<exchanges::FIX::common::FieldsFast::Side>()));
133  BOOST_CHECK_EQUAL(exchg_msg.instrumentID(), 133215);
134 }
135 
136 BOOST_AUTO_TEST_CASE_TEMPLATE(OrderCancelReplace, msg, msg_types) {
137  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
138  "8=FIX.5.0\0019=141\00135=G\00111=10\00141=10\00148=GB00BH4HKS39\00149=VENDOR\00156=BROKER\00134=10\00152=20000426-12:05:06\00155=EK\00154=1\00160=19980930-09:25:58\00138=99\00140=1\00144=43.000000\00159=0\00110=013\001"
139  };
140  exchanges::FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &fix_msg=reinterpret_cast<exchanges::FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &>(*fix_buffer.begin());
141  BOOST_CHECK(fix_msg.is_valid());
142  const std::string ref_data_file("133215;FTSE100;SET0;PT_T;TP_1;GB00BH4HKS39;;20060731;0;1;10000;42467000;1;;1;DE;VOD;VODAFONE GRP.;BH4HKS3;15225662730;GBX;1;Y;0023;VOVOD;VODAFONE GROUP PLC;0;;;15000;ORD USD0.20 20/21;;1;1;5;GB;;;FE00;1;;;;1;A;;;;;;");
143  std::stringstream ss;
144  ss<<ref_data_file;
145  const typename msg::second_type ref_data(ss);
146  typename msg::first_type::OrderCancelReplaceRequest exchg_msg(fix_msg, ref_data);
147  BOOST_CHECK_EQUAL(exchg_msg.start_of_message, 2);
148  BOOST_CHECK_EQUAL(std::string(exchg_msg.originalClientOrderID().begin()), "10");
149  BOOST_CHECK_EQUAL(exchg_msg.orderQty(), exchanges::FIX::common::convert<exchanges::FIX::common::Quantity_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::OrderQty>()));
150  BOOST_CHECK_EQUAL(exchg_msg.side(), exchanges::MIT::common::convert<exchanges::MIT::common::Side>(fix_msg.find<exchanges::FIX::common::FieldsFast::Side>()));
151  BOOST_CHECK_EQUAL(exchg_msg.instrumentID(), 133215);
152  BOOST_CHECK_EQUAL(exchg_msg.limitPrice(), exchanges::MIT::common::convert<exchanges::MIT::common::Price_t>(fix_msg.find<exchanges::FIX::common::FieldsFast::Price>()));
153  BOOST_CHECK_EQUAL(exchg_msg.tif(), exchanges::MIT::common::convert<exchanges::MIT::common::TIF>(fix_msg.find<exchanges::FIX::common::FieldsFast::TimeInForce>()));
154 }
155 
156 BOOST_AUTO_TEST_SUITE_END()
157 
158 BOOST_AUTO_TEST_SUITE_END()