libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
ref_data.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_MIT_COMMON_REF_DATA_HPP
2 #define ISIMUD_EXCHANGES_MIT_COMMON_REF_DATA_HPP
3 
4 /******************************************************************************
5 ** Copyright © 2016 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 "types.hpp"
23 
24 #include "../../common/isin.hpp"
25 
26 #include "core/csv_iterator.hpp"
27 #include "core/line_iterator.hpp"
28 #include "core/ttypes.hpp"
29 
30 #include <boost/lexical_cast.hpp>
31 #include <boost/mpl/assert.hpp>
32 
33 #include <functional>
34 #include <sstream>
35 #include <unordered_map>
36 
37 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace MIT { namespace common {
38 
39 /// Structures for encapsulating the MIT reference-data details.
40 /**
41  From Section 2.3 "Reference Data" of <a href="https://www.londonstockexchange.com/products-and-services/millennium-exchange/millennium-exchange-migration/mit301issue10.pdf">"London Stock Exchange - MIT301 - Guide to Market Data Services - Issue 10.14 February 2015"</a>.
42 */
43 class ref_data {
44 private:
45  struct MF_Record;
46 
47 public:
48  /**
49  From Section 2.2 "Instrument Identification"
50  */
51  struct security_id_key {
52  using element_type=exchanges::common::ISIN_t;
53 
54  const element_type isin_;
55 
56  explicit constexpr security_id_key(element_type const &isin) noexcept(true);
57  explicit security_id_key(MF_Record const &) noexcept(true);
58 
59  bool operator==(security_id_key const &sik) const noexcept(true);
60  bool operator<(security_id_key const &sik) const noexcept(true);
61 
62  std::string to_string() const noexcept(false);
63  };
64 
65 private:
66  struct hash_security_id_key {
67  using element_type=std::uint64_t;
68 
69  BOOST_MPL_ASSERT_RELATION(sizeof(security_id_key::element_type)/2, <=, sizeof(element_type));
70 
71  /**
72  \todo Need to check the quality of this hash operator.
73  */
74  element_type operator()(security_id_key const sik) const noexcept/* (true) - Bug in clang, so comment out. */;
75  };
76 
77 public:
78  /// Convert from a security_id_key to a common::SecurityID_t.
80  /// Convert from a common::SecurityID_t to a security_id_key.
82  enum : std::size_t {
84  isin_field=5
85  };
86  BOOST_MPL_ASSERT_RELATION(instrument_id_field, <, isin_field);
87 
88  /// Read the reference data from the input stream.
89  /**
90  The reference data should be in the format specified in <a href="http://www.londonstockexchange.com/products-and-services/millennium-exchange/millennium-exchange-migration/mit401.pdf">MIT401 - MILLENNIUM EXCHANGE - Guide to Reference Data Services - Issue 11.3 - 24 September 2013</a>.
91 
92  \param is The input std::istream that contains the reference data that should be in a restricted CSV format, with no comments, no internal white space, not escaping nor escaped commas.
93  */
94  explicit ref_data(std::istream &is) noexcept(false);
95 
96  /**
97  \return Const-accessor to the contained collection of security_id_key to common::SecurityID_t. Intra-day updates are not allowed via this method.
98  */
99  /**
100  \return Const-accessor to the contained collection of common::SecurityID_t to security_id_key. Intra-day updates are not allowed via this method.
101  */
102  lookup_instrument_id_t const &lookup_instrument_id() const noexcept(true) {
103  return lookup_instrument_id_;
104  }
105  lookup_isin_t const &lookup_isin() const noexcept(true) {
106  return lookup_isin_;
107  }
108 
109  std::string to_string() const noexcept(false);
110 
111 private:
112  /**
113  From section 2.3 "Reference Data".
114  */
115  struct MF_Record {
116  common::SecurityID_t instrument;
117  exchanges::common::ISIN_t isin;
118  };
119 
120  lookup_instrument_id_t lookup_instrument_id_;
121  lookup_isin_t lookup_isin_;
122 };
123 
124 std::ostream &
125 operator<<(std::ostream &is, ref_data::security_id_key const &sik) noexcept(false);
126 std::ostream &
127 operator<<(std::ostream &is, ref_data const &rd) noexcept(false);
128 
129 } } } } }
130 
131 #include "ref_data_impl.hpp"
132 
133 #endif