root/isimud/exchanges/BATSBOE/common/processing_rules.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef libjmmcg_isimud_exchanges_common_MIT_processing_rules_hpp
   2 #define libjmmcg_isimud_exchanges_common_MIT_processing_rules_hpp
   3 
   4 /******************************************************************************
   5 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/exchanges/BATSBOE/common/processing_rules.hpp 2358 2018-10-22 23:59:23Z jmmcg $
   6 **
   7 ** Copyright (c) 2015 by J.M.McGuiness, isimud@hussar.me.uk
   8 **
   9 ** This library is free software; you can redistribute it and/or
  10 ** modify it under the terms of the GNU Lesser General Public
  11 ** License as published by the Free Software Foundation; either
  12 ** version 2.1 of the License, or (at your option) any later version.
  13 **
  14 ** This library is distributed in the hope that it will be useful,
  15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17 ** Lesser General Public License for more details.
  18 **
  19 ** You should have received a copy of the GNU Lesser General Public
  20 ** License along with this library; if not, write to the Free Software
  21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22 */
  23 
  24 #include "../../common/processing_rules.hpp"
  25 
  26 #include "core/msm.hpp"
  27 
  28 namespace isimud { namespace exchanges { namespace BATSBOE { namespace common {
  29 
  30 /// A client-to-BATSBOE-protocol message handler.
  31 /**
  32         The behaviour of this handler is derived from the specification in  [1, 2].
  33         [1] "BATS Chi-X Europe Binary Order Entry Specification Version 1.44"
  34         [2] "BZX Exchange US Equities BOE Specification Version 1.8.6"
  35 */
  36 template<class SrcMsgDetails, class DestMsgDetails, class SktT>
  37 class client_to_exchange_transformations final : public exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails, SktT>, typename SrcMsgDetails::client_to_exchange_messages_t, SktT> {
  38 public:
  39         using base_t=exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails, SktT>, typename SrcMsgDetails::client_to_exchange_messages_t, SktT>;
  40         using src_msg_details_t=typename base_t::src_msg_details_t;
  41         using dest_msg_details_t=typename base_t::dest_msg_details_t;
  42         using socket_t=typename base_t::socket_t;
  43 
  44         /**
  45                 \return False to continue processing messages, true otherwise.
  46         */
  47         bool process_msg(typename src_msg_details_t::msg_buffer_t const &buff, socket_t &exchg_skt, socket_t &dest_skt) override;
  48 
  49         std::string to_string() const noexcept(false);
  50 
  51 private:
  52         struct state_machine_t;
  53         using machine=jmmcg::msm::unroll::machine<state_machine_t>;
  54 
  55         std::uint32_t sequenceNumber{};
  56         const machine msm{std::ref(sequenceNumber)};
  57 };
  58 
  59 template<class SrcMsgDetails, class DestMsgDetails, class SktT> inline std::ostream &
  60 operator<<(std::ostream &os, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails, SktT> const &ec) noexcept(false);
  61 
  62 /// A BATSBOE-protocol-to-client message handler.
  63 /**
  64         The behaviour of this handler is derived from the specification in  [1, 2].
  65         [1] "BATS Chi-X Europe Binary Order Entry Specification Version 1.44"
  66         [2] "BZX Exchange US Equities BOE Specification Version 1.8.6"
  67 */
  68 template<class SrcMsgDetails, class DestMsgDetails, class SktT>
  69 class exchange_to_client_transformations final : public exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails, SktT>, typename SrcMsgDetails::exchange_to_client_messages_t, SktT> {
  70 public:
  71         using base_t=exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails, SktT>, typename SrcMsgDetails::exchange_to_client_messages_t, SktT>;
  72         using src_msg_details_t=typename base_t::src_msg_details_t;
  73         using dest_msg_details_t=typename base_t::dest_msg_details_t;
  74         using socket_t=typename base_t::socket_t;
  75 
  76         /**
  77                 \return False to continue processing messages, true otherwise.
  78         */
  79         bool process_msg(typename src_msg_details_t::msg_buffer_t const &buff, socket_t &exchg_skt, socket_t &client_skt) override;
  80 
  81         std::string to_string() const noexcept(false);
  82 
  83 private:
  84         struct state_machine_t;
  85         using machine=jmmcg::msm::unroll::machine<state_machine_t>;
  86 
  87         std::uint32_t sequenceNumber{};
  88         const machine msm{std::ref(sequenceNumber)};
  89 };
  90 
  91 template<class SrcMsgDetails, class DestMsgDetails, class SktT> inline std::ostream &
  92 operator<<(std::ostream &os, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails, SktT> const &ec) noexcept(false);
  93 
  94 /// A simple, BATSBOE-protocol exchange simulator.
  95 /**
  96         The behaviour of this simulator is a simplification derived from the specification in [1, 2].
  97         [1] "BATS Chi-X Europe Binary Order Entry Specification Version 1.44"
  98         [2] "BZX Exchange US Equities BOE Specification Version 1.8.6"
  99 */
 100 template<class SrcMsgDetails, class SktT>
 101 class simulator_responses final : public exchanges::common::simulator_responses<SrcMsgDetails, simulator_responses<SrcMsgDetails, SktT>, SktT> {
 102 public:
 103         using base_t=exchanges::common::simulator_responses<SrcMsgDetails, simulator_responses<SrcMsgDetails, SktT>, SktT>;
 104         using msg_details_t=typename base_t::msg_details_t;
 105         using src_msg_details_t=msg_details_t;
 106         using socket_t=typename base_t::socket_t;
 107 
 108         /// The only valid instrument, all others will be rejected.
 109         static inline constexpr typename msg_details_t::SecurityID_t instrumentID{"GB00BH4HKS39"};
 110         /// An invalid instrument, that will be rejected.
 111         static inline constexpr typename msg_details_t::SecurityID_t invalidInstrumentID{"GB0000595859"};
 112 
 113         simulator_responses()=default;
 114         simulator_responses(simulator_responses const &sr) noexcept(true)
 115         : base_t(sr), msm{std::ref(*this)} {
 116         }
 117 
 118         /**
 119                 \return False to continue processing messages, true otherwise.
 120         */
 121         bool process_msg(typename msg_details_t::msg_buffer_t const &buff, socket_t &exchg_skt, socket_t &client_skt) override;
 122 
 123         std::string to_string() const noexcept(false);
 124 
 125 private:
 126         struct state_machine_t;
 127         using machine=jmmcg::msm::unroll::machine<state_machine_t>;
 128 
 129         const machine msm{std::ref(*this)};
 130 };
 131 
 132 template<class SrcMsgDetails, class SktT> inline std::ostream &
 133 operator<<(std::ostream &os, simulator_responses<SrcMsgDetails, SktT> const &ec) noexcept(false);
 134 
 135 } } } }
 136 
 137 #include "processing_rules_impl.hpp"
 138 
 139 #endif

/* [<][>][^][v][top][bottom][index][help] */