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:
dekun
2026-07-14 12:49:03 +08:00
parent 036501b70c
commit 9e0d89bd01
8 changed files with 148 additions and 19 deletions
+17
View File
@@ -69,6 +69,23 @@ def suggest_contracts_from_notional(
return float(notional) / (float(entry) * float(contract_size))
def floor_contracts_to_precision(contracts: float, decimals: int) -> float:
"""按交易所张数精度向下取整,避免建议张数超过可用保证金."""
import math
raw = float(contracts or 0.0)
if raw <= 0:
return 0.0
try:
d = int(decimals)
except (TypeError, ValueError):
d = 0
if d <= 0:
return float(math.floor(raw + 1e-12))
scale = 10**d
return math.floor(raw * scale + 1e-12) / scale
def build_perp_options_preview(
*,
direction: str,