"""Pure exchange-filter rounding. Quantity floors to step_size (never overshoot the intended size); price
rounds to the nearest tick; min-notional is the exchange's hard floor (~5 USDT on Binance USDⓈ-M)."""
from __future__ import annotations

import math

from fxhnt.ports.crypto_exchange import SymbolFilter


def round_qty(qty: float, f: SymbolFilter) -> float:
    if f.step_size <= 0:
        return qty
    steps = math.floor(abs(qty) / f.step_size + 1e-9)
    return round(steps * f.step_size, 12)


def round_price(price: float, f: SymbolFilter) -> float:
    if f.tick_size <= 0:
        return price
    ticks = round(price / f.tick_size)
    return round(ticks * f.tick_size, 12)


def meets_min_notional(qty: float, price: float, f: SymbolFilter) -> bool:
    return abs(qty) * price >= f.min_notional
