fix: paper positions use Binance realtime price instead of signal_indicators
This commit is contained in:
parent
66810701fb
commit
d177d28498
@ -568,8 +568,20 @@ async def paper_positions(user: dict = Depends(get_current_user)):
|
|||||||
"tp1_price, tp2_price, sl_price, tp1_hit, status, atr_at_entry "
|
"tp1_price, tp2_price, sl_price, tp1_hit, status, atr_at_entry "
|
||||||
"FROM paper_trades WHERE status IN ('active','tp1_hit') ORDER BY entry_ts DESC"
|
"FROM paper_trades WHERE status IN ('active','tp1_hit') ORDER BY entry_ts DESC"
|
||||||
)
|
)
|
||||||
# 获取实时价格
|
# 从币安API获取实时价格
|
||||||
prices = {}
|
prices = {}
|
||||||
|
symbols_needed = list(set(r["symbol"] for r in rows))
|
||||||
|
if symbols_needed:
|
||||||
|
try:
|
||||||
|
async with httpx.AsyncClient(timeout=5) as client:
|
||||||
|
resp = await client.get("https://fapi.binance.com/fapi/v1/ticker/price")
|
||||||
|
if resp.status_code == 200:
|
||||||
|
for item in resp.json():
|
||||||
|
if item["symbol"] in symbols_needed:
|
||||||
|
prices[item["symbol"]] = float(item["price"])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
# fallback: 如果币安API失败,用signal_indicators
|
||||||
for r in rows:
|
for r in rows:
|
||||||
sym = r["symbol"]
|
sym = r["symbol"]
|
||||||
if sym not in prices:
|
if sym not in prices:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user