Skip to content

FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.

1.4 KB
Raw Blame
#pragma once
#include "screens/dashboard/widgets/BaseWidget.h"
#include "services/markets/MarketDataService.h"

#include <QHash>
#include <QLabel>

namespace fincept::screens::widgets {

/// Performance tracker widget — fetches a basket of symbols (SPY, QQQ, DIA, IWM, etc.)
/// and computes real YTD/daily performance metrics from yfinance data.
///
/// Subscribes to `market:quote:<sym>` on the DataHub for the benchmark
/// basket and re-derives the metrics from cached rows on every delivery.
class PerformanceWidget : public BaseWidget {
    Q_OBJECT
  public:
    explicit PerformanceWidget(QWidget* parent = nullptr);

  protected:
    void on_theme_changed() override;
    void showEvent(QShowEvent* e) override;
    void hideEvent(QHideEvent* e) override;
    void retranslateUi() override;

  private:
    void apply_styles();
    void refresh_data();
    void populate(const QVector<services::QuoteData>& quotes);

    void hub_subscribe_all();
    void hub_unsubscribe_all();
    void rebuild_from_cache();

    struct MetricRow {
        QLabel* label = nullptr;
        QLabel* value = nullptr;
        QLabel* period = nullptr;
    };
    QWidget* rows_host_ = nullptr; // owns the rows + the one stylesheet styling them
    QVector<MetricRow> rows_;

    QHash<QString, services::QuoteData> row_cache_;
    bool hub_active_ = false;
};

} // namespace fincept::screens::widgets