fix: показывать mark-to-market баланс (equity + unrealized PnL) как на бирже

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-09 15:12:45 +10:00
co-authored by Claude Opus 4.6
parent c8249b092e
commit 2e36837e80
+17 -13
View File
@@ -74,28 +74,34 @@ def format_status_report(cfg, conn) -> str:
total_equity = sum(a["equity"] for a in assets)
total_initial = cfg.initial_capital * len(assets) if assets else cfg.initial_capital
total_pnl = total_equity - total_initial
total_pct = (total_equity / total_initial - 1) * 100 if total_initial > 0 else 0
# Collect open positions and calculate unrealized PnL
open_positions = []
total_unrealized = 0.0
for a in assets:
pos = get_open_position(conn, a["ticker"])
if pos:
cur_price = _get_current_price(cfg, a["ticker"])
open_positions.append((a, pos, cur_price))
if cur_price:
total_unrealized += pos["pos_size"] * (cur_price - pos["entry_price"]) * pos["direction"]
total_balance = total_equity + total_unrealized
total_pnl = total_balance - total_initial
total_pct = (total_balance / total_initial - 1) * 100 if total_initial > 0 else 0
lines = ["\U0001f4ca <b>RemizovTrader</b>"]
lines.append("")
# --- Portfolio ---
lines.append(f"\U0001f4b0 <b>Портфель</b>")
lines.append(f" Капитал: <b>${total_equity:,.2f}</b> ({total_pct:+.1f}%)")
lines.append(f" Баланс: <b>${total_balance:,.2f}</b> ({total_pct:+.1f}%)")
lines.append(f" PnL: ${total_pnl:+,.2f}")
lines.append("")
# --- Open positions with unrealized PnL ---
open_positions = []
for a in assets:
pos = get_open_position(conn, a["ticker"])
if pos:
open_positions.append((a, pos))
if open_positions:
lines.append(f"\U0001f4c8 <b>Позиции</b> ({len(open_positions)}/{cfg.risk.max_open_positions})")
for a, pos in open_positions:
for a, pos, cur_price in open_positions:
d = "\U0001f7e2 LONG" if pos["direction"] == 1 else "\U0001f534 SHORT"
entry = pos["entry_price"]
stop = pos["stop_price"]
@@ -103,8 +109,6 @@ def format_status_report(cfg, conn) -> str:
pos_size = pos["pos_size"]
risk_pct = abs(entry - stop) / entry * 100
# Fetch current price for unrealized PnL
cur_price = _get_current_price(cfg, a["ticker"])
if cur_price:
upnl = pos_size * (cur_price - entry) * pos["direction"]
upnl_pct = (cur_price / entry - 1) * 100 * pos["direction"]