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.

general updates and bug fixes

tilakpatel229b860f357749
diff --git a/.github/workflows/build-cpp.yml b/.github/workflows/build-cpp.yml
index 0ae77ae76..693a3802b 100644
--- a/.github/workflows/build-cpp.yml
+++ b/.github/workflows/build-cpp.yml
@@ -800,12 +800,61 @@ jobs:
export OUTPUT="FinceptTerminal-Linux-x86_64.AppImage"
export UPDATE_INFORMATION="gh-releases-zsync|Fincept-Corporation|FinceptTerminal|latest|FinceptTerminal-Linux-x86_64.AppImage.zsync"
+ # ── OpenSSL must be bundled as a MATCHED PAIR (#352) ───────────────
+ # The app only calls libcrypto APIs, so ld's --as-needed drops
+ # libssl.so.3 from DT_NEEDED and linuxdeploy (which walks DT_NEEDED)
+ # bundled libcrypto.so.3 alone. Qt then dlopen()s the HOST libssl.so.3,
+ # which needs OPENSSL_3.3.0 from the stale bundled libcrypto 3.0.2:
+ # qt.tlsbackend.ossl: Failed to load libssl/libcrypto → all HTTPS dies.
+ # Keep this in sync with the same block in release.yml.
+ resolve_soname() {
+ local soname="$1" path
+ path=$(ldconfig -p | awk -v s="${soname}" '$1 == s && /x86-64/ { print $NF; exit }')
+ if [ -z "${path}" ] || [ "$(basename "${path}")" != "${soname}" ]; then
+ path="/usr/lib/x86_64-linux-gnu/${soname}"
+ fi
+ if [ ! -e "${path}" ]; then
+ echo "::error::${soname} not found on the runner — cannot bundle a consistent OpenSSL pair (#352)" >&2
+ exit 1
+ fi
+ printf '%s' "${path}"
+ }
+ OPENSSL_ARGS=()
+ for _so in libssl.so.3 libcrypto.so.3; do
+ _path=$(resolve_soname "${_so}")
+ echo "Bundling OpenSSL library: ${_path}"
+ OPENSSL_ARGS+=(--library "${_path}")
+ done
+
./linuxdeploy-x86_64.AppImage \
--appdir AppDir \
--plugin qt \
--output appimage \
+ "${OPENSSL_ARGS[@]}" \
2>&1 || true
+ # ── Guard: never ship a half-bundled OpenSSL again (#352) ──────────
+ SSL_BUNDLED=$(find AppDir -name 'libssl.so.3' -print -quit)
+ CRYPTO_BUNDLED=$(find AppDir -name 'libcrypto.so.3' -print -quit)
+ if [ -z "${SSL_BUNDLED}" ] || [ -z "${CRYPTO_BUNDLED}" ]; then
+ echo "::error::AppImage must bundle libssl.so.3 AND libcrypto.so.3 (ssl='${SSL_BUNDLED}' crypto='${CRYPTO_BUNDLED}') — a bundled libcrypto next to the host libssl breaks all TLS (#352)"
+ exit 1
+ fi
+ if LD_LIBRARY_PATH="$(dirname "${SSL_BUNDLED}")" ldd "${SSL_BUNDLED}" \
+ | grep -q 'libcrypto\.so\.3 => not found'; then
+ echo "::error::Bundled libssl.so.3 cannot resolve the bundled libcrypto.so.3"
+ LD_LIBRARY_PATH="$(dirname "${SSL_BUNDLED}")" ldd "${SSL_BUNDLED}" || true
+ exit 1
+ fi
+ echo "OpenSSL pair OK: ${SSL_BUNDLED} + ${CRYPTO_BUNDLED}"
+
+ TLS_PLUGIN=$(find AppDir -name 'libqopensslbackend.so' -print -quit)
+ if [ -z "${TLS_PLUGIN}" ]; then
+ echo "::error::Qt TLS backend plugin (libqopensslbackend.so) missing from AppDir — HTTPS would fail at runtime"
+ exit 1
+ fi
+ echo "Qt TLS plugin OK: ${TLS_PLUGIN}"
+
# Verify AppImage was created
if [ ! -f "$OUTPUT" ]; then
# Fallback: find any AppImage produced
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 6829846fe..785cf20d8 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -847,14 +847,71 @@ jobs:
export OUTPUT="FinceptTerminal-${VERSION}-linux-x64-setup.run"
export UPDATE_INFORMATION="gh-releases-zsync|Fincept-Corporation|FinceptTerminal|latest|FinceptTerminal-*-linux-x64-setup.run.zsync"
+ # ── OpenSSL must be bundled as a MATCHED PAIR (#352) ───────────────
+ # The app only calls libcrypto APIs (storage/secure/SecureStorage.cpp,
+ # trading/exchanges/hyperliquid/HyperliquidSigner.cpp), so ld's default
+ # --as-needed drops libssl.so.3 from DT_NEEDED even though CMake links
+ # OpenSSL::SSL. linuxdeploy walks DT_NEEDED, so it bundled libcrypto.so.3
+ # ALONE. Qt's TLS backend dlopen()s libssl.so.3 at runtime and picks the
+ # HOST copy (3.3+ on Arch/NixOS/Fedora), which needs OPENSSL_3.3.0 from
+ # libcrypto but finds our stale bundled 3.0.2 first on LD_LIBRARY_PATH:
+ # qt.tlsbackend.ossl: Failed to load libssl/libcrypto
+ # → every HTTPS request fails and the setup wizard says "no network".
+ # Force-deploy both so the bundled pair is internally consistent.
+ resolve_soname() {
+ local soname="$1" path
+ path=$(ldconfig -p | awk -v s="${soname}" '$1 == s && /x86-64/ { print $NF; exit }')
+ # ldconfig prints the SONAME-named file; fall back to the multiarch
+ # path if the cache is stale or the name doesn't match exactly.
+ if [ -z "${path}" ] || [ "$(basename "${path}")" != "${soname}" ]; then
+ path="/usr/lib/x86_64-linux-gnu/${soname}"
+ fi
+ if [ ! -e "${path}" ]; then
+ echo "::error::${soname} not found on the runner — cannot bundle a consistent OpenSSL pair (#352)" >&2
+ exit 1
+ fi
+ printf '%s' "${path}"
+ }
+ OPENSSL_ARGS=()
+ for _so in libssl.so.3 libcrypto.so.3; do
+ _path=$(resolve_soname "${_so}")
+ echo "Bundling OpenSSL library: ${_path}"
+ OPENSSL_ARGS+=(--library "${_path}")
+ done
+
./linuxdeploy-x86_64.AppImage \
--appdir "${APPDIR}" \
--plugin qt \
--output appimage \
+ "${OPENSSL_ARGS[@]}" \
--desktop-file "${APPDIR}/usr/share/applications/fincept-terminal.desktop" \
--icon-file "${ICON_DEST}" \
2>&1
+ # ── Guard: never ship a half-bundled OpenSSL again (#352) ──────────
+ SSL_BUNDLED=$(find "${APPDIR}" -name 'libssl.so.3' -print -quit)
+ CRYPTO_BUNDLED=$(find "${APPDIR}" -name 'libcrypto.so.3' -print -quit)
+ if [ -z "${SSL_BUNDLED}" ] || [ -z "${CRYPTO_BUNDLED}" ]; then
+ echo "::error::AppImage must bundle libssl.so.3 AND libcrypto.so.3 (ssl='${SSL_BUNDLED}' crypto='${CRYPTO_BUNDLED}') — a bundled libcrypto next to the host libssl breaks all TLS (#352)"
+ exit 1
+ fi
+ if LD_LIBRARY_PATH="$(dirname "${SSL_BUNDLED}")" ldd "${SSL_BUNDLED}" \
+ | grep -q 'libcrypto\.so\.3 => not found'; then
+ echo "::error::Bundled libssl.so.3 cannot resolve the bundled libcrypto.so.3"
+ LD_LIBRARY_PATH="$(dirname "${SSL_BUNDLED}")" ldd "${SSL_BUNDLED}" || true
+ exit 1
+ fi
+ echo "OpenSSL pair OK: ${SSL_BUNDLED} + ${CRYPTO_BUNDLED}"
+
+ # Qt's TLS backend plugin is dlopen()ed too — if the qt plugin didn't
+ # deploy it, HTTPS fails with the same "no network" symptom.
+ TLS_PLUGIN=$(find "${APPDIR}" -name 'libqopensslbackend.so' -print -quit)
+ if [ -z "${TLS_PLUGIN}" ]; then
+ echo "::error::Qt TLS backend plugin (libqopensslbackend.so) missing from AppDir — HTTPS would fail at runtime"
+ exit 1
+ fi
+ echo "Qt TLS plugin OK: ${TLS_PLUGIN}"
+
# linuxdeploy names the output after the desktop entry — find it.
if [ ! -f "${OUTPUT}" ]; then
PRODUCED=$(find . -maxdepth 1 -name "*.AppImage" | head -1)
@@ -2328,6 +2385,13 @@ jobs:
MAC_URL=$(gh release view "${TAG}" --json assets \
--jq '.assets[] | select(.name | test("\\.dmg$|macos.*setup")) | .url' \
| head -1)
+ # Native Linux packages — Fedora/RHEL users have no apt (#192).
+ DEB_URL=$(gh release view "${TAG}" --json assets \
+ --jq '.assets[] | select(.name | test("\\.deb$")) | .url' \
+ | head -1)
+ RPM_URL=$(gh release view "${TAG}" --json assets \
+ --jq '.assets[] | select(.name | test("\\.rpm$")) | .url' \
+ | head -1)
# Fallback: if browser_download_url not available via .url, try .browserDownloadUrl
[ -z "$WIN_URL" ] && WIN_URL=$(gh release view "${TAG}" --json assets \
@@ -2339,22 +2403,34 @@ jobs:
[ -z "$MAC_URL" ] && MAC_URL=$(gh release view "${TAG}" --json assets \
--jq '.assets[] | select(.name | test("\\.dmg$|macos.*setup")) | .browserDownloadUrl' \
| head -1) || true
+ [ -z "$DEB_URL" ] && DEB_URL=$(gh release view "${TAG}" --json assets \
+ --jq '.assets[] | select(.name | test("\\.deb$")) | .browserDownloadUrl' \
+ | head -1) || true
+ [ -z "$RPM_URL" ] && RPM_URL=$(gh release view "${TAG}" --json assets \
+ --jq '.assets[] | select(.name | test("\\.rpm$")) | .browserDownloadUrl' \
+ | head -1) || true
# Release page URL as final fallback
RELEASE_URL="https://github.com/Fincept-Corporation/FinceptTerminal/releases/tag/${TAG}"
WIN_URL="${WIN_URL:-${RELEASE_URL}}"
LIN_URL="${LIN_URL:-${RELEASE_URL}}"
MAC_URL="${MAC_URL:-${RELEASE_URL}}"
+ DEB_URL="${DEB_URL:-${RELEASE_URL}}"
+ RPM_URL="${RPM_URL:-${RELEASE_URL}}"
echo "WIN_URL=${WIN_URL}" >> "$GITHUB_ENV"
echo "LIN_URL=${LIN_URL}" >> "$GITHUB_ENV"
echo "MAC_URL=${MAC_URL}" >> "$GITHUB_ENV"
+ echo "DEB_URL=${DEB_URL}" >> "$GITHUB_ENV"
+ echo "RPM_URL=${RPM_URL}" >> "$GITHUB_ENV"
echo "RELEASE_URL=${RELEASE_URL}" >> "$GITHUB_ENV"
echo "TAG=${TAG}" >> "$GITHUB_ENV"
echo "Windows : ${WIN_URL}"
echo "Linux : ${LIN_URL}"
echo "macOS : ${MAC_URL}"
+ echo "Linux deb: ${DEB_URL}"
+ echo "Linux rpm: ${RPM_URL}"
# ── Rewrite README download table ─────────────────────────────────────
# Strategy: replace a clearly-delimited block between two sentinel
@@ -2376,7 +2452,9 @@ jobs:
| Platform | Download | Run |
|----------|----------|-----|
| **Windows x64** | [FinceptTerminal-Windows-x64-setup.exe](${WIN_URL}) | Run installer → launch \`FinceptTerminal.exe\` |
- | **Linux x64** | [FinceptTerminal-Linux-x64.run](${LIN_URL}) | \`chmod +x\` → run installer |
+ | **Linux x64 (AppImage)** | [FinceptTerminal-Linux-x64.run](${LIN_URL}) | \`chmod +x\` → run installer |
+ | **Linux x64 (Debian/Ubuntu)** | [FinceptTerminal-Linux-x64.deb](${DEB_URL}) | \`sudo apt install ./FinceptTerminal-*.deb\` |
+ | **Linux x64 (Fedora/RHEL)** | [FinceptTerminal-Linux-x64.rpm](${RPM_URL}) | \`sudo dnf install ./FinceptTerminal-*.rpm\` |
| **macOS Apple Silicon** | [FinceptTerminal-macOS-arm64.dmg](${MAC_URL}) | Open DMG → drag to Applications |
${END_MARKER}"
diff --git a/README.md b/README.md
index 92611f634..822f9ff05 100644
--- a/README.md
+++ b/README.md
@@ -74,7 +74,9 @@ Latest release: **v4.2.0** — [View all releases](https://github.com/Fincept-Co
| Platform | Download | Run |
|----------|----------|-----|
| **Windows x64** | [FinceptTerminal-Windows-x64-setup.exe](https://github.com/Fincept-Corporation/FinceptTerminal/releases/download/v4.2.0/FinceptTerminal-4.2.0-windows-x64-setup.exe) | Run installer → launch `FinceptTerminal.exe` |
-| **Linux x64** | [FinceptTerminal-Linux-x64.run](https://github.com/Fincept-Corporation/FinceptTerminal/releases/download/v4.2.0/FinceptTerminal-4.2.0-linux-x64-setup.run) | `chmod +x` → run installer |
+| **Linux x64 (AppImage)** | [FinceptTerminal-Linux-x64.run](https://github.com/Fincept-Corporation/FinceptTerminal/releases/download/v4.2.0/FinceptTerminal-4.2.0-linux-x64-setup.run) | `chmod +x` → run installer |
+| **Linux x64 (Debian/Ubuntu)** | [FinceptTerminal-Linux-x64.deb](https://github.com/Fincept-Corporation/FinceptTerminal/releases/download/v4.2.0/FinceptTerminal-4.2.0-linux-x64.deb) | `sudo apt install ./FinceptTerminal-4.2.0-linux-x64.deb` |
+| **Linux x64 (Fedora/RHEL)** | [FinceptTerminal-Linux-x64.rpm](https://github.com/Fincept-Corporation/FinceptTerminal/releases/download/v4.2.0/FinceptTerminal-4.2.0-linux-x64.rpm) | `sudo dnf install ./FinceptTerminal-4.2.0-linux-x64.rpm` |
| **macOS Apple Silicon** | [FinceptTerminal-macOS-arm64.dmg](https://github.com/Fincept-Corporation/FinceptTerminal/releases/download/v4.2.0/FinceptTerminal-4.2.0-macos-arm64-setup.dmg) | Open DMG → drag to Applications |
<!-- DOWNLOAD-TABLE-END -->
diff --git a/fincept-qt/CMakeLists.txt b/fincept-qt/CMakeLists.txt
index c1915c668..f2ecb38b0 100644
--- a/fincept-qt/CMakeLists.txt
+++ b/fincept-qt/CMakeLists.txt
@@ -1479,6 +1479,7 @@ set(UI_SOURCES
src/ui/charts/SeriesLayer.cpp
src/ui/charts/HorizontalLineLayer.cpp
src/ui/charts/ChartOverlayManager.cpp
+ src/ui/charts/TimeAxisNavigator.cpp
src/ui/charts/IndicatorPicker.cpp
src/ui/charts/IndicatorParamDialog.cpp
src/ui/charts/layers/EmaLayer.cpp
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoChart.cpp b/fincept-qt/src/screens/crypto_trading/CryptoChart.cpp
index dcc977260..0c0f496bb 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoChart.cpp
+++ b/fincept-qt/src/screens/crypto_trading/CryptoChart.cpp
@@ -18,7 +18,8 @@
// • Time-axis label format auto-scales with the timeframe
// (HH:mm · MMM dd HH:mm · MMM dd · MMM yy)
// • Generous bottom margin so the time-axis labels stop being clipped
-// • Mouse wheel = zoom price axis; drag = pan
+// • Mouse wheel = zoom time (Ctrl+wheel = price), left-drag = pan,
+// double-click = back to auto-follow (see TimeAxisNavigator)
//
// Sizing principles:
// • No pixel-pinned heights on the header buttons — uses QSS padding so
@@ -117,6 +118,19 @@ QFont scene_font() {
return f;
}
+// Pixel clamps for the candle body. Qt derives the body width from the candle
+// time period in DOMAIN units (qtcharts candlestick.cpp: `columnWidth =
+// m_timePeriod`), so a chart holding only a handful of candles stretches every
+// body across the plot — the giant blocks in issue #338. The maximum keeps a
+// 3-candle chart looking like candles; the minimum stops a 120-candle chart
+// from collapsing into hairlines.
+constexpr qreal kMaxCandlePx = 18.0;
+constexpr qreal kMinCandlePx = 2.0;
+
+// One wheel notch.
+constexpr double kZoomInFactor = 0.85;
+constexpr double kZoomOutFactor = 1.0 / kZoomInFactor;
+
} // namespace
// ── HoverChartView ──────────────────────────────────────────────────────────
@@ -136,35 +150,72 @@ class HoverChartView : public QChartView {
protected:
void mouseMoveEvent(QMouseEvent* e) override {
- if (host_ && chart()) {
+ if (dragging_ && host_) {
+ const int dx = e->pos().x() - drag_pos_.x();
+ drag_pos_ = e->pos();
+ host_->pan_time_pixels(dx);
+ } else if (host_ && chart()) {
const QPointF chart_pos = chart()->mapToValue(e->pos());
host_->on_hover_position(chart_pos, e->pos());
}
QChartView::mouseMoveEvent(e);
}
+ void mousePressEvent(QMouseEvent* e) override {
+ if (e->button() == Qt::LeftButton) {
+ dragging_ = true;
+ drag_pos_ = e->pos();
+ setCursor(Qt::ClosedHandCursor);
+ if (host_)
+ host_->on_hover_leave(); // crosshair off while dragging
+ }
+ QChartView::mousePressEvent(e);
+ }
+ void mouseReleaseEvent(QMouseEvent* e) override {
+ if (e->button() == Qt::LeftButton && dragging_) {
+ dragging_ = false;
+ unsetCursor();
+ }
+ QChartView::mouseReleaseEvent(e);
+ }
+ void mouseDoubleClickEvent(QMouseEvent* e) override {
+ // Back to auto-follow — the live candle stream drives the axis again.
+ if (host_)
+ host_->reset_view();
+ e->accept();
+ }
void leaveEvent(QEvent* e) override {
if (host_)
host_->on_hover_leave();
QChartView::leaveEvent(e);
}
void wheelEvent(QWheelEvent* e) override {
- if (!chart()) {
+ if (!chart() || !host_) {
QChartView::wheelEvent(e);
return;
}
- // Zoom price axis only. Wheel-panning the time axis collides with the
- // candle stream — users expect Time fixed and Price scaled.
- const double factor = (e->angleDelta().y() > 0) ? 0.9 : 1.1;
- if (auto* y = qobject_cast<QValueAxis*>(host_ ? host_->price_axis_ : nullptr)) {
- const double mid = (y->min() + y->max()) / 2.0;
- const double span = (y->max() - y->min()) * factor;
- y->setRange(mid - span / 2.0, mid + span / 2.0);
+ const bool zoom_in = e->angleDelta().y() > 0;
+ const double factor = zoom_in ? kZoomInFactor : kZoomOutFactor;
+
+ // Ctrl+wheel keeps the old behaviour (scale the price axis); a plain
+ // wheel now zooms time, which is what the candle chart needs to be
+ // scrollable at all (#338).
+ if (e->modifiers().testFlag(Qt::ControlModifier)) {
+ if (auto* y = host_->price_axis_) {
+ const double mid = (y->min() + y->max()) / 2.0;
+ const double span = (y->max() - y->min()) * factor;
+ y->setRange(mid - span / 2.0, mid + span / 2.0);
+ }
+ } else {
+ const QPointF anchor = chart()->mapToValue(e->position());
+ host_->zoom_time(factor, static_cast<qint64>(anchor.x()));
}
e->accept();
}
private:
CryptoChart* host_ = nullptr;
+ bool dragging_ = false;
+ QPoint drag_pos_;
};
// ── CryptoChart ─────────────────────────────────────────────────────────────
@@ -223,6 +274,8 @@ CryptoChart::CryptoChart(QWidget* parent) : QWidget(parent) {
series_->setIncreasingColor(QColor(colors::POSITIVE()));
series_->setDecreasingColor(QColor(colors::NEGATIVE()));
series_->setBodyWidth(0.78);
+ series_->setMaximumColumnWidth(kMaxCandlePx);
+ series_->setMinimumColumnWidth(kMinCandlePx);
series_->setPen(QPen(Qt::NoPen)); // no outline on body
series_->setCapsVisible(false);
chart_->addSeries(series_);
@@ -380,6 +433,9 @@ QString CryptoChart::current_timeframe() const {
void CryptoChart::set_candles(const QVector<trading::Candle>& candles) {
candles_ = candles;
+ // A wholesale replacement means a new symbol/timeframe — a window the user
+ // panned over the previous series no longer maps to anything.
+ nav_.reset();
rebuild_chart();
overlay_mgr_->set_candles(fincept::ui::CandleData::from_candles(candles_));
apply_tf_axis_format();
@@ -480,6 +536,7 @@ void CryptoChart::recompute_bounds() {
void CryptoChart::clear() {
candles_.clear();
+ nav_.reset();
series_->clear();
if (last_price_line_)
last_price_line_->clear();
@@ -512,24 +569,87 @@ void CryptoChart::update_axes(double min_price, double max_price, qint64 min_tim
last_max_price_ = p_max;
}
+ const qint64 slot = tf_slot_ms(TF_LABELS[active_tf_]);
+ qint64 effective_min = min_time;
qint64 effective_max = max_time;
if (min_time >= max_time) {
- effective_max = min_time + tf_slot_ms(TF_LABELS[active_tf_]);
+ effective_max = min_time + slot;
} else {
// Add half-a-slot of right padding so the latest candle isn't pinned
// to the right edge of the plot — looks more like a real terminal.
- effective_max = max_time + tf_slot_ms(TF_LABELS[active_tf_]) / 2;
+ effective_max = max_time + slot / 2;
+ }
+
+ // Floor the window at MIN_VISIBLE_SLOTS. Without it a chart holding a
+ // handful of candles (history fetch empty, bars arriving live) fits the
+ // axis to ~3 minutes, and Qt then draws each body a third of the plot
+ // wide — the "broken candles" in #338. Anchoring left instead keeps the
+ // candles at the right edge at their normal width.
+ const qint64 min_span = MIN_VISIBLE_SLOTS * slot;
+ if (effective_max - effective_min < min_span)
+ effective_min = effective_max - min_span;
+
+ // The user's own pan/zoom wins over the auto-fit until they double-click.
+ nav_.set_extent(effective_min, effective_max, slot);
+ if (nav_.active()) {
+ effective_min = nav_.min();
+ effective_max = nav_.max();
+ } else {
+ nav_.seed(effective_min, effective_max);
}
- if (min_time != last_min_time_ || effective_max != last_max_time_) {
- time_axis_->setRange(QDateTime::fromMSecsSinceEpoch(min_time), QDateTime::fromMSecsSinceEpoch(effective_max));
- last_min_time_ = min_time;
+ if (effective_min != last_min_time_ || effective_max != last_max_time_) {
+ time_axis_->setRange(QDateTime::fromMSecsSinceEpoch(effective_min),
+ QDateTime::fromMSecsSinceEpoch(effective_max));
+ last_min_time_ = effective_min;
last_max_time_ = effective_max;
}
overlay_mgr_->reposition_all();
}
+void CryptoChart::apply_view_range() {
+ if (!time_axis_ || !nav_.active())
+ return;
+ const qint64 lo = nav_.min();
+ const qint64 hi = nav_.max();
+ if (hi <= lo)
+ return;
+ time_axis_->setRange(QDateTime::fromMSecsSinceEpoch(lo), QDateTime::fromMSecsSinceEpoch(hi));
+ last_min_time_ = lo;
+ last_max_time_ = hi;
+ apply_tf_axis_format();
+ update_last_price_marker();
+ overlay_mgr_->reposition_all();
+}
+
+void CryptoChart::zoom_time(double factor, qint64 anchor_ms) {
+ if (nav_.zoom(factor, anchor_ms))
+ apply_view_range();
+}
+
+void CryptoChart::pan_time_pixels(int dx) {
+ if (!chart_ || dx == 0)
+ return;
+ const qreal plot_w = chart_->plotArea().width();
+ const qint64 span = last_max_time_ - last_min_time_;
+ if (plot_w <= 1.0 || span <= 0)
+ return;
+ // Drag right → walk back in time.
+ const auto delta = static_cast<qint64>(-dx * (static_cast<double>(span) / plot_w));
+ if (nav_.pan(delta))
+ apply_view_range();
+}
+
+void CryptoChart::reset_view() {
+ if (!nav_.active())
+ return;
+ nav_.reset();
+ rebuild_chart(); // re-fits both axes to the candle set
+ apply_tf_axis_format();
+ update_last_price_marker();
+}
+
void CryptoChart::apply_tf_axis_format() {
if (!time_axis_)
return;
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoChart.h b/fincept-qt/src/screens/crypto_trading/CryptoChart.h
index afdbf9a9c..280ea232e 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoChart.h
+++ b/fincept-qt/src/screens/crypto_trading/CryptoChart.h
@@ -4,6 +4,7 @@
#include "trading/TradingTypes.h"
#include "ui/charts/ChartOverlayManager.h"
+#include "ui/charts/TimeAxisNavigator.h"
#include <QEvent>
#include <QPushButton>
@@ -58,6 +59,15 @@ class CryptoChart : public QWidget {
void on_hover_position(const QPointF& chart_value_pos, const QPoint& view_pos);
void on_hover_leave();
+ // ── User-driven time navigation (#338) ────────────────────────────────
+ // Wheel zooms around the cursor, left-drag pans, double-click returns to
+ // auto-follow. While the user window is active the live candle stream no
+ // longer re-fits the time axis.
+ void zoom_time(double factor, qint64 anchor_ms);
+ void pan_time_pixels(int dx);
+ void reset_view();
+ void apply_view_range();
+
HoverChartView* chart_view_ = nullptr;
QChart* chart_ = nullptr;
QCandlestickSeries* series_ = nullptr;
@@ -91,6 +101,12 @@ class CryptoChart : public QWidget {
QVector<trading::Candle> candles_;
static constexpr int MAX_VISIBLE = 120;
+ // Never fit the time axis tighter than this many slots. Qt sizes a candle
+ // body from the slot width in DOMAIN units, so a data-fitted axis holding
+ // 3 live candles inflates each body to a third of the plot (#338).
+ static constexpr int MIN_VISIBLE_SLOTS = 40;
+
+ fincept::ui::TimeAxisNavigator nav_;
// Axis range cache (padded values actually applied to the axis)
double last_min_price_ = -1;
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen.h b/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen.h
index f111e17e7..a578be192 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen.h
+++ b/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen.h
@@ -93,7 +93,9 @@ class CryptoTradingScreen : public QWidget, public IStatefulScreen, public IGrou
bool is_perp_market() const;
void update_futures_visibility();
- void async_fetch_candles(const QString& symbol, const QString& timeframe);
+ // `attempt` drives the retry backoff for an empty OHLCV response (#338) —
+ // callers always start at 0.
+ void async_fetch_candles(const QString& symbol, const QString& timeframe, int attempt = 0);
void async_fetch_live_positions();
void async_fetch_live_orders();
void async_fetch_live_balance();
@@ -150,6 +152,13 @@ class CryptoTradingScreen : public QWidget, public IStatefulScreen, public IGrou
QString portfolio_id_;
trading::PtPortfolio portfolio_;
+ // "<symbol>|<timeframe>" the chart currently holds history for. Lets an
+ // empty OHLCV response keep a good chart instead of wiping it, while still
+ // clearing content that belongs to a symbol the user has left (#338).
+ QString chart_symbol_;
+ static constexpr int CANDLE_FETCH_MAX_ATTEMPTS = 3;
+ static constexpr int CANDLE_FETCH_RETRY_MS = 2000;
+
// Async fetch guards
std::atomic<bool> candles_fetching_{false};
std::atomic<int> live_inflight_{0}; // counts async_fetch_live_* tasks still running
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_AsyncFetch.cpp b/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_AsyncFetch.cpp
index 18fb1bd05..2d2c67592 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_AsyncFetch.cpp
+++ b/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_AsyncFetch.cpp
@@ -31,6 +31,7 @@
#include <QSplitter>
#include <QStringListModel>
#include <QStyle>
+#include <QTimer>
#include <QVBoxLayout>
#include <QtConcurrent/QtConcurrent>
@@ -39,21 +40,64 @@ namespace fincept::screens {
using namespace fincept::trading;
using namespace fincept::screens::crypto;
-void CryptoTradingScreen::async_fetch_candles(const QString& symbol, const QString& timeframe) {
+void CryptoTradingScreen::async_fetch_candles(const QString& symbol, const QString& timeframe, int attempt) {
if (candles_fetching_.exchange(true))
return;
QPointer<CryptoTradingScreen> self = this;
- (void)QtConcurrent::run([self, symbol, timeframe]() {
+ (void)QtConcurrent::run([self, symbol, timeframe, attempt]() {
auto candles = ExchangeService::instance().fetch_ohlcv(symbol, timeframe, OHLCV_FETCH_COUNT);
if (!self)
return;
self->candles_fetching_ = false;
QMetaObject::invokeMethod(
self,
- [self, candles]() {
+ [self, candles, symbol, timeframe, attempt]() {
if (!self)
return;
- self->chart_->set_candles(candles);
+ // The user may have moved on while the REST call was in flight.
+ if (self->selected_symbol_ != symbol || self->chart_->current_timeframe() != timeframe)
+ return;
+
+ if (!candles.isEmpty()) {
+ self->chart_->set_candles(candles);
+ self->chart_symbol_ = symbol + QLatin1Char('|') + timeframe;
+ return;
+ }
+
+ // Empty result — the daemon errored, rate-limited, or the
+ // market has no history. Pushing it into the chart wipes the
+ // history and leaves the user watching WS bars trickle in one
+ // per minute, each drawn as a giant block (#338). Keep what we
+ // have, and only clear when the stale content belongs to a
+ // different symbol/timeframe.
+ const QString key = symbol + QLatin1Char('|') + timeframe;
+ if (self->chart_symbol_ != key) {
+ self->chart_->clear();
+ self->chart_symbol_.clear();
+ }
+ LOG_WARN("CryptoTrading", QString("fetch_ohlcv returned no candles for %1 %2 (attempt %3/%4)")
+ .arg(symbol, timeframe)
+ .arg(attempt + 1)
+ .arg(CANDLE_FETCH_MAX_ATTEMPTS));
+
+ if (attempt + 1 < CANDLE_FETCH_MAX_ATTEMPTS) {
+ // The first fetch races the daemon's exchange handshake on
+ // a cold start; back off and try again rather than leaving
+ // the chart permanently empty.
+ const int delay_ms = CANDLE_FETCH_RETRY_MS * (attempt + 1);
+ QTimer::singleShot(delay_ms, self, [self, symbol, timeframe, attempt]() {
+ if (!self || self->selected_symbol_ != symbol)
+ return;
+ if (self->chart_->current_timeframe() != timeframe)
+ return;
+ self->async_fetch_candles(symbol, timeframe, attempt + 1);
+ });
+ } else {
+ LOG_ERROR("CryptoTrading",
+ QString("no OHLCV history for %1 %2 after %3 attempts — chart is live-only")
+ .arg(symbol, timeframe)
+ .arg(CANDLE_FETCH_MAX_ATTEMPTS));
+ }
},
Qt::QueuedConnection);
});
diff --git a/fincept-qt/src/screens/equity_trading/EquityChart.cpp b/fincept-qt/src/screens/equity_trading/EquityChart.cpp
index 80a638dbf..1ab538038 100644
--- a/fincept-qt/src/screens/equity_trading/EquityChart.cpp
+++ b/fincept-qt/src/screens/equity_trading/EquityChart.cpp
@@ -103,6 +103,18 @@ QString time_format_for(qint64 span_ms) {
return QStringLiteral("MMM yy");
}
+// Pixel clamps for the candle body. Qt derives the body width from the candle
+// time period in DOMAIN units (qtcharts candlestick.cpp: `columnWidth =
+// m_timePeriod`), so a chart holding only a handful of candles stretches every
+// body across the plot (#338). The minimum keeps a full 120-bar chart from
+// collapsing into hairlines.
+constexpr qreal kMaxCandlePx = 18.0;
+constexpr qreal kMinCandlePx = 2.0;
+
+// One wheel notch.
+constexpr double kZoomInFactor = 0.85;
+constexpr double kZoomOutFactor = 1.0 / kZoomInFactor;
+
QFont scene_font() {
QFont f;
f.setFamily(QStringLiteral("Consolas"));
@@ -130,29 +142,61 @@ class HoverEquityChartView : public QChartView {
protected:
void mouseMoveEvent(QMouseEvent* e) override {
- if (host_ && chart()) {
+ if (dragging_ && host_) {
+ const int dx = e->pos().x() - drag_pos_.x();
+ drag_pos_ = e->pos();
+ host_->pan_time_pixels(dx);
+ } else if (host_ && chart()) {
const QPointF chart_pos = chart()->mapToValue(e->pos());
host_->on_hover_position(chart_pos, e->pos());
}
QChartView::mouseMoveEvent(e);
}
+ void mousePressEvent(QMouseEvent* e) override {
+ if (e->button() == Qt::LeftButton) {
+ dragging_ = true;
+ drag_pos_ = e->pos();
+ setCursor(Qt::ClosedHandCursor);
+ if (host_)
+ host_->on_hover_leave(); // crosshair off while dragging
+ }
+ QChartView::mousePressEvent(e);
+ }
+ void mouseReleaseEvent(QMouseEvent* e) override {
+ if (e->button() == Qt::LeftButton && dragging_) {
+ dragging_ = false;
+ unsetCursor();
+ }
+ QChartView::mouseReleaseEvent(e);
+ }
+ void mouseDoubleClickEvent(QMouseEvent* e) override {
+ if (host_)
+ host_->reset_view();
+ e->accept();
+ }
void leaveEvent(QEvent* e) override {
if (host_)
host_->on_hover_leave();
QChartView::leaveEvent(e);
}
void wheelEvent(QWheelEvent* e) override {
- if (!chart()) {
+ if (!chart() || !host_) {
QChartView::wheelEvent(e);
return;
}
- // Zoom price axis only. Wheel-panning the time axis collides with the
- // candle stream -- users expect Time fixed and Price scaled.
- const double factor = (e->angleDelta().y() > 0) ? 0.9 : 1.1;
- if (auto* y = qobject_cast<QValueAxis*>(host_ ? host_->price_axis_ : nullptr)) {
- const double mid = (y->min() + y->max()) / 2.0;
- const double span = (y->max() - y->min()) * factor;
- y->setRange(mid - span / 2.0, mid + span / 2.0);
+ const double factor = (e->angleDelta().y() > 0) ? kZoomInFactor : kZoomOutFactor;
+
+ // Ctrl+wheel keeps the old behaviour (scale the price axis); a plain
+ // wheel zooms time so the chart can be scrolled at all (#338).
+ if (e->modifiers().testFlag(Qt::ControlModifier)) {
+ if (auto* y = host_->price_axis_) {
+ const double mid = (y->min() + y->max()) / 2.0;
+ const double span = (y->max() - y->min()) * factor;
+ y->setRange(mid - span / 2.0, mid + span / 2.0);
+ }
+ } else {
+ const QPointF anchor = chart()->mapToValue(e->position());
+ host_->zoom_time(factor, static_cast<qint64>(anchor.x()));
}
e->accept();
}
@@ -168,6 +212,8 @@ class HoverEquityChartView : public QChartView {
private:
EquityChart* host_ = nullptr;
+ bool dragging_ = false;
+ QPoint drag_pos_;
};
// -- EquityChart -------------------------------------------------------------
@@ -223,6 +269,8 @@ EquityChart::EquityChart(QWidget* parent) : QWidget(parent) {
series_->setIncreasingColor(QColor(colors::POSITIVE()));
series_->setDecreasingColor(QColor(colors::NEGATIVE()));
series_->setBodyWidth(0.78);
+ series_->setMaximumColumnWidth(kMaxCandlePx);
+ series_->setMinimumColumnWidth(kMinCandlePx);
series_->setPen(QPen(Qt::NoPen)); // no outline on body
series_->setCapsVisible(false);
chart_->addSeries(series_);
@@ -379,6 +427,9 @@ QString EquityChart::current_timeframe() const {
void EquityChart::set_candles(const QVector<trading::BrokerCandle>& candles) {
candles_ = candles;
+ // A wholesale replacement means a new symbol/timeframe — a window the user
+ // panned over the previous series no longer maps to anything.
+ nav_.reset();
rebuild_chart();
// Overlay layers must use synthetic timestamps so their QLineSeries
@@ -462,6 +513,7 @@ void EquityChart::recompute_bounds() {
void EquityChart::clear() {
candles_.clear();
+ nav_.reset();
series_->clear();
if (last_price_line_)
last_price_line_->clear();
@@ -518,24 +570,87 @@ void EquityChart::update_axes(double min_price, double max_price, qint64 min_tim
last_max_price_ = p_max;
}
+ // Synthetic timestamps advance one `synth_slot_ms_` per candle; fall back
+ // to the timeframe's real slot before the first rebuild has run.
+ const qint64 slot = synth_slot_ms_ > 0 ? synth_slot_ms_ : tf_slot_ms(TF_LABELS[active_tf_]);
+ qint64 effective_min = min_time;
qint64 effective_max = max_time;
if (min_time >= max_time) {
- effective_max = min_time + tf_slot_ms(TF_LABELS[active_tf_]);
+ effective_max = min_time + slot;
} else {
// Add half-a-slot of right padding so the latest candle isn't pinned
// to the right edge of the plot -- looks more like a real terminal.
- effective_max = max_time + tf_slot_ms(TF_LABELS[active_tf_]) / 2;
+ effective_max = max_time + slot / 2;
+ }
+
+ // Floor the window at MIN_VISIBLE_SLOTS so a short series (a freshly
+ // opened symbol, a broker that returned two bars) renders as candles at
+ // the right edge instead of blocks spanning the plot (#338).
+ const qint64 min_span = MIN_VISIBLE_SLOTS * slot;
+ if (effective_max - effective_min < min_span)
+ effective_min = effective_max - min_span;
+
+ // The user's own pan/zoom wins over the auto-fit until they double-click.
+ nav_.set_extent(effective_min, effective_max, slot);
+ if (nav_.active()) {
+ effective_min = nav_.min();
+ effective_max = nav_.max();
+ } else {
+ nav_.seed(effective_min, effective_max);
}
- if (min_time != last_min_time_ || effective_max != last_max_time_) {
- time_axis_->setRange(QDateTime::fromMSecsSinceEpoch(min_time), QDateTime::fromMSecsSinceEpoch(effective_max));
- last_min_time_ = min_time;
+ if (effective_min != last_min_time_ || effective_max != last_max_time_) {
+ time_axis_->setRange(QDateTime::fromMSecsSinceEpoch(effective_min),
+ QDateTime::fromMSecsSinceEpoch(effective_max));
+ last_min_time_ = effective_min;
last_max_time_ = effective_max;
}
overlay_mgr_->reposition_all();
}
+void EquityChart::apply_view_range() {
+ if (!time_axis_ || !nav_.active())
+ return;
+ const qint64 lo = nav_.min();
+ const qint64 hi = nav_.max();
+ if (hi <= lo)
+ return;
+ time_axis_->setRange(QDateTime::fromMSecsSinceEpoch(lo), QDateTime::fromMSecsSinceEpoch(hi));
+ last_min_time_ = lo;
+ last_max_time_ = hi;
+ apply_tf_axis_format();
+ update_last_price_marker();
+ overlay_mgr_->reposition_all();
+}
+
+void EquityChart::zoom_time(double factor, qint64 anchor_ts) {
+ if (nav_.zoom(factor, anchor_ts))
+ apply_view_range();
+}
+
+void EquityChart::pan_time_pixels(int dx) {
+ if (!chart_ || dx == 0)
+ return;
+ const qreal plot_w = chart_->plotArea().width();
+ const qint64 span = last_max_time_ - last_min_time_;
+ if (plot_w <= 1.0 || span <= 0)
+ return;
+ // Drag right -> walk back in time.
+ const auto delta = static_cast<qint64>(-dx * (static_cast<double>(span) / plot_w));
+ if (nav_.pan(delta))
+ apply_view_range();
+}
+
+void EquityChart::reset_view() {
+ if (!nav_.active())
+ return;
+ nav_.reset();
+ rebuild_chart(); // re-fits both axes to the candle set
+ apply_tf_axis_format();
+ update_last_price_marker();
+}
+
void EquityChart::apply_tf_axis_format() {
if (!time_axis_ || candles_.isEmpty())
return;
diff --git a/fincept-qt/src/screens/equity_trading/EquityChart.h b/fincept-qt/src/screens/equity_trading/EquityChart.h
index de90de2ac..5459d4775 100644
--- a/fincept-qt/src/screens/equity_trading/EquityChart.h
+++ b/fincept-qt/src/screens/equity_trading/EquityChart.h
@@ -4,6 +4,7 @@
#include "trading/TradingTypes.h"
#include "ui/charts/ChartOverlayManager.h"
+#include "ui/charts/TimeAxisNavigator.h"
#include <QColor>
#include <QEvent>
@@ -73,6 +74,14 @@ class EquityChart : public QWidget {
void on_hover_position(const QPointF& chart_value_pos, const QPoint& view_pos);
void on_hover_leave();
+ // ── User-driven time navigation (#338) ────────────────────────────────
+ // Wheel zooms around the cursor, left-drag pans, double-click returns to
+ // auto-follow. Operates in synthetic-timestamp space, same as the axis.
+ void zoom_time(double factor, qint64 anchor_ts);
+ void pan_time_pixels(int dx);
+ void reset_view();
+ void apply_view_range();
+
HoverEquityChartView* chart_view_ = nullptr;
QChart* chart_ = nullptr;
QCandlestickSeries* series_ = nullptr;
@@ -99,6 +108,12 @@ class EquityChart : public QWidget {
QVector<trading::BrokerCandle> candles_;
static constexpr int MAX_VISIBLE = 120;
+ // Never fit the time axis tighter than this many slots — Qt sizes a candle
+ // body from the slot width in DOMAIN units, so a handful of candles on a
+ // data-fitted axis renders as giant blocks (#338).
+ static constexpr int MIN_VISIBLE_SLOTS = 40;
+
+ fincept::ui::TimeAxisNavigator nav_;
double last_min_price_ = -1;
double last_max_price_ = -1;
diff --git a/fincept-qt/src/screens/equity_trading/EquityTradingScreen.h b/fincept-qt/src/screens/equity_trading/EquityTradingScreen.h
index 6c354193f..2f483137c 100644
--- a/fincept-qt/src/screens/equity_trading/EquityTradingScreen.h
+++ b/fincept-qt/src/screens/equity_trading/EquityTradingScreen.h
@@ -270,6 +270,11 @@ class EquityTradingScreen : public QWidget, public IGroupLinked, public IStatefu
// ── Multi-account state ──
QString focused_account_id_; // the account targeted by order entry + chart
QString selected_symbol_ = "RELIANCE";
+ // "<symbol>|<timeframe>" the chart currently holds history for. Lets an
+ // empty broker response keep a good chart instead of wiping it down to
+ // live-only bars, while still clearing content the user has moved on
+ // from (#338).
+ QString chart_symbol_;
QString selected_exchange_ = "NSE";
// Paper trading (derived from focused account)
diff --git a/fincept-qt/src/screens/equity_trading/EquityTradingScreen_Streams.cpp b/fincept-qt/src/screens/equity_trading/EquityTradingScreen_Streams.cpp
index 30cc11c74..71352bb25 100644
--- a/fincept-qt/src/screens/equity_trading/EquityTradingScreen_Streams.cpp
+++ b/fincept-qt/src/screens/equity_trading/EquityTradingScreen_Streams.cpp
@@ -343,8 +343,26 @@ void EquityTradingScreen::update_chart_position() {
// ============================================================================
void EquityTradingScreen::on_stream_candles_fetched(const QString& account_id, const QVector<BrokerCandle>& candles) {
- if (account_id == focused_account_id_)
+ if (account_id != focused_account_id_)
+ return;
+
+ const QString key = selected_symbol_ + QLatin1Char('|') + chart_->current_timeframe();
+ if (!candles.isEmpty()) {
chart_->set_candles(candles);
+ chart_symbol_ = key;
+ return;
+ }
+
+ // Empty history — broker rejected the request, throttled us, or the symbol
+ // has no bars for this timeframe. Pushing it into the chart wipes what the
+ // user is looking at and leaves live ticks drawing a couple of giant
+ // blocks (#338). Keep the current series unless it belongs to a symbol or
+ // timeframe the user has already left.
+ if (chart_symbol_ != key) {
+ chart_->clear();
+ chart_symbol_.clear();
+ }
+ LOG_WARN("EquityTrading", QString("no candles returned for %1 — keeping existing chart").arg(key));
}
void EquityTradingScreen::on_stream_orderbook_fetched(const QString& account_id,
diff --git a/fincept-qt/src/trading/ExchangeSession.cpp b/fincept-qt/src/trading/ExchangeSession.cpp
index df1b63493..2dd3744df 100644
--- a/fincept-qt/src/trading/ExchangeSession.cpp
+++ b/fincept-qt/src/trading/ExchangeSession.cpp
@@ -662,8 +662,14 @@ OrderBookData ExchangeSession::fetch_orderbook(const QString& symbol, int limit)
QVector<Candle> ExchangeSession::fetch_ohlcv(const QString& symbol, const QString& timeframe, int limit) {
const auto j = daemon_call("fetch_ohlcv", {{"symbol", symbol}, {"timeframe", timeframe}, {"limit", limit}});
QVector<Candle> result;
- if (j.contains("error") || !j.contains("candles"))
+ if (j.contains("error") || !j.contains("candles")) {
+ // Swallowing this left the chart silently empty and the terminal
+ // showing live-only bars with no way to tell why (#338).
+ LOG_WARN(kSessionTag, QString("[%1] fetch_ohlcv %2 %3 failed: %4")
+ .arg(exchange_id_, symbol, timeframe,
+ j.value("error").toString(QStringLiteral("no candles in response"))));
return result;
+ }
const auto arr = j.value("candles").toArray();
for (const auto& item : arr)
result.append(parse_candle(item.toObject()));
diff --git a/fincept-qt/src/ui/charts/TimeAxisNavigator.cpp b/fincept-qt/src/ui/charts/TimeAxisNavigator.cpp
new file mode 100644
index 000000000..d05f7dd6d
--- /dev/null
+++ b/fincept-qt/src/ui/charts/TimeAxisNavigator.cpp
@@ -0,0 +1,78 @@
+#include "ui/charts/TimeAxisNavigator.h"
+
+#include <algorithm>
+
+namespace fincept::ui {
+
+void TimeAxisNavigator::set_extent(long long first, long long last, long long slot) {
+ first_ = first;
+ last_ = std::max(first, last);
+ slot_ = slot > 0 ? slot : 1;
+ if (active_)
+ clamp();
+}
+
+void TimeAxisNavigator::seed(long long min_v, long long max_v) {
+ if (active_ || max_v <= min_v)
+ return;
+ min_ = min_v;
+ max_ = max_v;
+}
+
+bool TimeAxisNavigator::zoom(double factor, long long anchor) {
+ if (max_ <= min_ || factor <= 0.0)
+ return false;
+
+ const long long span = max_ - min_;
+ const long long min_span = MIN_SLOTS * slot_;
+ // Zooming out stops one screen-width past the data on each side — beyond
+ // that the candles would shrink into an empty plot.
+ const long long max_span = (last_ - first_) + 2LL * EDGE_SLOTS * slot_;
+
+ long long new_span = static_cast<long long>(static_cast<double>(span) * factor);
+ new_span = std::clamp(new_span, min_span, std::max(min_span, max_span));
+
+ // Keep `anchor` under the cursor: preserve its relative position in the window.
+ double rel = static_cast<double>(anchor - min_) / static_cast<double>(span);
+ rel = std::clamp(rel, 0.0, 1.0);
+
+ min_ = anchor - static_cast<long long>(rel * static_cast<double>(new_span));
+ max_ = min_ + new_span;
+ active_ = true;
+ clamp();
+ return true;
+}
+
+bool TimeAxisNavigator::pan(long long delta) {
+ if (max_ <= min_ || delta == 0)
+ return false;
+ min_ += delta;
+ max_ += delta;
+ active_ = true;
+ clamp();
+ return true;
+}
+
+void TimeAxisNavigator::clamp() {
+ const long long span = max_ - min_;
+ const long long lo = first_ - EDGE_SLOTS * slot_;
+ const long long hi = last_ + EDGE_SLOTS * slot_;
+
+ if (span >= hi - lo) {
+ // Window is wider than everything we allow scrolling over — centre it
+ // on the data instead of letting it drift.
+ const long long mid = first_ + (last_ - first_) / 2;
+ min_ = mid - span / 2;
+ max_ = min_ + span;
+ return;
+ }
+ if (min_ < lo) {
+ min_ = lo;
+ max_ = lo + span;
+ } else if (max_ > hi) {
+ max_ = hi;
+ min_ = hi - span;
+ }
+}
+
+} // namespace fincept::ui
diff --git a/fincept-qt/src/ui/charts/TimeAxisNavigator.h b/fincept-qt/src/ui/charts/TimeAxisNavigator.h
new file mode 100644
index 000000000..8c35bb366
--- /dev/null
+++ b/fincept-qt/src/ui/charts/TimeAxisNavigator.h
@@ -0,0 +1,55 @@
+#pragma once
+// TimeAxisNavigator — shared pan/zoom window state for the Qt Charts
+// candlestick views (CryptoChart, EquityChart).
+//
+// Both charts re-fit their QDateTimeAxis to the candle set on every tick, so a
+// user-driven pan or zoom used to be impossible: the next WS candle snapped the
+// view straight back (issue #338, "I am not able to scroll"). This class owns
+// the user's window instead — once `active()` is true the chart stops auto-
+// fitting the time axis and renders `min()..max()`.
+//
+// Deliberately Qt-free arithmetic (plain `long long`, same unit as the axis:
+// real epoch-ms for CryptoChart, synthetic slot-ms for EquityChart) so the
+// clamping rules can be reasoned about and tested in isolation.
+
+namespace fincept::ui {
+
+class TimeAxisNavigator {
+ public:
+ // Hard zoom-in floor and how far past the data the user may scroll,
+ // both in slots.
+ static constexpr int MIN_SLOTS = 5;
+ static constexpr int EDGE_SLOTS = 20;
+
+ // Current data extent + slot width. Call on every axis update so the
+ // clamp follows the stream as new candles arrive.
+ void set_extent(long long first, long long last, long long slot);
+
+ // Seed the window from the chart's auto-fitted range. No-op once the user
+ // has taken over, so live candles can't yank the view back.
+ void seed(long long min_v, long long max_v);
+
+ bool active() const { return active_; }
+ void reset() { active_ = false; }
+
+ long long min() const { return min_; }
+ long long max() const { return max_; }
+
+ // factor < 1 zooms in. `anchor` (a time value, typically under the cursor)
+ // keeps its relative screen position. Returns false when there is no
+ // window to act on yet.
+ bool zoom(double factor, long long anchor);
+ bool pan(long long delta);
+
+ private:
+ void clamp();
+
+ long long first_ = 0;
+ long long last_ = 0;
+ long long slot_ = 60000;
+ long long min_ = 0;
+ long long max_ = 0;
+ bool active_ = false;
+};
+
+} // namespace fincept::ui