libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
smart_order_router.hpp
Go to the documentation of this file.
1 #ifndef LIBJMMCG_ISIMUD_EXCHANGES_LINKS_SMART_ORDER_ROUTER_HPP
2 #define LIBJMMCG_ISIMUD_EXCHANGES_LINKS_SMART_ORDER_ROUTER_HPP
3 
4 /******************************************************************************
5 ** Copyright © 2020 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 "common/isin.hpp"
23 
24 #include <map>
25 
26 namespace isimud { namespace ISIMUD_VER_NAMESPACE {
27 
28  /// An idea for implementing a very simple smart order router.
30  public:
32  using price_t=int; ///< Probably needs to be a variant over the various price_types of the links if there is no common_type.
33  using volume_t=int; ///< Probably needs to be a variant over the various volume_types of the links if there is no common_type.
34 
35  bool operator<(available_to_trade const &) const noexcept(true);
36  };
37  using link_t=int; ///< Base class of all the links.
38  using link_ptr_t=link_t*;
39  /**
40  A collection that contains the ISINs that are tradeable on multiple exchanges ordered by ISIN->{price, volume}->link. So that as market data comes in the prices & available volumes are updated.
41 
42  May want to use a sorted vector instead....
43  */
45  exchanges::ISIN_t, ///< These are only ISINs that are traded on multiple venues.
46  /**
47  * May want to use a std::heap instead, as only need the best available, not all in order.
48  */
49  std::map<
52  >
53  >;
54 
55  /// The market-data thread receives updates for the subscribed ISINs and calls this function to update the internal container.
56  /**
57  * Re-insert the ISIN into the map with the updated details.
58  */
59  void market_data_update(ISIN_t const &, available_to_trade::price_t const &, available_to_trade::volume_t const &);
60 
61  /// Call to place an order via the SOR.
62  /**
63  * Places the trade on the venue that has the best price & most volume. Could split the trade between venues.
64  */
65  void place_an_order(...) noexcept(false);
66 
67  private:
68  /**
69  TODO We'll need some kind of funky locking for this, probably multi-level....
70  */
71  container_type multi_venue_instruments;
72  };
73 
74 } }
75 
76 #endif