Align hedge-plan perp contract precision with exchange and show TP/SL USDT PnL.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,10 +10,12 @@ from jinja2 import ChoiceLoader, FileSystemLoader
|
||||
from lib.hedge_plan.hedge_plan_calc_lib import (
|
||||
build_options_options_preview,
|
||||
build_perp_options_preview,
|
||||
floor_contracts_to_precision,
|
||||
gate_status,
|
||||
option_premium_total,
|
||||
suggest_contracts_from_notional,
|
||||
)
|
||||
from lib.hub.hub_calculator_market_lib import amount_decimals_from_exchange
|
||||
from lib.trade.position_sizing_lib import (
|
||||
compute_full_margin_sizing,
|
||||
load_position_sizing_mode,
|
||||
@@ -305,6 +307,11 @@ def _fetch_perp_market(cfg: dict[str, Any], base: str) -> tuple[dict[str, Any],
|
||||
entry = float(mark or last or 0)
|
||||
sizing = None
|
||||
suggest_contracts = None
|
||||
amount_precision = 4
|
||||
try:
|
||||
amount_precision = int(amount_decimals_from_exchange(ex, sym))
|
||||
except Exception:
|
||||
amount_precision = 4
|
||||
if available is not None and entry > 0:
|
||||
sizing, _serr = compute_full_margin_sizing(
|
||||
symbol=sym,
|
||||
@@ -316,11 +323,20 @@ def _fetch_perp_market(cfg: dict[str, Any], base: str) -> tuple[dict[str, Any],
|
||||
funds_decimals=int(cfg.get("funds_decimals") or 2),
|
||||
)
|
||||
if sizing:
|
||||
suggest_contracts = suggest_contracts_from_notional(
|
||||
raw_contracts = suggest_contracts_from_notional(
|
||||
notional=float(sizing["notional_value"]),
|
||||
entry=entry,
|
||||
contract_size=cs,
|
||||
)
|
||||
# 优先走交易所 amount_to_precision;失败则按精度位数向下取整
|
||||
suggest_contracts = None
|
||||
try:
|
||||
precise = float(ex.amount_to_precision(sym, raw_contracts))
|
||||
if precise > raw_contracts + 1e-12:
|
||||
precise = floor_contracts_to_precision(raw_contracts, amount_precision)
|
||||
suggest_contracts = precise
|
||||
except Exception:
|
||||
suggest_contracts = floor_contracts_to_precision(raw_contracts, amount_precision)
|
||||
|
||||
return {
|
||||
"exchange_symbol": sym,
|
||||
@@ -331,7 +347,11 @@ def _fetch_perp_market(cfg: dict[str, Any], base: str) -> tuple[dict[str, Any],
|
||||
"contract_size": cs,
|
||||
"available_usdt": available,
|
||||
"full_margin_sizing": sizing,
|
||||
"suggest_contracts": round(suggest_contracts, 6) if suggest_contracts is not None else None,
|
||||
"suggest_contracts": suggest_contracts,
|
||||
"amount_precision": amount_precision,
|
||||
"unit_quote": "USDT",
|
||||
"unit_contracts": "合约张",
|
||||
"unit_note": "价格单位 USDT;张数=交易所永续合约张(与下单精度一致);名义≈张数×面值×价格",
|
||||
"entry_ref": entry or None,
|
||||
}, None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user