libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_to_batsboe_common_conversions.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_conversions_fix_to_batsboe_common_conversions_hpp
2 #define ISIMUD_EXCHANGES_conversions_fix_to_batsboe_common_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 #include "../BATSBOE/common/messages.hpp"
25 
26 #include <cstring>
27 
28 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace BATSBOE { namespace common {
29 
30 template<class Ret> constexpr Ret
31 convert(FIX::common::field_str_const_range_t const &)=delete;
32 
33 /**
34  \todo What should be done with OrdType's that cannot be mapped?.
35 */
36 template<> constexpr inline OrdType
37 convert<OrdType>(FIX::common::field_str_const_range_t const &a) {
38  assert((a.second-a.first)==1);
39  switch (*a.first) {
40  case '1':
41  return OrdType::Market;
42  case '2':
43  return OrdType::Limit;
44  case 'P':
45  return OrdType::Pegged;
46  default:
47  return static_cast<OrdType>(0);
48  };
49 }
50 
51 /**
52  \todo What should be done with TIF's that cannot be mapped?.
53 */
54 template<> constexpr inline TIF
55 convert<TIF>(FIX::common::field_str_const_range_t const &a) {
56  assert((a.second-a.first)==1);
57  switch (*a.first) {
58  case '0':
59  return TIF::Day;
60  case '1':
61  return TIF::GTC;
62  case '2':
63  return TIF::ATO;
64  case '3':
65  return TIF::IOC;
66  case '6':
67  return TIF::GTD;
68  case '7':
69  return TIF::ATC;
70  default:
71  return static_cast<TIF>(0);
72  };
73 }
74 
75 /**
76  \todo What should be done with Side's that cannot be mapped?.
77 */
78 template<> constexpr inline Side
79 convert<Side>(FIX::common::field_str_const_range_t const &a) {
80  assert((a.second-a.first)==1);
81  switch (*a.first) {
82  case '1':
83  return Side::Buy;
84  case '2':
85  return Side::Sell;
86  case '5':
87  return Side::Sell_short;
88  case '6':
89  return Side::Sell_short_exempt;
90  default:
91  return static_cast<Side>(0);
92  };
93 }
94 
95 /**
96  \todo We need to consider the symbology used, for example a conversion from ISIN to MIT native symbology.
97 */
98 template<> inline SecurityID_t
99 convert<SecurityID_t>(FIX::common::field_str_const_range_t const &a) {
100  SecurityID_t ret;
101  assert((a.second-a.first)>0);
102  assert(static_cast<SecurityID_t::size_type>(a.second-a.first)<ret.size());
103  std::memcpy(ret.data(), a.first, (a.second-a.first));
104  std::fill_n(ret.data()+(a.second-a.first), ret.size()-(a.second-a.first), '\0');
105  return ret;
106 }
107 
108 template<> inline Price_t
109 convert<Price_t>(FIX::common::field_str_const_range_t const &a) {
110  assert((a.second-a.first)>0);
111  return static_cast<Price_t>(libjmmcg::fromstring<double>(a.first, a.second-a.first)*implied_decimal_places);
112 }
113 
114 template<> inline Quantity_t
115 convert<Quantity_t>(FIX::common::field_str_const_range_t const &a) {
116  assert((a.second-a.first)>0);
117  return static_cast<Quantity_t>(libjmmcg::fromstring<double>(a.first, a.second-a.first)*implied_decimal_places);
118 }
119 
120 template<> inline
121 LogoutRequest::LogoutRequest(FIX::v5_0sp2::MsgTypes::LogoutRequest const &, SeqNum_t seqNum) noexcept(true)
122 : LogoutRequest(seqNum) {
123 }
124 
125 template<> inline
126 ClientHeartbeat::ClientHeartbeat(FIX::v5_0sp2::MsgTypes::ClientHeartbeat const &, SeqNum_t seqNum) noexcept(true)
127 : ClientHeartbeat(seqNum) {
128 }
129 
130 template<> inline
131 ServerHeartbeat::ServerHeartbeat(FIX::v5_0sp2::MsgTypes::ServerHeartbeat const &, SeqNum_t seqNum) noexcept(true)
132 : ServerHeartbeat(seqNum) {
133 }
134 
135 /**
136  Note that only ISIN symbology is supported.
137 */
138 template<> inline __stdcall
139 NewOrder::NewOrder(FIX::v5_0sp2::MsgTypes::NewOrderSingle const &msg, SeqNum_t seqNum) noexcept(true)
140 : NewOrder(
141  seqNum,
149  ) {
150  // We only support ISIN.
151  assert(!bitfields.find<bitfields_tags_type::IDSource>());
152 }
153 
154 template<> inline __stdcall
155 CancelOrder::CancelOrder(FIX::v5_0sp2::MsgTypes::OrderCancelRequest const &msg, SeqNum_t seqNum) noexcept(true)
156 : CancelOrder(
157  seqNum,
159  ) {
160 }
161 
162 template<> inline __stdcall
163 ModifyOrder::ModifyOrder(FIX::v5_0sp2::MsgTypes::OrderCancelReplace const &msg, SeqNum_t seqNum) noexcept(true)
164 : ModifyOrder(
165  seqNum,
170  ) {
171 }
172 
173 } } } } }
174 
175 #endif