@davoodmehraban89 / VELYQOR / commits / af39526
Fork 0

Intelligence, Advanced Charting & Trading Platform

feat(terminal): integrate manual paper positions and chart SL TP overlay

davoodmehraban89 committed Oct 14, 2026 at 22:41 UTC af3952612e2eab84e32ef6712620ac658ec87d6a
1 file changed +25 -3
apps/market-terminal/src/main.jsx
+25 -3
@@ -3,6 +3,7 @@ import {createRoot} from "react-dom/client";
3 import {createChart,CandlestickSeries,LineSeries,CrosshairMode} from "lightweight-charts";
4 import {normalizeHistoryResponse,normalizeStreamUpdate} from "../../../packages/market-feed/src/chart-adapter.mjs";
5 import "./style.css";
6 +import PaperTradingPanel from "./PaperTradingPanel.jsx";
7
8 const SYMBOLS=[
9 {value:"EUR_USD_ECB",label:"EUR/USD · نرخ مرجع بانک مرکزی اروپا"},
@@ -14,10 +15,11 @@ const WS_BASE=(import.meta.env.VITE_MARKET_WS_BASE||"").replace(/\/$/,"");
15 const allowedSymbol=(symbol)=>SYMBOLS.some(item=>item.value===symbol);
16 const number=(value)=>new Intl.NumberFormat("fa-IR",{maximumFractionDigits:6}).format(value);
17
17 -function ChartPane({model,lastTick,chartRef}){
18 +function ChartPane({model,lastTick,chartRef,paperPosition}){
19 const host=useRef(null);
20 const series=useRef(null);
21 const lastTime=useRef(null);
22 + const paperLines=useRef([]);
23 useEffect(()=>{
24 if(!host.current||!model)return;
25 const chart=createChart(host.current,{
@@ -43,11 +45,30 @@ function ChartPane({model,lastTick,chartRef}){
45 if(!newer)return;
46 try{series.current.update(lastTick);lastTime.current=value}catch{}
47 },[lastTick,model]);
48 + useEffect(()=>{
49 + const active=series.current;
50 + if(!active)return;
51 + for(const line of paperLines.current){try{active.removePriceLine(line)}catch{}}
52 + paperLines.current=[];
53 + if(!paperPosition||paperPosition.symbol!==model?.symbol)return;
54 + const thresholds=[
55 + {price:paperPosition.entryPrice,title:"ورود فرضی",color:"#dce6f3"},
56 + {price:paperPosition.stopPrice,title:"حد ضرر آزمایشی",color:"#ff8c88"},
57 + {price:paperPosition.takeProfitPrice,title:"حد سود آزمایشی",color:"#62dbc5"},
58 + ];
59 + for(const t of thresholds){
60 + if(Number.isFinite(t.price)&&t.price>0)paperLines.current.push(active.createPriceLine({
61 + price:t.price,color:t.color,lineWidth:1,lineStyle:2,axisLabelVisible:true,title:t.title
62 + }));
63 + }
64 + return ()=>{for(const line of paperLines.current){try{active.removePriceLine(line)}catch{}}paperLines.current=[]};
65 + },[paperPosition,model]);
66 return <div className="chart-frame" ref={host} role="img" aria-label={model?.kind==="candle"?"نمودار کندل منبع دارای مجوز":"نمودار خطی نرخ مرجع روزانه"} />;
67 }
68 function App(){
69 const [symbol,setSymbol]=useState("EUR_USD_ECB");
70 const [model,setModel]=useState(null);
71 + const [paperPosition,setPaperPosition]=useState(null);
72 const [status,setStatus]=useState("در انتظار دریافت تاریخچه...");
73 const [wsStatus,setWsStatus]=useState("غیرفعال: درگاه استریم هنوز منتشر نشده");
74 const [lastTick,setLastTick]=useState(null);
@@ -115,7 +136,7 @@ function App(){
136 <section className="main-column">
137 <div className="toolbar">
138 <label htmlFor="symbol">نماد</label>
118 - <select id="symbol" value={symbol} onChange={e=>setSymbol(e.target.value)}>
139 + <select id="symbol" value={symbol} onChange={e=>{setSymbol(e.target.value);setPaperPosition(null)}}>
140 {SYMBOLS.map(s=><option value={s.value} key={s.value}>{s.label}</option>)}
141 </select>
142 <span className="pill">{model?.kind==="candle"?"شمع‌های واقعی OHLC":"نمودار خطی · نرخ مرجع روزانه"}</span>
@@ -125,7 +146,7 @@ function App(){
146 <div><h2>{SYMBOLS.find(s=>s.value===symbol)?.label}</h2><p>{status}</p></div>
147 <div className="last-price">{close===null?"—":number(close)} <small>{model?.unit??""}</small></div>
148 </div>
128 - {model?<ChartPane model={model} lastTick={lastTick} chartRef={chartRef}/>:<div className="chart-empty">{status}</div>}
149 + {model?<ChartPane model={model} lastTick={lastTick} chartRef={chartRef} paperPosition={paperPosition}/>:<div className="chart-empty">{status}</div>}
150 </div>
151 <p className="license">نمودار با <a href="https://www.tradingview.com/" target="_blank" rel="noopener noreferrer">Lightweight Charts™ توسط TradingView</a> ساخته شده است. این محصول وابسته به TradingView نیست.</p>
152 </section>
@@ -137,6 +158,7 @@ function App(){
158 <div className="datum"><span>WebSocket</span><strong>{wsStatus}</strong></div>
159 <div className="notice"><strong>تفکیک الزامی داده‌ها</strong><p>نرخ مرجع ECB فقط در نمودار خطی دیده می‌شود. شمع‌ها صرفاً وقتی API داده OHLC واقعی با حق انتشار تأییدشده برگرداند ایجاد می‌شوند.</p></div>
160 <p className="small">{model?.attribution??"برای اطلاعات منبع به API رجوع کنید."}</p>
161 + <PaperTradingPanel key={symbol} symbol={symbol} onPositionChange={setPaperPosition} />
162 </aside>
163 </main>
164 </div>;