fix: paper mode показывает DB equity вместо биржевого баланса
В paper mode позиции только в БД, биржа не задействована. Старый код показывал "в сделках $0.00" — вводило в заблуждение. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -696,24 +696,42 @@ def format_cycle_report(logs: list[str], cfg=None) -> str:
|
|||||||
dot = " \u00b7 "
|
dot = " \u00b7 "
|
||||||
lines.append(f"<i>\u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b: {dot.join(parts)}</i>")
|
lines.append(f"<i>\u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b: {dot.join(parts)}</i>")
|
||||||
|
|
||||||
# Balance line: in positions / free
|
# Balance line
|
||||||
if cfg is not None:
|
if cfg is not None:
|
||||||
try:
|
try:
|
||||||
from .core.spot import SpotExecutor
|
if cfg.mode == "paper":
|
||||||
spot = SpotExecutor(cfg.exchange, leverage=cfg.risk.leverage)
|
# Paper mode: show DB equity, not exchange balance
|
||||||
spot._ensure_markets()
|
from .state import get_db, init_db, get_all_assets
|
||||||
b = spot.exchange.fetch_balance()
|
conn = get_db()
|
||||||
# Use USDT if any futures assets, otherwise USDC
|
init_db(conn)
|
||||||
has_futures = any(a.market_type == "futures" for a in cfg.assets)
|
assets = get_all_assets(conn)
|
||||||
quote_coin = "USDT" if has_futures else "USDC"
|
in_pos = sum(
|
||||||
free_usdc = float(b.get(quote_coin, {}).get("free", 0) or 0)
|
1 for a in assets
|
||||||
total_balance = _get_exchange_balance(cfg)
|
if get_open_position(conn, a["ticker"]) is not None
|
||||||
if total_balance is not None:
|
) if assets else 0
|
||||||
in_positions = total_balance - free_usdc
|
conn.close()
|
||||||
|
total_eq = sum(a["equity"] for a in assets) if assets else 0
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append(f"\U0001f4b0 ${total_balance:,.2f}"
|
lines.append(f"\U0001f4b0 DB equity: ${total_eq:,.2f}"
|
||||||
f" \u2192 \u0432 \u0441\u0434\u0435\u043b\u043a\u0430\u0445 ${in_positions:,.2f}"
|
f" ({in_pos} paper-\u043f\u043e\u0437\u0438\u0446\u0438\u0439)"
|
||||||
f" | \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e ${free_usdc:,.2f}")
|
f" [paper mode]")
|
||||||
|
else:
|
||||||
|
from .core.spot import SpotExecutor
|
||||||
|
spot = SpotExecutor(cfg.exchange, leverage=cfg.risk.leverage)
|
||||||
|
spot._ensure_markets()
|
||||||
|
b = spot.exchange.fetch_balance()
|
||||||
|
has_futures = any(a.market_type == "futures" for a in cfg.assets)
|
||||||
|
quote_coin = "USDT" if has_futures else "USDC"
|
||||||
|
free_quote = float(b.get(quote_coin, {}).get("free", 0) or 0)
|
||||||
|
total_balance = _get_exchange_balance(cfg)
|
||||||
|
if total_balance is not None:
|
||||||
|
in_positions = total_balance - free_quote
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"\U0001f4b0 ${total_balance:,.2f}"
|
||||||
|
f" \u2192 \u0432 \u0441\u0434\u0435\u043b\u043a\u0430\u0445"
|
||||||
|
f" ${in_positions:,.2f}"
|
||||||
|
f" | \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e"
|
||||||
|
f" ${free_quote:,.2f}")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user