ORE Studio 0.0.4
Loading...
Searching...
No Matches
SwapInstrumentForm.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_QT_SWAP_INSTRUMENT_FORM_HPP
21#define ORES_QT_SWAP_INSTRUMENT_FORM_HPP
22
23#include <chrono>
24#include <optional>
25#include <string>
26#include <vector>
27#include <boost/uuid/uuid.hpp>
28#include "ores.qt/IInstrumentForm.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.trading.api/domain/swap_leg.hpp"
31
32namespace Ui {
33class SwapInstrumentForm;
34}
35
36namespace ores::qt {
37
46class SwapInstrumentForm final : public IInstrumentForm {
47 Q_OBJECT
48
49private:
50 inline static std::string_view logger_name = "ores.qt.swap_instrument_form";
51
52 [[nodiscard]] static auto& lg() {
53 using namespace ores::logging;
54 static auto instance = make_logger(logger_name);
55 return instance;
56 }
57
58public:
70 // Identity
71 boost::uuids::uuid instrument_id;
72 std::optional<boost::uuids::uuid> trade_id;
73 // Set by setTradeType(); not carried by any domain object.
74 std::string trade_type_code;
75
76 // Common to most types
77 std::string start_date;
78 std::string maturity_date; // FRA: maps from/to end_date
79 std::string description;
80
81 // FRA-specific
82 std::string currency;
83 double notional = 0.0;
84 std::string rate_index;
85 double strike = 0.0;
86 std::string long_short;
87
88 // BalanceGuaranteedSwap-specific
89 std::optional<int> lockout_days;
90
91 // Callable swap-specific
92 std::string call_dates_json;
93 std::string call_type;
94
95 // RPA-specific
96 std::string reference_counterparty;
97 double participation_rate = 0.0;
98 std::optional<double> protection_fee;
99
100 // Inflation swap-specific
101 std::string inflation_index_code;
102 std::optional<double> base_cpi;
103 std::string lag_convention;
104
105 // Provenance
106 int version = 0;
107 std::string modified_by;
108 std::string performed_by;
109 std::chrono::system_clock::time_point recorded_at;
110 std::string change_reason_code;
111 std::string change_commentary;
112 };
113
114 explicit SwapInstrumentForm(QWidget* parent = nullptr);
115 ~SwapInstrumentForm() override;
116
117 void setClientManager(ClientManager* cm) override;
118 void setUsername(const std::string& username) override;
119 void setImageCache(ImageCache* cache) override;
120
121 void setInstrument(
122 const trading::domain::trade_instrument& instrument) override;
123 void clear() override;
124
125 void setTradeType(const QString& code,
126 bool has_options, bool has_extension) override;
127
128 void setReadOnly(bool readOnly) override;
129 bool isDirty() const override;
130 bool isLoaded() const override;
131
132 void setChangeReason(
133 const std::string& code, const std::string& commentary) override;
134 void writeUiToInstrument() override;
135
136 void saveInstrument(
137 std::function<void(const std::string& id)> on_success,
138 std::function<void(const QString& error)> on_failure) override;
139
140private:
141 void setupConnections();
142 void populateCurrencies();
143 void populateFromState();
144 void emitProvenance();
145 void onFieldChanged();
146
147 Ui::SwapInstrumentForm* ui_;
148 ClientManager* clientManager_ = nullptr;
149 ImageCache* imageCache_ = nullptr;
150 std::string username_;
151 SwapFormState state_;
152 std::vector<trading::domain::swap_leg> legs_;
153 bool dirty_ = false;
154 bool loaded_ = false;
155};
156
157}
158
159#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:54
Pure-virtual interface implemented by every per-family instrument form widget hosted in TradeDetailDi...
Definition IInstrumentForm.hpp:73
IInstrumentForm subclass owning the swap / rates instrument editor.
Definition SwapInstrumentForm.hpp:46
void saveInstrument(std::function< void(const std::string &id)> on_success, std::function< void(const QString &error)> on_failure) override
Save the in-flight instrument via the family's NATS request.
Definition SwapInstrumentForm.cpp:554
bool isLoaded() const override
True after the asynchronous load has populated the form.
Definition SwapInstrumentForm.cpp:433
void setInstrument(const trading::domain::trade_instrument &instrument) override
Populate the form with the already-resolved instrument.
Definition SwapInstrumentForm.cpp:472
void writeUiToInstrument() override
Pull the current UI values into the in-flight domain object.
Definition SwapInstrumentForm.cpp:441
void setImageCache(ImageCache *cache) override
Inject the image cache for flag icons on currency combo boxes.
Definition SwapInstrumentForm.cpp:361
void setUsername(const std::string &username) override
Inject the username stamped on every saved instrument.
Definition SwapInstrumentForm.cpp:395
void setTradeType(const QString &code, bool has_options, bool has_extension) override
Inform the form which trade type is currently selected.
Definition SwapInstrumentForm.cpp:409
void setChangeReason(const std::string &code, const std::string &commentary) override
Stamp the change reason on the in-flight instrument before the dialog calls saveInstrument.
Definition SwapInstrumentForm.cpp:435
void setReadOnly(bool readOnly) override
Toggle read-only on every editable widget.
Definition SwapInstrumentForm.cpp:416
void setClientManager(ClientManager *cm) override
Inject the NATS client used for load and save round-trips.
Definition SwapInstrumentForm.cpp:356
bool isDirty() const override
Has the user edited any field since the last load or save?
Definition SwapInstrumentForm.cpp:432
void clear() override
Reset the form to a blank state ready for create mode.
Definition SwapInstrumentForm.cpp:399
Form-local state for the swap instrument editor.
Definition SwapInstrumentForm.hpp:69