{s.label}
);
}
/* ─── Parse JSON from API response ─── */
function parseAnalysis(text) {
try {
const clean = text.replace(/```json|```/g, "").trim();
return JSON.parse(clean);
} catch {
return null;
}
}
/* ─── Main App ─── */
export default function StockTA() {
const [symbol, setSymbol] = useState("");
const [price, setPrice] = useState("");
const [loading, setLoading] = useState(false);
const [analysis, setAnalysis] = useState(null);
const [chartData, setChartData] = useState([]);
const [indicators, setIndicators] = useState(null);
const [error, setError] = useState("");
const POPULAR = ["RELIANCE", "TCS", "NIFTY 50", "HDFCBANK", "INFY", "WIPRO", "ICICIBANK", "ADANIENT", "BAJFINANCE", "SBIN", "TATAMOTORS", "MARUTI"];
const runAnalysis = useCallback(async () => {
const sym = symbol.trim().toUpperCase();
const basePrice = parseFloat(price);
if (!sym) { setError("স্টক সিম্বল বা নাম লিখুন"); return; }
if (!basePrice || basePrice <= 0) { setError("সঠিক মূল্য লিখুন"); return; }
setError(""); setLoading(true); setAnalysis(null);
// Simulate price data
const data = genCandles(basePrice, 60);
setChartData(data);
const rsi = computeRSI(data);
const ema20 = computeEMA(data, 20);
const ema50 = computeEMA(data, 50);
const macd = computeMACD(data);
const support = +(basePrice * 0.955).toFixed(2);
const resistance = +(basePrice * 1.055).toFixed(2);
const change1d = +((data[data.length - 1].close - data[data.length - 2].close) / data[data.length - 2].close * 100).toFixed(2);
setIndicators({ rsi, ema20, ema50, macd, support, resistance, change1d, basePrice });
const prompt = `You are an expert Indian stock market technical analyst. Analyze the following stock and provide COMPREHENSIVE technical analysis in BENGALI LANGUAGE only.
Stock: ${sym}
Current Price: ₹${basePrice}
RSI (14): ${rsi}
EMA 20: ₹${ema20}
EMA 50: ₹${ema50}
MACD: ${macd}
Support: ₹${support}
Resistance: ₹${resistance}
1-Day Change: ${change1d}%
Respond ONLY in this exact JSON format (no markdown, no extra text):
{
"signal": "BUY" or "SELL" or "NEUTRAL" or "STRONG_BUY" or "STRONG_SELL",
"summary": "2-3 sentence Bengali summary of overall market condition for this stock",
"trend": "Bengali analysis of current trend (bullish/bearish/sideways) with reasoning - 3-4 sentences",
"rsi_analysis": "Bengali RSI interpretation - what does ${rsi} mean for this stock - 2-3 sentences",
"moving_avg": "Bengali analysis of EMA20 vs EMA50 crossover and what it means - 2-3 sentences",
"macd_analysis": "Bengali MACD interpretation - ${macd} value meaning - 2-3 sentences",
"support_resistance": "Bengali analysis of support ₹${support} and resistance ₹${resistance} levels - 2-3 sentences",
"volume_analysis": "Bengali volume trend analysis - 2 sentences",
"risk": "Bengali risk assessment - what traders should watch out for - 2-3 sentences",
"targets": {
"short_term": "₹XXX (Bengali reasoning)",
"medium_term": "₹XXX (Bengali reasoning)",
"stop_loss": "₹XXX (Bengali reasoning)"
},
"recommendation": "Final Bengali recommendation paragraph - 3-4 sentences including whether to buy/sell/hold, at what levels, and key conditions"
}
IMPORTANT: Every single value must be in BENGALI language. Only ₹ amounts can use numbers.`;
try {
const resp = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "claude-sonnet-4-20250514",
max_tokens: 1000,
messages: [{ role: "user", content: prompt }]
})
});
const data2 = await resp.json();
const rawText = data2.content?.map(b => b.text || "").join("") || "";
const parsed = parseAnalysis(rawText);
if (parsed) {
setAnalysis(parsed);
} else {
setError("বিশ্লেষণ পার্স করতে সমস্যা। আবার চেষ্টা করুন।");
}
} catch (e) {
setError("নেটওয়ার্ক সমস্যা। আবার চেষ্টা করুন।");
} finally {
setLoading(false);
}
}, [symbol, price]);
/* ─── STYLES ─── */
const S = {
root: {
background: "#070d1a",
minHeight: "100vh",
fontFamily: "'Noto Sans Bengali', 'Noto Sans', sans-serif",
color: "#d0daf0",
padding: "0 0 40px"
},
topbar: {
background: "linear-gradient(135deg, #0a1628 0%, #0f1f3d 100%)",
borderBottom: "1px solid #1e3060",
padding: "14px 24px",
display: "flex", alignItems: "center", gap: 14
},
logo: {
fontSize: 22, fontWeight: 900,
background: "linear-gradient(90deg, #f0a500, #ffcc44)",
WebkitBackgroundClip: "text", WebkitTextFillColor: "transparent"
},
subtitle: { color: "#5577aa", fontSize: 12, marginTop: 2 },
live: {
marginLeft: "auto", display: "flex", alignItems: "center", gap: 6,
fontSize: 11, color: "#44ee88"
},
dot: {
width: 8, height: 8, borderRadius: "50%",
background: "#22cc66",
boxShadow: "0 0 6px #22cc66",
animation: "pulse 1.5s ease-in-out infinite"
},
body: { padding: "20px 20px" },
card: {
background: "#0c1526",
border: "1px solid #1a2d50",
borderRadius: 10,
marginBottom: 16
},
cardHead: {
padding: "12px 18px",
borderBottom: "1px solid #1a2d50",
display: "flex", alignItems: "center", gap: 10,
fontSize: 13, fontWeight: 700, color: "#8ab4e8"
},
cardBody: { padding: "16px 18px" },
inputRow: {
display: "flex", gap: 10, flexWrap: "wrap", alignItems: "flex-end"
},
inputGrp: { display: "flex", flexDirection: "column", gap: 6, flex: 1, minWidth: 160 },
label: { fontSize: 11, color: "#5577aa", fontWeight: 600, textTransform: "uppercase", letterSpacing: 0.5 },
input: {
background: "#0a1524", border: "1.5px solid #1e3a60",
borderRadius: 6, padding: "10px 14px",
color: "#e0ecff", fontSize: 14, fontFamily: "inherit",
outline: "none", transition: "border-color 0.2s"
},
btn: {
padding: "10px 28px", background: "linear-gradient(135deg, #1a56c4, #0e3a8c)",
color: "#e8f0ff", border: "none", borderRadius: 6,
fontFamily: "inherit", fontSize: 14, fontWeight: 700,
cursor: "pointer", letterSpacing: 0.3,
boxShadow: "0 4px 16px #1a56c444",
transition: "all 0.2s", minWidth: 140
},
chip: {
padding: "4px 12px", background: "#0f1e3a",
border: "1px solid #1e3a60", borderRadius: 20,
fontSize: 11, color: "#6688bb", cursor: "pointer",
transition: "all 0.15s", fontFamily: "monospace"
},
sectionTitle: {
fontSize: 12, fontWeight: 800, letterSpacing: 1,
color: "#4477bb", textTransform: "uppercase", marginBottom: 12
},
analysisSect: {
background: "#091422",
border: "1px solid #142840",
borderRadius: 8,
padding: "14px 16px",
marginBottom: 12
},
sectLabel: {
fontSize: 11, color: "#4488cc", fontWeight: 700,
textTransform: "uppercase", letterSpacing: 0.8,
marginBottom: 8, display: "flex", alignItems: "center", gap: 6
},
sectText: {
fontSize: 13.5, lineHeight: 1.75, color: "#c0d4f0"
},
targRow: {
display: "flex", gap: 10, flexWrap: "wrap", marginTop: 8
},
targCard: (color) => ({
flex: 1, minWidth: 120,
background: `${color}11`,
border: `1px solid ${color}44`,
borderRadius: 6, padding: "10px 14px",
}),
targLabel: { fontSize: 10, color: "#7799bb", fontWeight: 700, textTransform: "uppercase" },
targVal: { fontSize: 13, color: "#d0e8ff", marginTop: 4, lineHeight: 1.5 },
indRow: {
display: "grid",
gridTemplateColumns: "repeat(auto-fill, minmax(110px, 1fr))",
gap: 10, marginBottom: 16
},
indCard: (up) => ({
background: up ? "#061a0e" : "#1a0606",
border: `1px solid ${up ? "#1a5c2a" : "#5c1a1a"}`,
borderRadius: 7, padding: "10px 12px",
}),
indLabel: { fontSize: 10, color: "#6688aa", fontWeight: 700, marginBottom: 4 },
indVal: (up) => ({ fontSize: 15, fontWeight: 800, color: up ? "#44ee88" : "#ff5555" }),
skeleton: {
background: "linear-gradient(90deg, #0c1a30 25%, #111e38 50%, #0c1a30 75%)",
backgroundSize: "200% 100%",
borderRadius: 6, height: 16,
animation: "shimmer 1.4s ease-in-out infinite"
}
};
return (
{/* TOP BAR */}
);
}
📈 শেয়ার বিশ্লেষণ
Indian Stock Market · Technical Analysis · AI-Powered
NSE · BSE · লাইভ
{/* ── INPUT CARD ── */}
{error &&
{/* ── LOADING SKELETON ── */}
{loading && (
)}
{/* ── RESULTS ── */}
{analysis && indicators && !loading && (
<>
{/* Stock Header */}
{/* Indicators Row */}
`₹${v.toLocaleString("en-IN")}`} />
[`₹${v.toLocaleString("en-IN")}`, "মূল্য"]}
/>
{/* RSI Gauges */}
p > 0.7 ? "#ff5555" : p < 0.3 ? "#44ee88" : "#f0a500"} />
p > 0.5 ? "#44ee88" : "#ff5555"} />
p > 0.8 ? "#ff5555" : p < 0.2 ? "#44ee88" : "#f0a500"} />
{/* Analysis Sections */}
{/* Disclaimer */}
)}
🔍 স্টক বিশ্লেষণ করুন
স্টক সিম্বল / নাম
setSymbol(e.target.value)}
onKeyDown={e => e.key === "Enter" && runAnalysis()}
/>
বর্তমান মূল্য (₹)
setPrice(e.target.value)}
onKeyDown={e => e.key === "Enter" && runAnalysis()}
/>
⚠ {error}
}
{/* Popular chips */}
জনপ্রিয়:
{POPULAR.map(s => (
setSymbol(s)}
>{s}
))}
AI বিশ্লেষণ চলছে — {symbol.toUpperCase()} এর জন্য বাংলায় রিপোর্ট তৈরি হচ্ছে…
{[100, 80, 90, 70, 85].map((w, i) => (
))}
{symbol.toUpperCase()}
NSE · ইন্ডিয়ান শেয়ার বাজার
= 0 ? "#44ee88" : "#ff5555" }}>
₹{indicators.basePrice.toLocaleString("en-IN")}
= 0 ? "#0a3020" : "#300a0a",
color: indicators.change1d >= 0 ? "#44ee88" : "#ff5555",
fontSize: 14, fontWeight: 700
}}>
{indicators.change1d >= 0 ? "▲" : "▼"} {Math.abs(indicators.change1d)}%
{[
{ label: "RSI (14)", val: indicators.rsi, up: indicators.rsi < 70 && indicators.rsi > 30, unit: "" },
{ label: "EMA 20", val: `₹${indicators.ema20.toLocaleString("en-IN")}`, up: indicators.basePrice > indicators.ema20 },
{ label: "EMA 50", val: `₹${indicators.ema50.toLocaleString("en-IN")}`, up: indicators.basePrice > indicators.ema50 },
{ label: "MACD", val: indicators.macd, up: indicators.macd > 0 },
{ label: "সাপোর্ট", val: `₹${indicators.support.toLocaleString("en-IN")}`, up: true },
{ label: "রেজিস্টেন্স", val: `₹${indicators.resistance.toLocaleString("en-IN")}`, up: false },
].map(({ label, val, up }) => (
))}
{/* Chart */}
{label}
{val}
📊 মূল্য চার্ট (৬০ দিন সিমুলেশন)
🎯 টেকনিক্যাল ইন্ডিকেটর গেজ
{indicators.rsi > 70 ? "অতিরিক্ত কেনা" : indicators.rsi < 30 ? "অতিরিক্ত বেচা" : "স্বাভাবিক"}
{indicators.macd > 0 ? "বুলিশ মোমেন্টাম" : "বেয়ারিশ মোমেন্টাম"}
{indicators.basePrice > (indicators.support + indicators.resistance) / 2 ? "রেজিস্টেন্সের কাছে" : "সাপোর্টের কাছে"}
🧠 AI বিশ্লেষণ — বাংলায়
{/* Summary */}
{/* Grid 2 col */}
{/* Risk */}
{/* Recommendation */}
📋 সারসংক্ষেপ
{analysis.summary}
{[
{ icon: "📈", key: "trend", label: "ট্রেন্ড বিশ্লেষণ" },
{ icon: "📉", key: "rsi_analysis", label: "RSI বিশ্লেষণ" },
{ icon: "〰️", key: "moving_avg", label: "মুভিং অ্যাভারেজ" },
{ icon: "⚡", key: "macd_analysis", label: "MACD বিশ্লেষণ" },
{ icon: "🔒", key: "support_resistance", label: "সাপোর্ট / রেজিস্টেন্স" },
{ icon: "📦", key: "volume_analysis", label: "ভলিউম বিশ্লেষণ" },
].map(({ icon, key, label }) => (
))}
{/* Targets */}
{icon} {label}
{analysis[key]}
🎯 মূল্য লক্ষ্যমাত্রা
স্বল্পমেয়াদী লক্ষ্য
{analysis.targets?.short_term}
মধ্যমেয়াদী লক্ষ্য
{analysis.targets?.medium_term}
স্টপ লস
{analysis.targets?.stop_loss}
⚠️ ঝুঁকি মূল্যায়ন
{analysis.risk}
✅ চূড়ান্ত পরামর্শ
{analysis.recommendation}
⚠️ ডিসক্লেইমার: এই বিশ্লেষণ শুধুমাত্র শিক্ষামূলক উদ্দেশ্যে। এটি কোনো আর্থিক পরামর্শ নয়।
বিনিয়োগের আগে নিজে গবেষণা করুন এবং প্রয়োজনে বিশেষজ্ঞের পরামর্শ নিন।
>
)}
{/* Welcome state */}
{!analysis && !loading && (
📊
স্টক সিম্বল ও মূল্য লিখে বিশ্লেষণ শুরু করুন
AI দ্বারা সম্পূর্ণ বাংলায় টেকনিক্যাল বিশ্লেষণ পাবেন
No comments:
Post a Comment