libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_to_mit_conversions.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_conversions_fix_to_mit_conversions_hpp
2 #define ISIMUD_EXCHANGES_conversions_fix_to_mit_conversions_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 "../../exchanges/FIX/v5.0sp2/messages.hpp"
23 #include "../../exchanges/FIX/common/conversions.hpp"
24 
25 #include "../../exchanges/MIT/BIT/messages.hpp"
26 #include "../../exchanges/MIT/JSE/messages.hpp"
27 #include "../../exchanges/MIT/LSE/messages.hpp"
28 #include "../../exchanges/MIT/OSLO/messages.hpp"
29 #include "../../exchanges/MIT/TRQ/messages.hpp"
30 
31 #include "core/memops.hpp"
32 
33 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace MIT {
34 
35 namespace common {
36 
37 template<class Ret> Ret
38 convert(FIX::common::field_str_const_range_t const &) __attribute__((pure)) =delete;
39 
40 /**
41  \todo What should be done with OrderType's that cannot be mapped?.
42 */
43 template<> constexpr inline OrderType
44 convert<OrderType>(FIX::common::field_str_const_range_t const &a) {
45  assert((a.second-a.first)==1);
46  switch (*a.first) {
47  case '1':
48  return OrderType::Market;
49  case '2':
50  return OrderType::Limit;
51  case '3':
52  return OrderType::Stop;
53  case '4':
54  return OrderType::StopLimit;
55  default:
56  return static_cast<OrderType>(0);
57  };
58 }
59 
60 /**
61  \todo What should be done with TIF's that cannot be mapped?.
62 */
63 template<> inline constexpr TIF
64 convert<TIF>(FIX::common::field_str_const_range_t const &a) {
65  assert((a.second-a.first)==1);
66  switch (*a.first) {
67  case '0':
68  return TIF::Day;
69  case '2':
70  return TIF::OPG;
71  case '3':
72  return TIF::IOC;
73  case '4':
74  return TIF::FOK;
75  case '6':
76  return TIF::GTD;
77  case '7':
78  return TIF::ATC;
79  default:
80  return static_cast<TIF>(0);
81  };
82 }
83 
84 /**
85  \todo What should be done with Side's that cannot be mapped?.
86 */
87 template<> constexpr inline Side
88 convert<Side>(FIX::common::field_str_const_range_t const &a) {
89  assert((a.second-a.first)==1);
90  switch (*a.first) {
91  case '1':
92  return Side::Buy;
93  case '2':
94  return Side::Sell;
95  default:
96  return static_cast<Side>(0);
97  };
98 }
99 
100 /**
101  Note that only ISIN symbology is supported.
102 */
103 template<class MsgT, class RefData> constexpr inline SecurityID_t
104 convert_SecurityID_t(MsgT const &msg, RefData const &ref_data) {
105  auto const &isin_ptrs=msg.template find<FIX::common::FieldsFast::SecurityID>();
106  assert((isin_ptrs.second-isin_ptrs.first)==sizeof(typename RefData::lookup_instrument_id_t::key_type));
107  const typename RefData::lookup_instrument_id_t::key_type::element_type isin(reinterpret_cast<typename RefData::lookup_instrument_id_t::key_type::element_type::block_t const &>(*isin_ptrs.first));
108  const typename RefData::lookup_instrument_id_t::key_type key(isin);
109  auto const &i=ref_data.lookup_instrument_id().find(key);
110  assert(i!=ref_data.lookup_instrument_id().end());
111  return i->second;
112 }
113 
114 template<> inline Price_t
115 convert<Price_t>(FIX::common::field_str_const_range_t const &a) {
116  assert((a.second-a.first)>0);
117  return static_cast<Price_t>(libjmmcg::fromstring<double>(a.first, a.second-a.first)*implied_decimal_places);
118 }
119 
120 template<> inline __stdcall
121 LogonRequest::LogonRequest(FIX::v5_0sp2::MsgTypes::LogonRequest const &msg) noexcept(true)
122 : LogonRequest(
126  ) {
127  assert(is_valid());
128 }
129 
130 template<> inline __stdcall constexpr
131 LogoutRequest::LogoutRequest(FIX::v5_0sp2::MsgTypes::LogoutRequest const &, Reason_t r) noexcept(true)
132 : LogoutRequest(r) {
133  assert(is_valid());
134 }
135 
136 template<> inline __stdcall constexpr
137 Heartbeat::Heartbeat(FIX::v5_0sp2::MsgTypes::ClientHeartbeat const &) noexcept(true)
138 : Heartbeat() {
139  assert(is_valid());
140 }
141 
142 }
143 
144 namespace BIT {
145 
146 template<> inline __stdcall
147 NewOrder::NewOrder(FIX::v5_0sp2::MsgTypes::NewOrderSingle const &msg, common::ref_data const &rd) noexcept(true)
148 : base_t(
157 ) {
158  assert(is_valid());
159 }
160 
161 template<> inline __stdcall
162 OrderCancelRequest::OrderCancelRequest(FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &msg, common::ref_data const &rd) noexcept(true)
163 : base_t(
168 ) {
169  assert(is_valid());
170 }
171 
172 template<> inline __stdcall
173 OrderCancelReplaceRequest::OrderCancelReplaceRequest(FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &msg, common::ref_data const &rd) noexcept(true)
174 : base_t(
182 ) {
183  assert(is_valid());
184 }
185 
186 }
187 
188 namespace JSE {
189 
190 template<> inline __stdcall
191 Logon::Logon(FIX::v5_0sp2::MsgTypes::LogonRequest const &msg) noexcept(true)
192 : Logon(
196  ) {
197  assert(is_valid());
198 }
199 
200 template<> inline __stdcall
201 NewOrder::NewOrder(FIX::v5_0sp2::MsgTypes::NewOrderSingle const &msg, common::ref_data const &rd) noexcept(true)
202 : NewOrder(
211 ) {
212  assert(is_valid());
213 }
214 
215 template<> inline __stdcall
216 OrderCancelRequest::OrderCancelRequest(FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &msg, common::ref_data const &rd) noexcept(true)
217 : base_t(
222 ) {
223 }
224 
225 template<> inline __stdcall
226 OrderCancelReplaceRequest::OrderCancelReplaceRequest(FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &msg, common::ref_data const &rd) noexcept(true)
235 ) {
236  assert(is_valid());
237 }
238 
239 }
240 
241 namespace LSE {
242 
243 template<> inline __stdcall
244 NewOrder::NewOrder(FIX::v5_0sp2::MsgTypes::NewOrderSingle const &msg, common::ref_data const &rd) noexcept(true)
245 : base_t(
254 ) {
255  assert(is_valid());
256 }
257 
258 template<> inline __stdcall
259 OrderCancelRequest::OrderCancelRequest(FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &msg, common::ref_data const &rd) noexcept(true)
260 : base_t(
265 ) {
266  assert(is_valid());
267 }
268 
269 template<> inline __stdcall
270 OrderCancelReplaceRequest::OrderCancelReplaceRequest(FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &msg, common::ref_data const &rd) noexcept(true)
271 : base_t(
279 ) {
280  assert(is_valid());
281 }
282 
283 }
284 
285 namespace OSLO {
286 
287 template<> inline __stdcall
288 NewOrder::NewOrder(FIX::v5_0sp2::MsgTypes::NewOrderSingle const &msg, common::ref_data const &rd) noexcept(true)
289 : base_t(
298 ) {
299  assert(is_valid());
300 }
301 
302 template<> inline __stdcall
303 OrderCancelRequest::OrderCancelRequest(FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &msg, common::ref_data const &rd) noexcept(true)
304 : base_t(
309 ) {
310  assert(is_valid());
311 }
312 
313 template<> inline __stdcall
314 OrderCancelReplaceRequest::OrderCancelReplaceRequest(FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &msg, common::ref_data const &rd) noexcept(true)
315 : base_t(
323 ) {
324  assert(is_valid());
325 }
326 
327 }
328 
329 namespace TRQ {
330 
331 template<> inline __stdcall
332 NewOrder::NewOrder(FIX::v5_0sp2::MsgTypes::NewOrderSingle const &msg, common::ref_data const &rd) noexcept(true)
333 : base_t(
342 ) {
343  assert(is_valid());
344 }
345 
346 template<> inline __stdcall
347 OrderCancelRequest::OrderCancelRequest(FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &msg, common::ref_data const &rd) noexcept(true)
348 : base_t(
353 ) {
354  assert(is_valid());
355 }
356 
357 template<> inline __stdcall
358 OrderCancelReplaceRequest::OrderCancelReplaceRequest(FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &msg, common::ref_data const &rd) noexcept(true)
359 : base_t(
367 ) {
368  assert(is_valid());
369 }
370 
371 }
372 
373 } } } }
374 
375 #endif