"""Stream subscription parameter models for the `/subscribe` endpoint.
Each model serializes (via `.dict()`) to the `{ "type": "<stream>", ...params }`
object the server expects. `chain_id` is never sent — the gateway injects it from
the connection host. Subaccounts are normalized to lowercase hex.
"""
from typing import Optional, Union
from pydantic import field_validator
from nado_protocol.utils.model import NadoBaseModel
[docs]class TradeStream(NadoBaseModel):
type: str = "trade"
product_id: int
[docs]class BestBidOfferStream(NadoBaseModel):
type: str = "best_bid_offer"
product_id: int
[docs]class BookDepthStream(NadoBaseModel):
type: str = "book_depth"
product_id: int
[docs]class FillStream(NadoBaseModel):
type: str = "fill"
subaccount: str
product_id: Optional[int] = None
@field_validator("subaccount")
@classmethod
def _lower(cls, v: str) -> str:
return v.lower()
[docs]class PositionChangeStream(NadoBaseModel):
type: str = "position_change"
subaccount: str
product_id: Optional[int] = None
@field_validator("subaccount")
@classmethod
def _lower(cls, v: str) -> str:
return v.lower()
[docs]class OrderUpdateStream(NadoBaseModel):
type: str = "order_update"
subaccount: str
product_id: Optional[int] = None
@field_validator("subaccount")
@classmethod
def _lower(cls, v: str) -> str:
return v.lower()
[docs]class LiquidationStream(NadoBaseModel):
type: str = "liquidation"
product_id: Optional[int] = None
[docs]class LatestCandlestickStream(NadoBaseModel):
type: str = "latest_candlestick"
product_id: int
granularity: int
[docs]class FundingPaymentStream(NadoBaseModel):
type: str = "funding_payment"
product_id: int
[docs]class FundingRateStream(NadoBaseModel):
type: str = "funding_rate"
product_id: Optional[int] = None
[docs]class AllBboStream(NadoBaseModel):
type: str = "all_bbo"
StreamSubscription = Union[
TradeStream,
BestBidOfferStream,
BookDepthStream,
FillStream,
PositionChangeStream,
OrderUpdateStream,
LiquidationStream,
LatestCandlestickStream,
FundingPaymentStream,
FundingRateStream,
AllBboStream,
]