ORE Studio 0.0.4
Loading...
Searching...
No Matches
instrument.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TRADING_DOMAIN_INSTRUMENT_HPP
21#define ORES_TRADING_DOMAIN_INSTRUMENT_HPP
22
23#include <concepts>
24#include <vector>
25#include <variant>
26#include <boost/uuid/uuid.hpp>
27#include "ores.trading.api/domain/rates_instrument_variant.hpp"
28#include "ores.trading.api/domain/swap_leg.hpp"
29#include "ores.trading.api/domain/composite_instrument.hpp"
30#include "ores.trading.api/domain/composite_leg.hpp"
31
32namespace ores::trading::domain {
33
34template<typename T>
35concept Instrument = requires(T t) {
36 { t.instrument_id } -> std::convertible_to<boost::uuids::uuid>;
37 { t.trade_id } -> std::convertible_to<std::optional<boost::uuids::uuid>>;
38};
39
40template<typename T, typename Leg>
41struct with_legs {
42 T instrument;
43 std::vector<Leg> legs;
44};
45
46using swap_instrument_data = with_legs<rates_instrument_variant, swap_leg>;
47using composite_instrument_data = with_legs<composite_instrument, composite_leg>;
48
49template<Instrument T>
50void stamp_ids(T& instr,
51 boost::uuids::uuid instrument_id,
52 boost::uuids::uuid trade_id) {
53 instr.instrument_id = instrument_id;
54 instr.trade_id = trade_id;
55}
56
57template<typename... Ts>
58 requires (Instrument<Ts> && ...)
59void stamp_ids(std::variant<Ts...>& v,
60 boost::uuids::uuid instrument_id,
61 boost::uuids::uuid trade_id) {
62 std::visit([&]<Instrument I>(I& instr) {
63 stamp_ids(instr, instrument_id, trade_id);
64 }, v);
65}
66
67template<typename T, typename Leg>
68void stamp_ids(with_legs<T, Leg>& data,
69 boost::uuids::uuid instrument_id,
70 boost::uuids::uuid trade_id) {
71 stamp_ids(data.instrument, instrument_id, trade_id);
72 for (auto& leg : data.legs)
73 leg.instrument_id = instrument_id;
74}
75
76} // namespace ores::trading::domain
77
78#endif