Split live positions from hedge plans; show option+perp net PnL after fees.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 16:32:13 +08:00
parent 5c95625817
commit 0b3dabbbd9
7 changed files with 446 additions and 12 deletions
+21
View File
@@ -50,6 +50,7 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
from lib.exchange.okx_options_lib import (
build_option_chain,
fetch_index_price,
fetch_option_positions,
options_header_balances,
place_option_limit_order,
quote_option_contract,
@@ -76,6 +77,10 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
"place_exchange_order": getattr(app_module, "place_exchange_order", None),
"close_exchange_order": getattr(app_module, "close_exchange_order", None),
"get_live_position_contracts": getattr(app_module, "get_live_position_contracts", None),
"get_live_position_exchange_metrics": getattr(
app_module, "get_live_position_exchange_metrics", None
),
"fetch_option_positions": fetch_option_positions,
"amount_to_precision": _amount_to_precision,
"build_option_chain": build_option_chain,
"options_header_balances": options_header_balances,
@@ -1117,6 +1122,22 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
conn.close()
return jsonify({"ok": True, "plans": plans})
@app.route("/api/hedge-plan/live-positions")
@lr
def api_hedge_live_positions():
"""当前持仓:期权+永续实时卡,组合净利已扣开平双边手续费."""
from lib.hedge_plan.hedge_plan_db import init_hedge_plan_tables
from lib.hedge_plan.hedge_plan_live_positions_lib import build_live_hedge_cards
conn = cfg["get_db"]()
try:
init_hedge_plan_tables(conn)
cards = build_live_hedge_cards(cfg, conn)
conn.commit()
finally:
conn.close()
return jsonify({"ok": True, "cards": cards})
@app.route("/api/hedge-plan/stats")
@lr
def api_hedge_stats():