Commit graph

31 commits

Author SHA1 Message Date
Manohar
0e335f9654 fix: add missing </div> closing sec-cfg card — root cause of blank Analysis tab
The Alert Settings card (sec-cfg) was missing its outer closing </div>.
This caused the browser to nest view-analysis INSIDE view-dashboard.
When showView() set view-dashboard to display:none, view-analysis was
hidden too — making display:block on view-analysis itself useless since
a parent with display:none overrides all children.

Also retains the force-expand and loading-state improvements from prior
commits, and the diagnostic banner (to be removed once confirmed working).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 10:43:07 +05:30
Manohar
1b5e6d6868 debug: add step-by-step diagnostic banner to analysis tab
Adds a visible orange banner that updates at each step of loadAnalysis
(fetch → got data → renderAnalysis called → complete / error).
This definitively shows whether the view is reached and where it fails.
Remove after root cause is confirmed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 10:35:30 +05:30
Manohar
407f8a6b46 fix: force-expand analysis cards and show loading state on tab switch
- showView('analysis') now removes 'collapsed' from all three analysis
  card sections so localStorage state can't keep them hidden
- loadAnalysis() shows "Loading analysis…" immediately before the fetch
  so the user sees the view is active (not blank)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 10:25:50 +05:30
Manohar
8cd09d8a0e fix: three issues — symbol parser, booked PnL window, token reauth
1. parseOptionSymbol (greeks.ts)
   Added Format 3 for SENSEX weekly DD+MON+STRIKE symbols (no year).
   SENSEX26JUN77300PE was returning null — parser read year=26, day=77
   giving invalid date 2026-06-77. Now correctly parses as day=26,
   month=JUN, year=2026 (inferred), strike=77300.

2. Booked PnL window (server.ts)
   Changed all three booked-PnL queries from 'today IST only' to
   'last 7 days'. With a stale Angel One token, positions are not
   updated today so date(updated_at)=today returns 0 even when
   real closed-position PnL exists from yesterday.

3. Angel One token expiry UX (server.ts + index.html)
   - Added POST /api/reauth endpoint — forces a fresh Angel One
     login without restarting the container
   - Nav now shows red error text +  Reauth button whenever
     lastError is set; clicking reauth calls /api/reauth then
     re-runs refresh + analysis
   - Fixed loadHealth() to show/hide the error span (was always
     hidden due to missing display toggle)
   - Label changed from 'Booked P&L Today' → 'Booked PnL (7d)'

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 10:07:20 +05:30
Manohar
02cc8ed9b3 fix: make Analysis tab robust when no snapshot data exists
- showView() now tracks _curView, scrolls to top, forces visibility
- loadAnalysis() shows clear "No data yet" message when API returns null
  instead of silently leaving static placeholder text
- forceRefreshAnalysis() added: POSTs /api/refresh then reloads analysis
- ↻ Refresh button added at top of Analysis view with live timestamp
- Auto-refresh analysis every 30s when Analysis tab is active

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 14:20:59 +05:30
Manohar
dca5fea679 feat: add Analysis tab with position intelligence engine
Phase 1 of the position-tracker → analysis port:

Backend:
- src/ai/types.ts       — shared types (AnalysisInput, ClassifiedPosition, AnalysisResult, etc.)
- src/ai/greeks.ts      — added calcTheoreticalPrice() export for scenario analysis
- src/ai/classifier.ts  — pure-function position classifier (DEAD_WEIGHT/WORKING/UNDER_PRESSURE/HEDGE/DANGER_SHORT) with module-level hysteresis Map
- src/ai/portfolio-greeks.ts — aggregates per-unit Greeks × quantity into portfolio totals
- src/ai/risk-assessor.ts   — naked short detection, concentration, side imbalance, Greeks breach checks
- src/ai/scenario.ts        — P&L grid at ±100..±1000 spot moves per underlying
- src/ai/analyze.ts         — orchestrator: maps Position[] → AnalysisInput[], reads spot from market_cache, stores JSON in analysis_snapshots
- src/db/client.ts      — analysis_snapshots table + index
- src/tracker/poll.ts   — runAnalysis() called after every pollTick + forcePoll
- src/api/server.ts     — GET /api/analysis endpoint

