#!/usr/bin/env python3
"""
Base Exchange Interface

Abstract base class defining the interface for exchange adapters.
All exchange implementations must implement these methods.
"""

from abc import ABC, abstractmethod
from typing import Optional, Dict, Any, List
from dataclasses import dataclass


@dataclass
class Ticker:
    """Ticker data."""
    last: float
    bid: float
    ask: float
    volume_24h: float
    high_24h: float
    low_24h: float


@dataclass
class OrderBook:
    """Order book data."""
    bids: List[Dict[str, float]]  # [{'price': float, 'size': float}, ...]
    asks: List[Dict[str, float]]


@dataclass
class Candle:
    """OHLCV candle data."""
    timestamp: float
    open: float
    high: float
    low: float
    close: float
    volume: float


class BaseExchange(ABC):
    """Abstract base class for exchange adapters."""
    
    @abstractmethod
    async def fetch_ticker(self, symbol: str) -> Ticker:
        """Fetch current ticker data."""
        pass
    
    @abstractmethod
    async def get_orderbook(self, symbol: str, limit: int = 10) -> OrderBook:
        """Fetch order book."""
        pass
    
    @abstractmethod
    async def get_candles(
        self,
        symbol: str,
        timeframe: str = '1m',
        count: int = 100
    ) -> List[Candle]:
        """Fetch candlestick data."""
        pass
    
    @abstractmethod
    async def get_balance(self) -> Dict[str, float]:
        """Fetch account balances."""
        pass
    
    @abstractmethod
    async def buy(
        self,
        symbol: str,
        amount: float,
        price: Optional[float] = None,
        order_type: str = 'market'
    ) -> Any:
        """Place a buy order."""
        pass
    
    @abstractmethod
    async def sell(
        self,
        symbol: str,
        amount: float,
        price: Optional[float] = None,
        order_type: str = 'market'
    ) -> Any:
        """Place a sell order."""
        pass
    
    @abstractmethod
    async def cancel_order(self, order_id: str) -> bool:
        """Cancel an open order."""
        pass
    
    @abstractmethod
    async def get_recent_volume(
        self,
        symbol: str,
        window_minutes: int = 60
    ) -> Dict[str, Any]:
        """Get recent volume statistics."""
        pass
