ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientTradeModel.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_CLIENT_TRADE_MODEL_HPP
21#define ORES_QT_CLIENT_TRADE_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/AbstractClientModel.hpp"
27#include "ores.qt/ClientManager.hpp"
28#include "ores.qt/RecencyPulseManager.hpp"
29#include "ores.qt/RecencyTracker.hpp"
30#include "ores.logging/make_logger.hpp"
31#include "ores.trading.api/domain/trade.hpp"
32#include "ores.trading.api/messaging/trade_protocol.hpp"
33
34namespace ores::qt {
35
43 Q_OBJECT
44
45private:
46 inline static std::string_view logger_name =
47 "ores.qt.client_trade_model";
48
49 [[nodiscard]] static auto& lg() {
50 using namespace ores::logging;
51 static auto instance = make_logger(logger_name);
52 return instance;
53 }
54
55public:
59 enum Column {
60 ExternalId,
61 TradeType,
62 LifecycleEvent,
63 TradeDate,
64 EffectiveDate,
65 TerminationDate,
66 NettingSetId,
67 Version,
68 ModifiedBy,
69 RecordedAt,
70 ColumnCount
71 };
72
73 explicit ClientTradeModel(ClientManager* clientManager,
74 QObject* parent = nullptr);
75 ~ClientTradeModel() override = default;
76
77 // QAbstractTableModel interface
78 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
79 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
80 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
81 QVariant headerData(int section, Qt::Orientation orientation,
82 int role = Qt::DisplayRole) const override;
83
87 void refresh();
88
95 const trading::domain::trade* getTrade(int row) const;
96
100 void load_page(std::uint32_t offset, std::uint32_t limit);
101
105 std::uint32_t page_size() const { return page_size_; }
106
110 void set_page_size(std::uint32_t size);
111
115 std::uint32_t total_available_count() const { return total_available_count_; }
116
117signals:
126private slots:
127 void onTradesLoaded();
128 void onPulseStateChanged(bool isOn);
129 void onPulsingComplete();
130
131private:
132 QVariant recency_foreground_color(const std::string& code) const;
133
134 struct FetchResult {
135 bool success;
136 std::vector<trading::domain::trade> trades;
137 std::uint32_t total_available_count;
138 QString error_message;
139 QString error_details;
140 };
141
142 void fetch_trades(std::uint32_t offset, std::uint32_t limit);
143
144 ClientManager* clientManager_;
145 std::vector<trading::domain::trade> items_;
146 QFutureWatcher<FetchResult>* watcher_;
147 std::uint32_t page_size_{100};
148 std::uint32_t total_available_count_{0};
149 bool is_fetching_{false};
150
151 using TradeKeyExtractor =
152 std::string(*)(const trading::domain::trade&);
153 using TradeTimestampExtractor = std::chrono::system_clock::time_point(*)(
155 RecencyTracker<trading::domain::trade,
156 TradeKeyExtractor,
157 TradeTimestampExtractor> recencyTracker_;
158 RecencyPulseManager* pulseManager_;
159};
160
161}
162
163#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:37
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123
Model for displaying trades fetched from the server.
Definition ClientTradeModel.hpp:42
const trading::domain::trade * getTrade(int row) const
Get trade at the specified row.
Definition ClientTradeModel.cpp:285
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientTradeModel.cpp:273
void refresh()
Refresh trade data from server asynchronously.
Definition ClientTradeModel.cpp:147
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientTradeModel.hpp:115
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientTradeModel.cpp:173
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientTradeModel.hpp:105
Column
Enumeration of table columns for type-safe column access.
Definition ClientTradeModel.hpp:59
Trade capturing FpML Trade Header properties.
Definition trade.hpp:39