from typing_extensions import Literal, AsyncIterable
from dataclasses import dataclass
from mexc.spot.streams.core import StreamsMixin
from mexc.spot.streams.core.proto import PublicLimitDepthsV3Api

def channel_name(symbol: str, level: Literal[5, 10, 20]):
  return f'spot@public.limit.depth.v3.api.pb@{symbol}@{level}'
  
@dataclass
class Depth(StreamsMixin):
  async def depth(self, symbol: str, level: Literal[5, 10, 20] = 5) -> AsyncIterable[PublicLimitDepthsV3Api]:
    """Subscribe to the order book for a given symbol.
    
    - `symbol`: The symbol being traded, e.g. `BTCUSDT`.
    - `level`: The level of the order book (default: 5).

    > [MEXC API docs](https://www.mexc.com/api-docs/spot-v3/websocket-market-streams#trade-streams)
    """
    async for proto in self.subscribe(channel_name(symbol, level)):
      if proto.public_limit_depths is not None:
        yield proto.public_limit_depths