Frontend (public/index.html):
- Multi-page nav with Dashboard | Analysis tabs (showView())
- Analysis view: summary cards (delta/theta/vega/risk level), action list (urgent positions sorted by urgency score), classification table with urgency bars, risk assessment details, scenario P&L grid per underlying
- loadAnalysis() + renderAnalysis() wired to tab switch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 14:07:24 +05:30
Manohar
b2e6ef940a fix: payoff chart zoomed to 1.5 SD range instead of 8% flat pad 2026-05-27 19:16:30 +05:30
Manohar
ef459facfc feat: reorder cards (payoff below positions), booked=totalRealised, payoff respects expiry tab 2026-05-27 14:00:41 +05:30
Manohar
a1945d06e2 fix: tab filtering uses filtered not open; tab class quote; booked=netqty=0 today only 2026-05-27 13:32:35 +05:30
Manohar
e8bb8fdd30 fix: expiry tabs outside card-head (no collapse on click), stopPropagation 2026-05-27 13:24:37 +05:30
Manohar
acf8799880 fix: P&L today-only date filter (IST), expiry tabs in positions table 2026-05-27 13:17:44 +05:30
Manohar
805f25eb75 fix: afterDraw with 1SD/2SD lines, breakeven%, spot line; all 3 table fixes 2026-05-15 10:38:16 +05:30
Manohar
b3b1946ee6 fix: slot label literal, netqty filter, today-only closed, calcSD + SD wire 2026-05-15 10:37:27 +05:30
Manohar
2540a89bae fix: slot label literal, netqty filter, today-only closed, green/red payoff lines, SD+breakeven% annotations 2026-05-15 10:14:02 +05:30
Manohar
aba1dcbdda fix: avg_price from netprice, hardcode VIX/crude/USDINR tokens, UI market cache fallback 2026-05-15 04:07:16 +00:00
Manohar
91fd17b158 fix: correct booked PnL (netqty=0 only), closed positions card, no false is_closed on open qty 2026-05-12 04:57:18 +00:00
Manohar
ade11564a8 fix: wire booked PnL to UI stat card 2026-05-12 04:34:28 +00:00
Manohar
4d1c956963 fix: booked PnL from closed legs, login mutex, market cache-on-error 2026-05-12 04:33:15 +00:00
Manohar
882d55adad feat: payoff graph clean inject (Python, no template literal escaping) 2026-05-11 05:23:12 +00:00
Manohar
c9a38be908 fix: payoff regex (\d stripped to d), proper fill zones, canvas annotation plugin 2026-05-11 05:16:17 +00:00
Manohar
4b0bfb2a12 feat: strategy payoff graph — breakeven, max P&L, R/R, spot line, profit/loss shading 2026-05-11 05:01:23 +00:00
Manohar
7cf1de885e fix: market fixed 6-slot order always; collapsed header shows P&L + alert count 2026-05-11 04:54:16 +00:00
Manohar
ed84985237 feat: 30s polling, market open/close Telegram alerts, mobile responsive UI 2026-05-11 04:45:22 +00:00
Manohar
ea6af0ea82 fix: each collapsible section is now independent — proper div structure 2026-05-09 04:19:38 +00:00
Manohar
dad5f9d337 fix: collapsible arrows on all 4 sections + market fixed order 2026-05-09 04:05:43 +00:00
Manohar
8564dcb8b2 fix: market cards fixed order; collapsible with arrow indicator 2026-05-09 04:04:09 +00:00
Manohar
5bdf7fbffe fix: market cache in SQLite for after-hours; collapsible sections with localStorage state 2026-05-09 03:50:11 +00:00
Manohar
1f00d2da41 design: favicon, market indices, alert settings, TTE, dark/light toggle 2026-05-09 03:42:19 +00:00
Manohar
30884f10e0 design: premium fintech UI — DM Serif, dark/light toggle, coral accents, glassmorphism nav 2026-05-08 17:31:26 +00:00
Manohar
e97a2ca643 feat: new UI — P&L summary cards, intraday chart, totals footer 2026-05-08 17:10:26 +00:00
Manohar
971c59df11 feat: initial position tracker scaffold 2026-05-08 11:22:05 +00:00