fix: 模拟盘前端ActivePositions组件自行fetch config计算paper1R
This commit is contained in:
parent
31e6e19ea6
commit
8bd5f8fa84
@ -233,6 +233,12 @@ function LatestSignals() {
|
|||||||
// ─── 当前持仓 ────────────────────────────────────────────────────
|
// ─── 当前持仓 ────────────────────────────────────────────────────
|
||||||
|
|
||||||
function ActivePositions({ strategy }: { strategy: StrategyFilter }) {
|
function ActivePositions({ strategy }: { strategy: StrategyFilter }) {
|
||||||
|
const [paperRiskUsd, setPaperRiskUsd] = useState(200);
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try { const r = await authFetch("/api/paper/config"); if (r.ok) { const cfg = await r.json(); setPaperRiskUsd((cfg.initial_balance || 10000) * (cfg.risk_per_trade || 0.02)); } } catch {}
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
const [positions, setPositions] = useState<any[]>([]);
|
const [positions, setPositions] = useState<any[]>([]);
|
||||||
const [wsPrices, setWsPrices] = useState<Record<string, number>>({});
|
const [wsPrices, setWsPrices] = useState<Record<string, number>>({});
|
||||||
|
|
||||||
@ -294,8 +300,7 @@ function ActivePositions({ strategy }: { strategy: StrategyFilter }) {
|
|||||||
const fullR = riskDist > 0 ? (p.direction === "LONG" ? (currentPrice - entry) / riskDist : (entry - currentPrice) / riskDist) : 0;
|
const fullR = riskDist > 0 ? (p.direction === "LONG" ? (currentPrice - entry) / riskDist : (entry - currentPrice) / riskDist) : 0;
|
||||||
const tp1R = riskDist > 0 ? (p.direction === "LONG" ? ((p.tp1_price || 0) - entry) / riskDist : (entry - (p.tp1_price || 0)) / riskDist) : 0;
|
const tp1R = riskDist > 0 ? (p.direction === "LONG" ? ((p.tp1_price || 0) - entry) / riskDist : (entry - (p.tp1_price || 0)) / riskDist) : 0;
|
||||||
const unrealR = p.tp1_hit ? 0.5 * tp1R + 0.5 * fullR : fullR;
|
const unrealR = p.tp1_hit ? 0.5 * tp1R + 0.5 * fullR : fullR;
|
||||||
const paper1R = (config?.initial_balance || 10000) * (config?.risk_per_trade || 0.02);
|
const unrealUsdt = unrealR * paperRiskUsd;
|
||||||
const unrealUsdt = unrealR * paper1R;
|
|
||||||
return (
|
return (
|
||||||
<div key={p.id} className="px-3 py-2 bg-emerald-50/60">
|
<div key={p.id} className="px-3 py-2 bg-emerald-50/60">
|
||||||
<div className="flex items-center justify-between gap-2">
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
|||||||
@ -183,6 +183,12 @@ function LatestSignals() {
|
|||||||
// ─── 当前持仓 ────────────────────────────────────────────────────
|
// ─── 当前持仓 ────────────────────────────────────────────────────
|
||||||
|
|
||||||
function ActivePositions() {
|
function ActivePositions() {
|
||||||
|
const [paperRiskUsd, setPaperRiskUsd] = useState(200);
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try { const r = await authFetch("/api/paper/config"); if (r.ok) { const cfg = await r.json(); setPaperRiskUsd((cfg.initial_balance || 10000) * (cfg.risk_per_trade || 0.02)); } } catch {}
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
const [positions, setPositions] = useState<any[]>([]);
|
const [positions, setPositions] = useState<any[]>([]);
|
||||||
const [wsPrices, setWsPrices] = useState<Record<string, number>>({});
|
const [wsPrices, setWsPrices] = useState<Record<string, number>>({});
|
||||||
|
|
||||||
@ -231,8 +237,7 @@ function ActivePositions() {
|
|||||||
const fullR = riskDist > 0 ? (p.direction === "LONG" ? (currentPrice - entry) / riskDist : (entry - currentPrice) / riskDist) : 0;
|
const fullR = riskDist > 0 ? (p.direction === "LONG" ? (currentPrice - entry) / riskDist : (entry - currentPrice) / riskDist) : 0;
|
||||||
const tp1R = riskDist > 0 ? (p.direction === "LONG" ? ((p.tp1_price || 0) - entry) / riskDist : (entry - (p.tp1_price || 0)) / riskDist) : 0;
|
const tp1R = riskDist > 0 ? (p.direction === "LONG" ? ((p.tp1_price || 0) - entry) / riskDist : (entry - (p.tp1_price || 0)) / riskDist) : 0;
|
||||||
const unrealR = p.tp1_hit ? 0.5 * tp1R + 0.5 * fullR : fullR;
|
const unrealR = p.tp1_hit ? 0.5 * tp1R + 0.5 * fullR : fullR;
|
||||||
const paper1R = (config?.initial_balance || 10000) * (config?.risk_per_trade || 0.02);
|
const unrealUsdt = unrealR * paperRiskUsd;
|
||||||
const unrealUsdt = unrealR * paper1R;
|
|
||||||
return (
|
return (
|
||||||
<div key={p.id} className="px-3 py-2">
|
<div key={p.id} className="px-3 py-2">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user