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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user