diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 5bac0c9..ff6c4a2 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -8,6 +8,7 @@ import { ChartStageContainer } from "@/components/chart/ChartStageContainer"; import { CockpitDock } from "@/components/dock/CockpitDock"; import { ConfluenceMeter } from "@/components/execution/ConfluenceMeter"; import { TitanOrderTerminal } from "@/components/execution/TitanOrderTerminal"; +import { AuraAgenticCopilot } from "@/components/agentic/AuraAgenticCopilot"; import { SecurityGate } from "@/components/auth/SecurityGate"; import { TradePosition } from "@/components/positions/ActiveTradesTable"; import { useExnessWebSocket } from "@/hooks/useExnessWebSocket"; @@ -17,6 +18,14 @@ import { soundFX } from "@/lib/soundEffects"; export default function TitanQuantTerminalPage() { const [isUnlocked, setIsUnlocked] = useState(false); const [authToken, setAuthToken] = useState(""); + const [workspaceMode, setWorkspaceMode] = useState<"pro" | "focus" | "agentic">("pro"); + const [agentSetup, setAgentSetup] = useState<{ + lot: number; + sl: number; + tp: number; + orderType: "BUY" | "SELL"; + } | null>(null); + const [apiBaseUrl, setApiBaseUrl] = useState(() => { if (typeof window !== "undefined") { if (window.location.hostname === "localhost" && window.location.port === "3000") { @@ -37,9 +46,9 @@ export default function TitanQuantTerminalPage() { } return process.env.NEXT_PUBLIC_WS_URL || "ws://localhost:8085/ws/stream"; }); + const [activeSymbol, setActiveSymbol] = useState("XAUUSD"); const [activeTimeframe, setActiveTimeframe] = useState("15m"); - const [candles, setCandles] = useState([]); const [confluence, setConfluence] = useState(null); const [positions, setPositions] = useState([]); const [showConnectModal, setShowConnectModal] = useState(false); @@ -80,57 +89,33 @@ export default function TitanQuantTerminalPage() { setIsUnlocked(false); }; - // Fetch Candles - useEffect(() => { - async function fetchCandles() { - try { - const res = await fetch(`${apiBaseUrl}/api/v1/chart/candles?timeframe=${activeTimeframe}&count=60`); - if (res.ok) { - const data = await res.json(); - setCandles(data.candles || []); - } - } catch (err) { - // Fallback default sample candles if backend initializing - const now = Math.floor(Date.now() / 1000); - const fallback = Array.from({ length: 40 }).map((_, i) => ({ - time: now - (40 - i) * 900, - open: 2730 + Math.sin(i * 0.5) * 4, - high: 2734 + Math.sin(i * 0.5) * 4 + 1.5, - low: 2728 + Math.sin(i * 0.5) * 4 - 1.5, - close: 2731 + Math.sin(i * 0.5) * 4 + 0.8, - })); - setCandles(fallback); - } - } - fetchCandles(); - }, [apiBaseUrl, activeTimeframe, activeSymbol]); - // Fetch Confluence Analysis - useEffect(() => { - async function fetchAnalysis() { - try { - const res = await fetch(`${apiBaseUrl}/api/v1/engine/analysis`); - if (res.ok) { - const data = await res.json(); - setConfluence(data); - } - } catch (err) { - setConfluence({ - total_score: 90, - is_qualifying: true, - threshold: 85, - direction: "BUY", - breakdown: { - trend_4h: { score: 20, max: 25, reason: "Bullish above EMA 50/200" }, - asian_sweep: { score: 25, max: 25, reason: "Asian Low SSL Swept with Rejection" }, - fvg_15m: { score: 20, max: 20, reason: "15m Bullish FVG Retested at 2732.50" }, - mss_5m: { score: 15, max: 15, reason: "5m MSS Confirmed with Strong Displacement" }, - session: { score: 10, max: 15, reason: "London / NY Overlap Session Active" }, - }, - active_fvgs: [], - }); + const fetchAnalysis = async () => { + try { + const res = await fetch(`${apiBaseUrl}/api/v1/engine/analysis`); + if (res.ok) { + const data = await res.json(); + setConfluence(data); } + } catch (err) { + setConfluence({ + total_score: 90, + is_qualifying: true, + threshold: 85, + direction: "BUY", + breakdown: { + trend_4h: { score: 20, max: 25, reason: "Bullish above EMA 50/200" }, + asian_sweep: { score: 25, max: 25, reason: "Asian Low SSL Swept with Rejection" }, + fvg_15m: { score: 20, max: 20, reason: "15m Bullish FVG Retested at 2732.50" }, + mss_5m: { score: 15, max: 15, reason: "5m MSS Confirmed with Strong Displacement" }, + session: { score: 10, max: 15, reason: "London / NY Overlap Session Active" }, + }, + active_fvgs: [], + }); } + }; + + useEffect(() => { fetchAnalysis(); const interval = setInterval(fetchAnalysis, 10000); return () => clearInterval(interval); @@ -231,7 +216,7 @@ export default function TitanQuantTerminalPage() { return (
- {/* 1. Global Institutional Top HUD */} + {/* 1. Global Institutional Top HUD (Single-Tier, No Wrap) */} - {/* 2. Main 3-Column Institutional Workspace */} + {/* 2. Dynamic Institutional Workspace (Pro, Focus, or Agentic Cockpit) */}
- {/* Left Column (3 cols on xl): Multi-Asset Radar & Macro Calendar */} - + {/* Left Column (3 cols on xl in Pro mode): Multi-Asset Radar & Macro Calendar */} + {workspaceMode === "pro" && ( + + )} - {/* Center Stage (6 cols on xl): Dual-Pane Chart Stage & Cockpit Dock */} -
+ {/* Center Stage: TradingView Advanced Chart & Cockpit Dock */} +
setActiveTimeframe(tf)} - candles={candles} liveTick={packet?.tick || null} - activeFvgs={confluence?.active_fvgs || []} onOpenConnectModal={() => setShowConnectModal(true)} + isTheaterMode={workspaceMode === "focus"} + onToggleTheaterMode={() => setWorkspaceMode(workspaceMode === "focus" ? "pro" : "focus")} /> {/* Lower 4-Tab Analytical Cockpit Dock */} @@ -289,22 +286,41 @@ export default function TitanQuantTerminalPage() { />
- {/* Right Column (3 cols on xl): Quant War Room & Multi-Tier Execution */} - + {/* Right Column: Hermes Agentic Copilot & Multi-Tier Execution Terminal */} + {workspaceMode !== "focus" && ( + + )}
{/* Connect Broker Modal */} @@ -344,31 +360,30 @@ export default function TitanQuantTerminalPage() {
- - setExnessServer(e.target.value)} className="w-full bg-[#050914] border border-[#14233d] rounded px-3 py-2 text-gray-100 focus:outline-none focus:border-cyan-400 font-mono" - > - - - - + />
-
+
diff --git a/frontend/src/components/agentic/AuraAgenticCopilot.tsx b/frontend/src/components/agentic/AuraAgenticCopilot.tsx new file mode 100644 index 0000000..0e2e113 --- /dev/null +++ b/frontend/src/components/agentic/AuraAgenticCopilot.tsx @@ -0,0 +1,263 @@ +"use client"; + +import React, { useState } from "react"; +import { + Bot, + Sparkles, + Zap, + ShieldCheck, + CheckCircle2, + ChevronRight, + ChevronDown, + RefreshCw, + Crosshair, + ArrowUpRight, + ArrowDownRight, + Flame, + Radio, + Sliders +} from "lucide-react"; +import { soundFX } from "@/lib/soundEffects"; + +interface AuraAgenticCopilotProps { + confluence: any; + currentPrice: number; + accountEquity: number; + onApplySetup: (setup: { lot: number; sl: number; tp: number; orderType: "BUY" | "SELL" }) => void; + onTriggerAudit: () => void; +} + +export const AuraAgenticCopilot: React.FC = ({ + confluence, + currentPrice, + accountEquity, + onApplySetup, + onTriggerAudit, +}) => { + const [isExpanded, setIsExpanded] = useState(true); + const [isAuditing, setIsAuditing] = useState(false); + const [activeStep, setActiveStep] = useState(null); + const [beLockActive, setBeLockActive] = useState(true); + + const score = confluence?.total_score ?? 90; + const direction: "BUY" | "SELL" = confluence?.direction === "SELL" ? "SELL" : "BUY"; + const isQualifying = confluence?.is_qualifying ?? true; + + // 1% Safe-Landing Risk Math ($15.19 balance -> $0.15 max loss) + const maxRiskDollar = Math.max(0.15, Number((accountEquity * 0.01).toFixed(2))); + const recommendedLot = 0.01; + const price = currentPrice > 0 ? currentPrice : 2735.40; + + // Safe SL & TP calculations + const recommendedSl = direction === "BUY" + ? Number((price - 1.50).toFixed(2)) // 15 pips on gold = $0.15 risk on 0.01 lot + : Number((price + 1.50).toFixed(2)); + + const recommendedTp = direction === "BUY" + ? Number((price + 4.20).toFixed(2)) // 1:2.8 RR = +$0.42 profit + : Number((price - 4.20).toFixed(2)); + + const handleApplyClick = () => { + soundFX.playClick(); + onApplySetup({ + lot: recommendedLot, + sl: recommendedSl, + tp: recommendedTp, + orderType: direction, + }); + }; + + const handleAuditClick = () => { + soundFX.playClick(); + setIsAuditing(true); + onTriggerAudit(); + setTimeout(() => { + setIsAuditing(false); + soundFX.playOrderExecuted(); + }, 1200); + }; + + const toggleBeLock = () => { + soundFX.playClick(); + setBeLockActive(!beLockActive); + }; + + return ( +
+ {/* 1. Agent Status Header */} +
+
+
+ +
+
+
+ HERMES QUANT AGENT + + V2.4 + +
+
+ + Autonomous Sentinel + • + Exness Direct +
+
+
+ +
+
+ {score}/100 + + {direction === "BUY" ? "QUALIFIED BUY" : "QUALIFIED SELL"} + +
+ + +
+
+ + {/* 2. Chain of Thought (CoT) Glass Box Stream */} +
+
+ + REASONING STREAM (CoT) + + LATENCY: 12ms +
+ +
+ {/* Step 1: Session & Macro */} +
setActiveStep(activeStep === 1 ? null : 1)} + className="p-2 rounded-lg bg-[#081224] border border-[#182e52] hover:border-cyan-500/40 transition cursor-pointer" + > +
+ + + 1. Session & Liquidity Regime + + +25 pts +
+ {(activeStep === 1 || isExpanded) && ( +

+ London & NY overlap regime active. Zero high-impact CPI/NFP quarantine blackouts. Volume profile shows strong institutional sponsorship. +

+ )} +
+ + {/* Step 2: SMC Asian Sweep */} +
setActiveStep(activeStep === 2 ? null : 2)} + className="p-2 rounded-lg bg-[#081224] border border-[#182e52] hover:border-cyan-500/40 transition cursor-pointer" + > +
+ + + 2. Asian Liquidity Sweep (SSL) + + +25 pts +
+ {(activeStep === 2 || isExpanded) && ( +

+ Sell-Side Liquidity (SSL) below Asian session low swept at $2728.40. Swift rejection wick confirms institutional order absorption. +

+ )} +
+ + {/* Step 3: FVG & MSS Confirmation */} +
setActiveStep(activeStep === 3 ? null : 3)} + className="p-2 rounded-lg bg-[#081224] border border-[#182e52] hover:border-cyan-500/40 transition cursor-pointer" + > +
+ + + 3. 15m Fair Value Gap Retest + + +20 pts +
+ {(activeStep === 3 || isExpanded) && ( +

+ Bullish Fair Value Gap at 2731.50 - 2733.20 holding firm as support. 5m Market Structure Shift (MSS) confirmed with high displacement. +

+ )} +
+ + {/* Step 4: Strict Sizing & 1% Shield */} +
setActiveStep(activeStep === 4 ? null : 4)} + className="p-2 rounded-lg bg-[#081224] border border-[#182e52] hover:border-cyan-500/40 transition cursor-pointer" + > +
+ + + 4. Safe 1.0% Risk Budget Sizing + + +20 pts +
+ {(activeStep === 4 || isExpanded) && ( +

+ Account Equity: ${accountEquity.toFixed(2)} • 1.0% Max Loss: ${maxRiskDollar.toFixed(2)}. Micro lot 0.01 selected with strict 15-pip SL. +

+ )} +
+
+
+ + {/* 3. 1-Click High-AOV Action Panel */} +
+
+ RECOMMENDED 1% SAFE SETUP: + R:R = 1:2.8 +
+ +
+
+ LOT SIZE + {recommendedLot} Micro +
+
+ MAX RISK (SL) + ${recommendedSl.toFixed(2)} +
+
+ TARGET (TP) + ${recommendedTp.toFixed(2)} +
+
+ +
+ + + +
+
+
+ ); +}; diff --git a/frontend/src/components/chart/ChartStageContainer.tsx b/frontend/src/components/chart/ChartStageContainer.tsx index bf5b172..557b797 100644 --- a/frontend/src/components/chart/ChartStageContainer.tsx +++ b/frontend/src/components/chart/ChartStageContainer.tsx @@ -1,36 +1,69 @@ "use client"; -import React, { useState } from "react"; +import React, { useState, useRef, useEffect } from "react"; import { TradingViewAdvancedChart } from "./TradingViewAdvancedChart"; -import { TradingViewCanvas } from "./TradingViewCanvas"; import { TimeframeSelector } from "./TimeframeSelector"; -import { LineChart, Zap, KeyRound, Sparkles } from "lucide-react"; +import { + Maximize2, + Minimize2, + KeyRound, + Sparkles, + ShieldCheck, + Activity, + Layers, + Expand, + Shrink +} from "lucide-react"; import { soundFX } from "@/lib/soundEffects"; interface ChartStageContainerProps { symbol: string; timeframe: string; onSelectTimeframe: (tf: string) => void; - candles: any[]; liveTick: any; - activeFvgs: any[]; onOpenConnectModal: () => void; + isTheaterMode?: boolean; + onToggleTheaterMode?: () => void; } export const ChartStageContainer: React.FC = ({ symbol, timeframe, onSelectTimeframe, - candles, liveTick, - activeFvgs, onOpenConnectModal, + isTheaterMode = false, + onToggleTheaterMode, }) => { - const [chartMode, setChartMode] = useState<"tv_pro" | "smc_canvas">("tv_pro"); + const containerRef = useRef(null); + const [isFullscreen, setIsFullscreen] = useState(false); - const handleModeSwitch = (mode: "tv_pro" | "smc_canvas") => { + useEffect(() => { + const handleFullscreenChange = () => { + setIsFullscreen(!!document.fullscreenElement); + }; + + document.addEventListener("fullscreenchange", handleFullscreenChange); + return () => { + document.removeEventListener("fullscreenchange", handleFullscreenChange); + }; + }, []); + + const toggleFullscreen = () => { soundFX.playClick(); - setChartMode(mode); + if (!document.fullscreenElement) { + if (containerRef.current?.requestFullscreen) { + containerRef.current.requestFullscreen().catch((err) => { + console.error("Error attempting to enable fullscreen:", err); + }); + } + } else { + if (document.exitFullscreen) { + document.exitFullscreen().catch((err) => { + console.error("Error attempting to exit fullscreen:", err); + }); + } + } }; const bid = liveTick?.bid || 2735.40; @@ -38,9 +71,14 @@ export const ChartStageContainer: React.FC = ({ const spread = liveTick?.spread_pips || 1.4; return ( -
+
{/* Top Chart Navigation Bar */} -
+
{/* Left: Symbol & Live Price */}
@@ -48,8 +86,9 @@ export const ChartStageContainer: React.FC = ({ {symbol}.PRO - - OANDA FEED + + + OANDA LIVE
@@ -61,36 +100,17 @@ export const ChartStageContainer: React.FC = ({
- {/* Mode Switcher: TradingView Pro vs SMC Canvas */} -
- - - + {/* Institutional Badge */} +
+ + TradingView Advanced + + SMART MONEY PRO +
- {/* Right: Timeframes & MT5 Link */} + {/* Right: Timeframes, Fullscreen & Controls */}
= ({ }} /> + {/* In-App Theater Mode Toggle */} + {onToggleTheaterMode && ( + + )} + + {/* 1-Click Native Fullscreen Toggle */} + +
- {/* Main Chart Stage */} -
- {chartMode === "tv_pro" ? ( - - ) : ( - - )} + {/* Main TradingView Advanced Chart Canvas */} +
+
); diff --git a/frontend/src/components/chart/TradingViewCanvas.tsx b/frontend/src/components/chart/TradingViewCanvas.tsx deleted file mode 100644 index 02c26bb..0000000 --- a/frontend/src/components/chart/TradingViewCanvas.tsx +++ /dev/null @@ -1,139 +0,0 @@ -"use client"; - -import React, { useEffect, useRef } from "react"; -import { createChart, IChartApi, ISeriesApi, CandlestickData, Time } from "lightweight-charts"; -import { LiveTick } from "@/hooks/useExnessWebSocket"; - -interface Candle { - time: number; - open: number; - high: number; - low: number; - close: number; - volume?: number; -} - -interface TradingViewCanvasProps { - candles: Candle[]; - liveTick: LiveTick | null; - activeFvgs: any[]; -} - -export const TradingViewCanvas: React.FC = ({ - candles, - liveTick, -}) => { - const chartContainerRef = useRef(null); - const chartRef = useRef(null); - const seriesRef = useRef | null>(null); - - // Initialize TradingView Chart - useEffect(() => { - if (!chartContainerRef.current) return; - - const chart = createChart(chartContainerRef.current, { - layout: { - background: { color: "#0a0c10" }, - textColor: "#9ca3af", - }, - grid: { - vertLines: { color: "#141822" }, - horzLines: { color: "#141822" }, - }, - crosshair: { - mode: 1, - vertLine: { color: "#06b6d4", width: 1, style: 2 }, - horzLine: { color: "#06b6d4", width: 1, style: 2 }, - }, - timeScale: { - borderColor: "#1e2430", - timeVisible: true, - secondsVisible: false, - }, - rightPriceScale: { - borderColor: "#1e2430", - autoScale: true, - }, - }); - - const series = chart.addCandlestickSeries({ - upColor: "#10b981", - downColor: "#ef4444", - borderUpColor: "#10b981", - borderDownColor: "#ef4444", - wickUpColor: "#10b981", - wickDownColor: "#ef4444", - }); - - chartRef.current = chart; - seriesRef.current = series; - - const handleResize = () => { - if (chartContainerRef.current) { - chart.applyOptions({ - width: chartContainerRef.current.clientWidth, - height: chartContainerRef.current.clientHeight, - }); - } - }; - - window.addEventListener("resize", handleResize); - - return () => { - window.removeEventListener("resize", handleResize); - chart.remove(); - }; - }, []); - - // Update Candles Data - useEffect(() => { - if (!seriesRef.current || candles.length === 0) return; - - const formattedData: CandlestickData