feat: add pip-installable aura-trade-sdk and real TradingView advanced chart
This commit is contained in:
+10
-41
@@ -4,8 +4,7 @@ import React, { useState, useEffect } from "react";
|
||||
import { TitanHeader } from "@/components/header/TitanHeader";
|
||||
import { WatchlistRadar } from "@/components/radar/WatchlistRadar";
|
||||
import { EconomicCalendarDock } from "@/components/macro/EconomicCalendarDock";
|
||||
import { TradingViewCanvas } from "@/components/chart/TradingViewCanvas";
|
||||
import { TimeframeSelector } from "@/components/chart/TimeframeSelector";
|
||||
import { ChartStageContainer } from "@/components/chart/ChartStageContainer";
|
||||
import { CockpitDock } from "@/components/dock/CockpitDock";
|
||||
import { ConfluenceMeter } from "@/components/execution/ConfluenceMeter";
|
||||
import { TitanOrderTerminal } from "@/components/execution/TitanOrderTerminal";
|
||||
@@ -238,45 +237,15 @@ export default function TitanQuantTerminalPage() {
|
||||
|
||||
{/* Center Stage (6 cols on xl): Dual-Pane Chart Stage & Cockpit Dock */}
|
||||
<section className="xl:col-span-6 flex flex-col gap-2.5">
|
||||
{/* Active Chart Navigation & Controls */}
|
||||
<div className="bg-[#070d18] border border-[#14233d] rounded-xl p-2.5 flex items-center justify-between shadow-lg">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="font-extrabold text-amber-400 text-sm font-mono tracking-wider">
|
||||
{activeSymbol}.PRO
|
||||
</span>
|
||||
<span className="text-[11px] text-gray-400 font-mono hidden sm:inline">
|
||||
Institutional Exness Direct Feed
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<TimeframeSelector
|
||||
activeTimeframe={activeTimeframe}
|
||||
onSelect={(tf) => {
|
||||
soundFX.playClick();
|
||||
setActiveTimeframe(tf);
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
onClick={() => {
|
||||
soundFX.playClick();
|
||||
setShowConnectModal(true);
|
||||
}}
|
||||
className="bg-[#0b172a] hover:bg-[#122240] border border-[#182e52] text-gray-300 text-xs px-2.5 py-1 rounded-md flex items-center gap-1.5 transition font-mono"
|
||||
>
|
||||
<KeyRound className="w-3.5 h-3.5 text-cyan-400" /> Connect MT5
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 60 FPS TradingView Canvas */}
|
||||
<div className="flex-1 bg-[#070d18] border border-[#14233d] rounded-xl overflow-hidden min-h-[380px] shadow-xl">
|
||||
<TradingViewCanvas
|
||||
candles={candles}
|
||||
liveTick={packet?.tick || null}
|
||||
activeFvgs={confluence?.active_fvgs || []}
|
||||
/>
|
||||
</div>
|
||||
<ChartStageContainer
|
||||
symbol={activeSymbol}
|
||||
timeframe={activeTimeframe}
|
||||
onSelectTimeframe={(tf) => setActiveTimeframe(tf)}
|
||||
candles={candles}
|
||||
liveTick={packet?.tick || null}
|
||||
activeFvgs={confluence?.active_fvgs || []}
|
||||
onOpenConnectModal={() => setShowConnectModal(true)}
|
||||
/>
|
||||
|
||||
{/* Lower 4-Tab Analytical Cockpit Dock */}
|
||||
<CockpitDock
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { TradingViewAdvancedChart } from "./TradingViewAdvancedChart";
|
||||
import { TradingViewCanvas } from "./TradingViewCanvas";
|
||||
import { TimeframeSelector } from "./TimeframeSelector";
|
||||
import { LineChart, Zap, KeyRound, Sparkles } 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;
|
||||
}
|
||||
|
||||
export const ChartStageContainer: React.FC<ChartStageContainerProps> = ({
|
||||
symbol,
|
||||
timeframe,
|
||||
onSelectTimeframe,
|
||||
candles,
|
||||
liveTick,
|
||||
activeFvgs,
|
||||
onOpenConnectModal,
|
||||
}) => {
|
||||
const [chartMode, setChartMode] = useState<"tv_pro" | "smc_canvas">("tv_pro");
|
||||
|
||||
const handleModeSwitch = (mode: "tv_pro" | "smc_canvas") => {
|
||||
soundFX.playClick();
|
||||
setChartMode(mode);
|
||||
};
|
||||
|
||||
const bid = liveTick?.bid || 2735.40;
|
||||
const ask = liveTick?.ask || 2735.54;
|
||||
const spread = liveTick?.spread_pips || 1.4;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 h-full">
|
||||
{/* Top Chart Navigation Bar */}
|
||||
<div className="bg-[#070d18] border border-[#14233d] rounded-xl p-2.5 flex flex-wrap items-center justify-between gap-3 shadow-lg select-none">
|
||||
{/* Left: Symbol & Live Price */}
|
||||
<div className="flex items-center gap-3">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-extrabold text-amber-400 text-sm font-mono tracking-wider">
|
||||
{symbol}.PRO
|
||||
</span>
|
||||
<span className="text-[10px] font-mono px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20 font-bold">
|
||||
OANDA FEED
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-[10px] text-gray-400 font-mono flex items-center gap-2">
|
||||
<span>Bid: <strong className="text-gray-100">{bid.toFixed(2)}</strong></span>
|
||||
<span>Ask: <strong className="text-gray-100">{ask.toFixed(2)}</strong></span>
|
||||
<span className="text-emerald-400 font-bold">Sp: {spread}p</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="h-6 w-px bg-[#14233d] hidden sm:block" />
|
||||
|
||||
{/* Mode Switcher: TradingView Pro vs SMC Canvas */}
|
||||
<div className="flex items-center p-0.5 rounded-lg bg-[#050914] border border-[#14233d] text-xs font-mono">
|
||||
<button
|
||||
onClick={() => handleModeSwitch("tv_pro")}
|
||||
className={`px-2.5 py-1 rounded-md flex items-center gap-1.5 font-bold transition ${
|
||||
chartMode === "tv_pro"
|
||||
? "bg-gradient-to-r from-cyan-600 to-blue-600 text-white shadow-md shadow-cyan-500/20"
|
||||
: "text-gray-400 hover:text-gray-200"
|
||||
}`}
|
||||
>
|
||||
<LineChart className="w-3.5 h-3.5 text-cyan-200" />
|
||||
<span>TradingView Pro</span>
|
||||
<span className="text-[9px] px-1 rounded bg-black/40 text-cyan-300">REAL</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => handleModeSwitch("smc_canvas")}
|
||||
className={`px-2.5 py-1 rounded-md flex items-center gap-1.5 font-bold transition ${
|
||||
chartMode === "smc_canvas"
|
||||
? "bg-gradient-to-r from-amber-600 to-orange-600 text-white shadow-md shadow-amber-500/20"
|
||||
: "text-gray-400 hover:text-gray-200"
|
||||
}`}
|
||||
>
|
||||
<Zap className="w-3.5 h-3.5 text-amber-200" />
|
||||
<span>SMC Imbalance</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right: Timeframes & MT5 Link */}
|
||||
<div className="flex items-center gap-2">
|
||||
<TimeframeSelector
|
||||
activeTimeframe={timeframe}
|
||||
onSelect={(tf) => {
|
||||
soundFX.playClick();
|
||||
onSelectTimeframe(tf);
|
||||
}}
|
||||
/>
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
soundFX.playClick();
|
||||
onOpenConnectModal();
|
||||
}}
|
||||
className="bg-[#0b172a] hover:bg-[#122240] border border-[#182e52] text-gray-300 text-xs px-2.5 py-1 rounded-md flex items-center gap-1.5 transition font-mono"
|
||||
>
|
||||
<KeyRound className="w-3.5 h-3.5 text-cyan-400" /> Connect MT5
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main Chart Stage */}
|
||||
<div className="flex-1 bg-[#070d18] border border-[#14233d] rounded-xl overflow-hidden min-h-[460px] shadow-xl relative">
|
||||
{chartMode === "tv_pro" ? (
|
||||
<TradingViewAdvancedChart symbol={symbol} timeframe={timeframe} height="100%" />
|
||||
) : (
|
||||
<TradingViewCanvas
|
||||
candles={candles}
|
||||
liveTick={liveTick}
|
||||
activeFvgs={activeFvgs}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useRef, memo } from "react";
|
||||
|
||||
// App Symbol -> Official TradingView Institutional Feed Map
|
||||
export const TV_SYMBOL_MAP: Record<string, string> = {
|
||||
"XAUUSD": "OANDA:XAUUSD",
|
||||
"XAU/USD": "OANDA:XAUUSD",
|
||||
"BTCUSD": "BINANCE:BTCUSDT",
|
||||
"BTC/USD": "BINANCE:BTCUSDT",
|
||||
"EURUSD": "FX:EURUSD",
|
||||
"EUR/USD": "FX:EURUSD",
|
||||
"GBPUSD": "FX:GBPUSD",
|
||||
"GBP/USD": "FX:GBPUSD",
|
||||
"US30": "CURRENCYCOM:US30",
|
||||
};
|
||||
|
||||
export function toTvSymbol(symbol: string): string {
|
||||
if (symbol.includes(":")) return symbol;
|
||||
return TV_SYMBOL_MAP[symbol.replace("/", "")] || `FX:${symbol.replace("/", "")}`;
|
||||
}
|
||||
|
||||
export function toTvInterval(tf: string): string {
|
||||
switch (tf) {
|
||||
case "1m": return "1";
|
||||
case "5m": return "5";
|
||||
case "15m": return "15";
|
||||
case "1H": return "60";
|
||||
case "4H": return "240";
|
||||
case "D1": return "D";
|
||||
default: return "15";
|
||||
}
|
||||
}
|
||||
|
||||
interface TradingViewAdvancedChartProps {
|
||||
symbol: string;
|
||||
timeframe: string;
|
||||
height?: string | number;
|
||||
}
|
||||
|
||||
const DEFAULT_STUDIES = [
|
||||
"RSI@tv-basicstudies",
|
||||
"MACD@tv-basicstudies",
|
||||
"MASimple@tv-basicstudies",
|
||||
];
|
||||
|
||||
function TradingViewAdvancedChartComponent({
|
||||
symbol,
|
||||
timeframe,
|
||||
height = "100%",
|
||||
}: TradingViewAdvancedChartProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const host = containerRef.current;
|
||||
if (!host) return;
|
||||
|
||||
const tvSymbol = toTvSymbol(symbol);
|
||||
const tvInterval = toTvInterval(timeframe);
|
||||
|
||||
// Clean previous widget
|
||||
host.innerHTML = "";
|
||||
|
||||
const widget = document.createElement("div");
|
||||
widget.className = "tradingview-widget-container__widget";
|
||||
widget.style.height = "100%";
|
||||
widget.style.width = "100%";
|
||||
host.appendChild(widget);
|
||||
|
||||
const script = document.createElement("script");
|
||||
script.src = "https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js";
|
||||
script.type = "text/javascript";
|
||||
script.async = true;
|
||||
script.innerHTML = JSON.stringify({
|
||||
autosize: true,
|
||||
symbol: tvSymbol,
|
||||
interval: tvInterval,
|
||||
timezone: "Asia/Dhaka",
|
||||
theme: "dark",
|
||||
style: "1", // Japanese Candlestick
|
||||
locale: "en",
|
||||
enable_publishing: false,
|
||||
backgroundColor: "#070d18",
|
||||
gridColor: "rgba(20, 35, 61, 0.4)",
|
||||
withdateranges: true,
|
||||
hide_side_toolbar: false, // FULL DRAWING TOOLBAR ENABLED
|
||||
allow_symbol_change: true,
|
||||
save_image: true,
|
||||
details: false,
|
||||
calendar: false,
|
||||
studies: DEFAULT_STUDIES,
|
||||
support_host: "https://www.tradingview.com",
|
||||
});
|
||||
|
||||
host.appendChild(script);
|
||||
|
||||
return () => {
|
||||
if (host) host.innerHTML = "";
|
||||
};
|
||||
}, [symbol, timeframe]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="tradingview-widget-container w-full h-full rounded-xl overflow-hidden"
|
||||
ref={containerRef}
|
||||
style={{ height, width: "100%" }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export const TradingViewAdvancedChart = memo(TradingViewAdvancedChartComponent);
|
||||
Reference in New Issue
Block a user