libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
batsboe_common_to_fix_conversions.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_conversions_batsboe_common_to_fix_conversions_hpp
2 #define ISIMUD_EXCHANGES_conversions_batsboe_common_to_fix_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 "../BATSBOE/common/messages.hpp"
24 
25 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace FIX { namespace common {
26 
27 constexpr inline Side
29  switch (a) {
31  return Side::Buy;
33  return Side::Sell;
35  return Side::Sell_short;
37  default:
38  return Side::Sell_short_exempt;
39  };
40 }
41 
42 inline int
43 convert_price(BATSBOE::common::Price_t const &a, char *buff, std::size_t sz) {
44  const double c=static_cast<double>(a)/BATSBOE::common::implied_decimal_places;
45  return libjmmcg::tostring(c, buff, sz);
46 }
47 
48 template<>
49 template<> inline
51 : Header_t() {
55  data+=msg.clientOrderID().size()-1;
58  ++data;
60  libjmmcg::memcpy_opt(msg.instrumentID(), reinterpret_cast<BATSBOE::common::SecurityID_t &>(*data));
61  data+=msg.instrumentID().size()-1;
63  const int j=convert_price(msg.executedPrice(), data, this->data_.size()-(data-this->data_.begin()));
64  assert(j>0);
65  data+=j;
67  const int k=convert(msg.executedQty(), data, this->data_.size()-(data-this->data_.begin()));
68  assert(k>0);
69  data+=k;
71  const int l=convert(msg.leavesQty(), data, this->data_.size()-(data-this->data_.begin()));
72  assert(l>0);
73  data+=l;
75  *data=static_cast<std::underlying_type<Side>::type>(convert(msg.side()));
76  ++data;
77 // TODO msg.orderRejectCode();
79 }
80 
81 template<>
82 template<> inline
84 : Header_t() {
88  data+=msg.clientOrderID().size()-1;
90  const int i=convert(msg.sequenceNumber, data, this->data_.size()-(data-this->data_.begin()));
91  assert(i>0);
92  data+=i;
94 }
95 
96 template<>
97 template<> inline
99 : Header_t() {
102  libjmmcg::memcpy_opt(msg.clientOrderID(), reinterpret_cast<BATSBOE::common::ClientOrderID_t &>(*data));
103  data+=msg.clientOrderID().size()-1;
104 // TODO cancelRejectReason_;
105 // TODO transactTime;
107 }
108 
109 template<>
110 template<> inline
112 : Header_t() {
115  libjmmcg::memcpy_opt(msg.clientOrderID(), reinterpret_cast<BATSBOE::common::ClientOrderID_t &>(*data));
116  data+=msg.clientOrderID().size()-1;
118  const int i=convert(msg.sequenceNumber, data, this->data_.size()-(data-this->data_.begin()));
119  assert(i>0);
120  data+=i;
121 // TODO
123 }
124 
125 template<>
126 template<> inline
128 : Header_t() {
131  libjmmcg::memcpy_opt(msg.clientOrderID(), reinterpret_cast<BATSBOE::common::ClientOrderID_t &>(*data));
132  data+=msg.clientOrderID().size()-1;
134  const int j=convert_price(msg.lastPrice(), data, this->data_.size()-(data-this->data_.begin()));
135  assert(j>0);
136  data+=j;
138  const int k=convert(msg.orderQty(), data, this->data_.size()-(data-this->data_.begin()));
139  assert(k>0);
140  data+=k;
142  const int l=convert(msg.leavesQty(), data, this->data_.size()-(data-this->data_.begin()));
143  assert(l>0);
144  data+=l;
146  *data=static_cast<std::underlying_type<Side>::type>(convert(msg.side()));
147  ++data;
148 // TODO msg.orderRejectCode();
150 }
151 
152 } } } } }
153 
154 #endif