libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
messages.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_BATSBOE_EU_v1_MESSAGES_HPP
2 #define ISIMUD_EXCHANGES_BATSBOE_EU_v1_MESSAGES_HPP
3 
4 /******************************************************************************
5 ** Copyright © 2015 by J.M.McGuiness, isimud@hussar.me.uk
6 **
7 ** This library is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU Lesser General Public
9 ** License as published by the Free Software Foundation; either
10 ** version 2.1 of the License, or (at your option) any later version.
11 **
12 ** This library is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ** Lesser General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with this library; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 #include "config.h"
23 #include "../messages.hpp"
24 
25 #include "core/max_min.hpp"
26 
27 #include <boost/mpl/max_element.hpp>
28 #include <boost/mpl/min_element.hpp>
29 #include <boost/mpl/vector.hpp>
30 #include <boost/variant/variant.hpp>
31 
32 #include <iostream>
33 
34 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace BATSBOE { namespace EU {
35 
36 /**
37  From <a href="http://cdn.batstrading.com/resources/participant_resources/BATS_ChiX_Europe_TRF_BOE_Specification.pdf">"BATS Chi-X Europe TRF BOE Specification" Version 1.7 25th June 2014</a>, originally from <a href="http://cdn.batstrading.com/resources/participant_resources/BATS_Europe_Binary_Order_Entry_Specification.pdf">"BATS Chi-X Europe Binary Order Entry Specification", Version 1.44, 27 November, 2014</a>.
38 */
39 namespace v1 {
40 
41 struct MsgTypes {
42 
43  static inline constexpr const exchanges::common::mic_codes::ISO_10383_MIC_Codes MIC_code=exchanges::common::mic_codes::ISO_10383_MIC_Codes::ISO_10383_UNITED_KINGDOM_BATE;
44 
45  struct ref_data {};
46 
47  using MsgTypes_t=common::MsgType_t;
48  using MsgType_t=EU::MsgType;
49  using UserName_t=common::UserName_t;
50  using Password_t=common::Password_t;
51  using SecurityID_t=common::SecurityID_t;
52  using SeqNum_t=common::SeqNum_t;
53  using Price_t=common::Price_t;
54  using Quantity_t=common::Quantity_t;
55  using ClientOrderID_t=common::ClientOrderID_t;
56  using OrderType=common::OrdType;
57  using Side=common::Side;
58  using TIF=common::TIF;
59  using OrderRejectReason=common::OrderRejectReason;
60  using LoginResponseStatus=common::LoginResponseStatus;
61  using logon_args_t=common::logon_args_t;
62 
65  using LogoutRequest=common::LogoutRequest;
66  using ClientHeartbeat=common::ClientHeartbeat;
68  using Logout=common::Logout;
69  using ServerHeartbeat=common::ServerHeartbeat;
70  using ReplayComplete=common::ReplayComplete;
71  using NewOrder_t=common::NewOrder;
72  using CancelOrder=common::CancelOrder;
73  using ModifyOrder=common::ModifyOrder;
74  using TradeCaptureReport=EU::TradeCaptureReport;
75  using OrderAcknowledgement=common::OrderAcknowledgement;
76  using OrderRejected=common::OrderRejected;
77  using OrderModified=common::OrderModified;
78  using OrderRestated=common::OrderRestated;
79  using UserModifyRejected=common::UserModifyRejected;
80  using OrderCancelled=common::OrderCancelled;
81  using CancelRejected=common::CancelRejected;
82  using OrderExecution=common::OrderExecution;
83  using TradeCancelOrCorrect=common::TradeCancelOrCorrect;
84  using TradeCaptureReportAck=EU::TradeCaptureReportAck;
85  using TradeCaptureReportReject=EU::TradeCaptureReportReject;
86  using TradeCaptureConfirm=EU::TradeCaptureConfirm;
87  using TradeCaptureDecline=EU::TradeCaptureDecline;
88 
89  using ExecutionReport=OrderExecution;
90  using Heartbeat=ClientHeartbeat;
91  using OrderCancelRequest=CancelOrder;
92  using OrderCancelReject=CancelRejected;
93  using OrderCancelReplaceRequest=ModifyOrder;
94 
95  static inline constexpr MsgTypes_t MatchAll=static_cast<MsgTypes_t>(MsgType_t::MatchAll); ///< For the meta-state machine to allow a catch-all rule to reject anything unhandled.
96  static inline constexpr MsgTypes_t Exit=static_cast<MsgTypes_t>(MsgType_t::Exit); ///< For the meta-state machine: the exit state to exit the msm.
97 
102  NewOrder_t,
103  CancelOrder,
104  ModifyOrder,
106  >;
107 
109  LogonReply,
110  Logout,
126  >;
127 
128  enum : std::size_t {
130  boost::mpl::deref<
131  boost::mpl::min_element<
132  boost::mpl::transform_view<client_to_exchange_messages_t, boost::mpl::sizeof_<boost::mpl::_1> >
133  >::type::base
134  >::type
135  ),
137  boost::mpl::deref<
138  boost::mpl::max_element<
139  boost::mpl::transform_view<client_to_exchange_messages_t, boost::mpl::sizeof_<boost::mpl::_1> >
140  >::type::base
141  >::type
142  ),
144  boost::mpl::deref<
145  boost::mpl::min_element<
146  boost::mpl::transform_view<exchange_to_client_messages_t, boost::mpl::sizeof_<boost::mpl::_1> >
147  >::type::base
148  >::type
149  ),
151  boost::mpl::deref<
152  boost::mpl::max_element<
153  boost::mpl::transform_view<exchange_to_client_messages_t, boost::mpl::sizeof_<boost::mpl::_1> >
154  >::type::base
155  >::type
156  ),
157  min_msg_size=libjmmcg::min<std::size_t, min_size_client_to_exchange_msg, min_size_exchange_to_client_msg>::value,
158  max_msg_size=libjmmcg::max<std::size_t, max_size_client_to_exchange_msg, max_size_exchange_to_client_msg>::value,
159  header_t_size=sizeof(typename LogonRequest::Header_t)
160  };
161  BOOST_MPL_ASSERT_RELATION(max_msg_size, >=, header_t_size);
162 
163  using msg_buffer_t=std::array<std::uint8_t, max_msg_size>;
166 
168 
169  static std::ostream &to_stream(std::ostream &) noexcept(false);
170 };
171 
172 /**
173  \test BATSBOE EU v1 size tests.
174 */
175 namespace tests {
176 
177 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::LogoutRequest), <=, MsgTypes::max_size_client_to_exchange_msg);
178 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::LogoutRequest), <=, MsgTypes::max_size_exchange_to_client_msg);
179 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::LogoutRequest), <=, MsgTypes::max_msg_size);
180 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::LogonRequest), ==, 261);
181 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::LogoutRequest), ==, 10);
182 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::ClientHeartbeat), ==, 10);
183 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::LogonReply), ==, 11);
184 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::Logout), ==, 76);
185 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::ServerHeartbeat), ==, 10);
186 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::ReplayComplete), ==, 10);
187 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::NewOrder_t), ==, 157);
188 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::CancelOrder), ==, 36);
189 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::ModifyOrder), ==, 73);
190 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::TradeCaptureReport), ==, 133);
191 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::OrderAcknowledgement), ==, 245);
192 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::OrderRejected), ==, 213);
193 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::OrderModified), ==, 205);
194 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::OrderRestated), ==, 216);
195 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::UserModifyRejected), ==, 108);
196 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::OrderCancelled), ==, 191);
197 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::CancelRejected), ==, 100);
198 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::OrderExecution), ==, 215);
199 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::TradeCancelOrCorrect), ==, 170);
200 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::TradeCaptureReportAck), ==, 185);
201 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::TradeCaptureReportReject), ==, 246);
202 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::TradeCaptureConfirm), ==, 290);
203 BOOST_MPL_ASSERT_RELATION(sizeof(MsgTypes::TradeCaptureDecline), ==, 290);
204 
205 }
206 
207 } } } } } }
208 
209 #include "messages_impl.hpp"
210 
211 #endif