"""交易所策略适配器接口(各所 app 注入 ccxt 实现)."""
from __future__ import annotations

from typing import Any, Optional, Protocol


class StrategyExchangeAdapter(Protocol):
    exchange_key: str

    def normalize_symbol(self, raw: str) -> str: ...

    def normalize_exchange_symbol(self, symbol: str) -> str: ...

    def get_mark_price(self, symbol: str) -> Optional[float]: ...

    def get_position(self, exchange_symbol: str, direction: str) -> dict[str, Any]:
        """返回 {contracts, entry_price, leverage?}."""
        ...

    def amount_to_precision(self, exchange_symbol: str, amount: float) -> Optional[float]: ...

    def price_to_precision(self, exchange_symbol: str, price: float) -> Optional[float]: ...

    def market_add(
        self, exchange_symbol: str, direction: str, amount: float, leverage: int
    ) -> dict[str, Any]: ...

    def limit_add(
        self,
        exchange_symbol: str,
        direction: str,
        amount: float,
        price: float,
        leverage: int,
    ) -> dict[str, Any]: ...

    def cancel_order(self, exchange_symbol: str, order_id: str) -> None: ...

    def replace_position_tpsl(
        self,
        exchange_symbol: str,
        direction: str,
        stop_loss: float,
        take_profit: float,
        order_monitor_row: Any = None,
    ) -> None: ...

    def ensure_live_ready(self) -> tuple[bool, str]: ...
