feat: paper frontend use aggTrade WS for real-time price (every tick instead of 1s)

This commit is contained in:
root 2026-02-28 12:30:11 +00:00
parent 95b45d0f07
commit 1d2304261b

View File

@ -120,15 +120,15 @@ function ActivePositions() {
f(); const iv = setInterval(f, 10000); return () => clearInterval(iv); f(); const iv = setInterval(f, 10000); return () => clearInterval(iv);
}, []); }, []);
// WebSocket实时价格 // WebSocket实时价格aggTrade逐笔成交
useEffect(() => { useEffect(() => {
const streams = ["btcusdt", "ethusdt", "xrpusdt", "solusdt"].map(s => `${s}@markPrice@1s`).join("/"); const streams = ["btcusdt", "ethusdt", "xrpusdt", "solusdt"].map(s => `${s}@aggTrade`).join("/");
const ws = new WebSocket(`wss://fstream.binance.com/stream?streams=${streams}`); const ws = new WebSocket(`wss://fstream.binance.com/stream?streams=${streams}`);
ws.onmessage = (e) => { ws.onmessage = (e) => {
try { try {
const msg = JSON.parse(e.data); const msg = JSON.parse(e.data);
if (msg.data) { if (msg.data) {
const sym = msg.data.s; // e.g. "BTCUSDT" const sym = msg.data.s;
const price = parseFloat(msg.data.p); const price = parseFloat(msg.data.p);
if (sym && price > 0) setWsPrices(prev => ({ ...prev, [sym]: price })); if (sym && price > 0) setWsPrices(prev => ({ ...prev, [sym]: price }));
} }