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.

3.0 KB
Raw Blame
#pragma once
// OISubTab — F&O OI Analytics content widget. Replaces the placeholder in
// FnoScreen for SubTab::OI.
//
// Layout (2 × 2 splitter)
// ───────────────────────
//   ┌────────────────────────┬──────────────────────────────┐
//   │ MultiStrikeOIChart     │  MaxPainChart                │
//   ├────────────────────────┼──────────────────────────────┤
//   │ OIBuildupTable         │  [Strike ▾] IntradayOIChart  │
//   └────────────────────────┴──────────────────────────────┘
//
// Subscribes to `option:chain:*` (pattern) — pushes the latest publish into
// the three chain-derived widgets and re-seeds the IntradayOIChart's strike
// combo if the underlying changed. Visibility-driven sub/unsub per D3/D4.

#include "screens/common/IStatefulScreen.h"
#include "services/options/OptionChainTypes.h"

#include <QEvent>
#include <QPointer>
#include <QString>
#include <QVariantMap>
#include <QWidget>

class QComboBox;
class QLabel;

namespace fincept::screens::fno {

class IntradayOIChart;
class MaxPainChart;
class MultiStrikeOIChart;
class OIBuildupTable;

class OISubTab : public QWidget {
    Q_OBJECT
  public:
    explicit OISubTab(QWidget* parent = nullptr);
    ~OISubTab() override;

    QVariantMap save_state() const;
    void restore_state(const QVariantMap& state);

  protected:
    void showEvent(QShowEvent* e) override;
    void hideEvent(QHideEvent* e) override;
    void changeEvent(QEvent* event) override;

  private slots:
    void on_strike_combo_changed(int index);

  private:
    void setup_ui();
    void retranslateUi();
    void on_chain_published(const QString& topic, const QVariant& v);
    void rebuild_strike_combo(const fincept::services::options::OptionChain& chain);
    void apply_strike_subscription();

    MultiStrikeOIChart* oi_bars_ = nullptr;
    MaxPainChart* pain_chart_ = nullptr;
    OIBuildupTable* buildup_ = nullptr;
    IntradayOIChart* intraday_ = nullptr;
    QComboBox* strike_combo_ = nullptr;
    QLabel* picker_lbl_ = nullptr;

    fincept::services::options::OptionChain last_chain_;
    QString current_underlying_;
    /// Expiry the strike combo was last built for. A new expiry has a different
    /// strike ladder, so the combo must be rebuilt even when the underlying is
    /// unchanged.
    QString current_expiry_;
    /// Strike the user picked (0 = none). Carried across combo rebuilds and
    /// session restore. Selection is keyed on the strike VALUE, never on a row
    /// index — the ladder shifts as the ATM moves.
    double selected_strike_ = 0.0;
    bool subscribed_ = false;
};

} // namespace fincept::screens::fno