feat: initial commit of AuraTrade quant terminal and sentinel risk engine

This commit is contained in:
2026-10-22 18:36:55 +06:00
commit 9469afec0b
31 changed files with 2434 additions and 0 deletions
@@ -0,0 +1,119 @@
"use client";
import React from "react";
import { CheckCircle2, XCircle, Flame, Target } from "lucide-react";
interface ConfluenceBreakdownItem {
name?: string;
bias?: string;
status?: string;
detail?: string;
points: number;
max: number;
}
interface ConfluenceData {
total_score: number;
is_qualifying: boolean;
threshold: number;
direction: string;
breakdown: Record<string, ConfluenceBreakdownItem>;
active_fvgs: any[];
}
interface ConfluenceMeterProps {
confluence: ConfluenceData | null;
}
export const ConfluenceMeter: React.FC<ConfluenceMeterProps> = ({ confluence }) => {
const score = confluence?.total_score ?? 75;
const isQualifying = score >= (confluence?.threshold ?? 85);
const direction = confluence?.direction ?? "BUY";
return (
<div className="bg-darkCard border border-darkBorder rounded-lg p-3.5 flex flex-col gap-3">
{/* Score Header */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-1.5">
<Target className="w-4 h-4 text-accentGold" />
<h3 className="text-xs font-bold text-gray-200 tracking-wider uppercase">SMC Confluence Engine</h3>
</div>
{isQualifying ? (
<span className="flex items-center gap-1 text-[11px] bg-emerald-950/60 border border-emerald-700/60 text-accentGreen font-bold px-2 py-0.5 rounded animate-pulse">
<Flame className="w-3 h-3" /> A+ SETUP READY
</span>
) : (
<span className="text-[10px] text-gray-500 font-mono">Requires &ge;85%</span>
)}
</div>
{/* Radial / Progress Meter */}
<div className="flex items-center gap-3">
<div className="relative w-16 h-16 flex items-center justify-center rounded-full border-4 border-darkBorder bg-darkBg">
<div className="text-center font-mono">
<span className={`text-lg font-bold leading-none ${isQualifying ? "text-accentGreen" : "text-accentGold"}`}>
{score}
</span>
<span className="block text-[8px] text-gray-500">/ 100</span>
</div>
</div>
<div className="flex-1 text-xs">
<div className="flex justify-between text-gray-400 mb-1">
<span>Setup Quality</span>
<strong className="text-gray-200">{isQualifying ? "Elite Institutional" : "Monitoring Structure"}</strong>
</div>
<div className="w-full bg-darkBorder h-2 rounded-full overflow-hidden">
<div
className={`h-full transition-all duration-500 rounded-full ${
isQualifying ? "bg-accentGreen" : "bg-accentGold"
}`}
style={{ width: `${score}%` }}
/>
</div>
<div className="mt-1 text-[11px] text-gray-400">
Bias: <strong className={direction === "BUY" ? "text-accentGreen" : "text-accentRed"}>{direction}</strong>
</div>
</div>
</div>
{/* Institutional Checklist */}
<div className="space-y-1.5 border-t border-darkBorder pt-2 text-[11px] font-mono">
<div className="flex items-center justify-between text-gray-300">
<span className="flex items-center gap-1.5">
<CheckCircle2 className="w-3.5 h-3.5 text-accentGreen" /> 4H/1H HTF Trend Alignment
</span>
<span className="text-gray-400">+20 pts</span>
</div>
<div className="flex items-center justify-between text-gray-300">
<span className="flex items-center gap-1.5">
<CheckCircle2 className="w-3.5 h-3.5 text-accentGreen" /> Asian Liquidity Sweep (BSL/SSL)
</span>
<span className="text-gray-400">+25 pts</span>
</div>
<div className="flex items-center justify-between text-gray-300">
<span className="flex items-center gap-1.5">
<CheckCircle2 className="w-3.5 h-3.5 text-accentGreen" /> 15m Fair Value Gap Retest
</span>
<span className="text-gray-400">+20 pts</span>
</div>
<div className="flex items-center justify-between text-gray-300">
<span className="flex items-center gap-1.5">
<CheckCircle2 className="w-3.5 h-3.5 text-accentGreen" /> 5m Market Structure Shift
</span>
<span className="text-gray-400">+15 pts</span>
</div>
<div className="flex items-center justify-between text-gray-300">
<span className="flex items-center gap-1.5">
<CheckCircle2 className="w-3.5 h-3.5 text-accentGreen" /> London/NY Overlap Hours
</span>
<span className="text-gray-400">+10 pts</span>
</div>
</div>
</div>
);
};
@@ -0,0 +1,183 @@
"use client";
import React, { useState, useEffect } from "react";
import { ArrowUpRight, ArrowDownRight, ShieldCheck, RefreshCw } from "lucide-react";
import { LiveTick, LiveTelemetry } from "@/hooks/useExnessWebSocket";
interface OrderDrawerProps {
liveTick: LiveTick | null;
telemetry: LiveTelemetry | null;
onExecuteTrade: (trade: {
symbol: string;
order_type: string;
lot: number;
price: number;
sl: number;
tp: number;
}) => Promise<void>;
}
export const OrderDrawer: React.FC<OrderDrawerProps> = ({
liveTick,
telemetry,
onExecuteTrade,
}) => {
const currentPrice = liveTick?.bid ?? 2735.40;
const equity = telemetry?.equity ?? 1000.0;
const [orderType, setOrderType] = useState<"BUY" | "SELL">("BUY");
const [entryPrice, setEntryPrice] = useState<number>(currentPrice);
const [slPrice, setSlPrice] = useState<number>(currentPrice - 5.50);
const [tpPrice, setTpPrice] = useState<number>(currentPrice + 14.00);
const [lotSize, setLotSize] = useState<number>(0.02);
const [isSubmitting, setIsSubmitting] = useState(false);
// Sync entry price when current price moves
useEffect(() => {
if (liveTick) {
setEntryPrice(liveTick.bid);
if (orderType === "BUY") {
setSlPrice(Number((liveTick.bid - 5.50).toFixed(2)));
setTpPrice(Number((liveTick.bid + 14.00).toFixed(2)));
} else {
setSlPrice(Number((liveTick.ask + 5.50).toFixed(2)));
setTpPrice(Number((liveTick.ask - 14.00).toFixed(2)));
}
}
}, [liveTick?.bid, orderType]);
// Recalculate 1.0% safe lot dynamically
useEffect(() => {
const slPips = Math.abs(entryPrice - slPrice) * 10;
if (slPips > 0 && equity > 0) {
const riskDollars = equity * 0.01; // 1% risk
const safeLot = Math.max(0.01, Number((riskDollars / (slPips * 10)).toFixed(2)));
setLotSize(safeLot);
}
}, [entryPrice, slPrice, equity]);
const slPips = Math.round(Math.abs(entryPrice - slPrice) * 10);
const tpPips = Math.round(Math.abs(tpPrice - entryPrice) * 10);
const riskReward = slPips > 0 ? (tpPips / slPips).toFixed(2) : "0.00";
const riskDollars = (equity * 0.01).toFixed(2);
const handleSubmit = async () => {
setIsSubmitting(true);
try {
await onExecuteTrade({
symbol: "XAUUSD",
order_type: orderType,
lot: lotSize,
price: entryPrice,
sl: slPrice,
tp: tpPrice,
});
} finally {
setIsSubmitting(false);
}
};
return (
<div className="bg-darkCard border border-darkBorder rounded-lg p-3.5 flex flex-col gap-3">
<div className="flex items-center justify-between border-b border-darkBorder pb-2">
<h3 className="text-xs font-bold text-gray-200 uppercase tracking-wider">1-Click Execution Terminal</h3>
<span className="text-[10px] bg-emerald-950/60 border border-emerald-800/60 text-accentGreen px-2 py-0.5 rounded flex items-center gap-1">
<ShieldCheck className="w-3 h-3" /> 1.0% Risk Capped
</span>
</div>
{/* Order Type Tabs */}
<div className="grid grid-cols-2 gap-2">
<button
onClick={() => setOrderType("BUY")}
className={`py-2 rounded font-bold text-xs flex items-center justify-center gap-1.5 transition ${
orderType === "BUY"
? "bg-accentGreen text-black shadow-lg shadow-emerald-500/20"
: "bg-darkBg text-gray-400 hover:text-gray-200 border border-darkBorder"
}`}
>
<ArrowUpRight className="w-4 h-4" /> BUY (LONG)
</button>
<button
onClick={() => setOrderType("SELL")}
className={`py-2 rounded font-bold text-xs flex items-center justify-center gap-1.5 transition ${
orderType === "SELL"
? "bg-accentRed text-white shadow-lg shadow-red-500/20"
: "bg-darkBg text-gray-400 hover:text-gray-200 border border-darkBorder"
}`}
>
<ArrowDownRight className="w-4 h-4" /> SELL (SHORT)
</button>
</div>
{/* Inputs Grid */}
<div className="grid grid-cols-2 gap-2 text-xs font-mono">
<div>
<label className="text-gray-400 block text-[10px] mb-1">Entry Price ($)</label>
<input
type="number"
step="0.01"
value={entryPrice}
onChange={(e) => setEntryPrice(parseFloat(e.target.value) || 0)}
className="w-full bg-darkBg border border-darkBorder rounded px-2.5 py-1.5 text-gray-200 focus:outline-none focus:border-accentCyan"
/>
</div>
<div>
<label className="text-gray-400 block text-[10px] mb-1">Lot Size (Auto 1%)</label>
<input
type="number"
step="0.01"
value={lotSize}
onChange={(e) => setLotSize(parseFloat(e.target.value) || 0.01)}
className="w-full bg-darkBg border border-darkBorder rounded px-2.5 py-1.5 text-accentGold font-bold focus:outline-none focus:border-accentGold"
/>
</div>
<div>
<label className="text-gray-400 block text-[10px] mb-1">Hard Stop Loss ($)</label>
<input
type="number"
step="0.01"
value={slPrice}
onChange={(e) => setSlPrice(parseFloat(e.target.value) || 0)}
className="w-full bg-darkBg border border-red-900/50 rounded px-2.5 py-1.5 text-red-400 focus:outline-none focus:border-red-500"
/>
<span className="text-[10px] text-gray-500">-{slPips} pips (${riskDollars})</span>
</div>
<div>
<label className="text-gray-400 block text-[10px] mb-1">Hard Take Profit ($)</label>
<input
type="number"
step="0.01"
value={tpPrice}
onChange={(e) => setTpPrice(parseFloat(e.target.value) || 0)}
className="w-full bg-darkBg border border-emerald-900/50 rounded px-2.5 py-1.5 text-emerald-400 focus:outline-none focus:border-emerald-500"
/>
<span className="text-[10px] text-gray-500">+{tpPips} pips (1:{riskReward} RR)</span>
</div>
</div>
{/* Execute Button */}
<button
onClick={handleSubmit}
disabled={isSubmitting}
className={`w-full py-2.5 rounded-lg font-bold text-xs tracking-wider uppercase transition shadow-lg flex items-center justify-center gap-2 ${
orderType === "BUY"
? "bg-accentGreen hover:bg-emerald-500 text-black shadow-emerald-500/20"
: "bg-accentRed hover:bg-red-600 text-white shadow-red-500/20"
} ${isSubmitting ? "opacity-50 cursor-not-allowed" : "active:scale-95"}`}
>
{isSubmitting ? (
<>
<RefreshCw className="w-3.5 h-3.5 animate-spin" /> EXECUTING ON EXNESS...
</>
) : (
`🚀 EXECUTE ${orderType} XAUUSD (${lotSize} LOT)`
)}
</button>
</div>
);
};