跳转至

市场数据模型

基础模型

cryptoservice.models.market_ticker.BaseMarketTicker(symbol: str, last_price: Decimal) dataclass

市场行情基础数据类.

ATTRIBUTE DESCRIPTION
symbol

交易对

TYPE: str

last_price

最新价格

TYPE: Decimal

现货行情

cryptoservice.models.market_ticker.SymbolTicker(symbol: str, last_price: Decimal) dataclass

Bases: BaseMarketTicker

单个交易币的行情数据类.

ATTRIBUTE DESCRIPTION
symbol

交易对

TYPE: str

last_price

最新价格

TYPE: Decimal

24小时行情

cryptoservice.models.market_ticker.DailyMarketTicker(symbol: str, last_price: Decimal, price_change: Decimal, price_change_percent: Decimal, volume: Decimal, quote_volume: Decimal, weighted_avg_price: Decimal, prev_close_price: Decimal, bid_price: Decimal, ask_price: Decimal, bid_qty: Decimal, ask_qty: Decimal, open_price: Decimal, high_price: Decimal, low_price: Decimal, open_time: int, close_time: int, first_id: int, last_id: int, count: int) dataclass

Bases: BaseMarketTicker

24小时行情数据类.

ATTRIBUTE DESCRIPTION
symbol

交易对

TYPE: str

last_price

最新价格

TYPE: Decimal

price_change

价格变动

TYPE: Decimal

price_change_percent

价格变动百分比

TYPE: Decimal

volume

成交量

TYPE: Decimal

quote_volume

成交额

TYPE: Decimal

weighted_avg_price

加权平均价

TYPE: Decimal

prev_close_price

前收盘价

TYPE: Decimal

bid_price

买一价

TYPE: Decimal

ask_price

卖一价

TYPE: Decimal

bid_qty

买一量

TYPE: Decimal

ask_qty

卖一量

TYPE: Decimal

open_price

开盘价

TYPE: Decimal

high_price

最高价

TYPE: Decimal

low_price

最低价

TYPE: Decimal

open_time

开盘时间

TYPE: int

close_time

收盘时间

TYPE: int

first_id

第一个ID

TYPE: int

last_id

最后一个ID

TYPE: int

count

计数

TYPE: int

K线行情

cryptoservice.models.market_ticker.KlineMarketTicker(symbol: str, last_price: Decimal, open_price: Decimal, high_price: Decimal, low_price: Decimal, volume: Decimal, close_time: int) dataclass

Bases: BaseMarketTicker

K线行情数据类.

ATTRIBUTE DESCRIPTION
symbol

交易对

TYPE: str

last_price

最新价格

TYPE: Decimal

open_price

开盘价

TYPE: Decimal

high_price

最高价

TYPE: Decimal

low_price

最低价

TYPE: Decimal

volume

成交量

TYPE: Decimal

close_time

收盘时间

TYPE: int

K线数据索引

cryptoservice.models.market_ticker.KlineIndex

K线数据索引定义

ATTRIBUTE DESCRIPTION
OPEN_TIME

开盘时间

OPEN

开盘价

HIGH

最高价

LOW

最低价

CLOSE

收盘价

VOLUME

成交量

CLOSE_TIME

收盘时间

QUOTE_VOLUME

成交额

TRADES_COUNT

成交笔数

TAKER_BUY_VOLUME

买方成交量

TAKER_BUY_QUOTE_VOLUME

买方成交额

IGNORE

忽略

永续合约行情

cryptoservice.models.market_ticker.PerpetualMarketTicker(symbol: str, open_time: int, raw_data: List[Any])

永续合约市场数据模型.

轻量级实现,使用 slots 来优化内存使用.

ATTRIBUTE DESCRIPTION
symbol

str # 交易对名称

open_time

int # K线开始时间戳(毫秒)

raw_data

List[Any] # 原始K线数据

Source code in src/cryptoservice/models/market_ticker.py
def __init__(self, symbol: str, open_time: int, raw_data: List[Any]):
    self.symbol = symbol
    self.open_time = open_time
    self.raw_data = raw_data

Functions

from_binance_futures(symbol: str, kline: List[Any]) -> PerpetualMarketTicker classmethod

从 Binance 永续合约K线数据创建实例.

PARAMETER DESCRIPTION
symbol

交易对名称

TYPE: str

kline

Binance K线数据列表 [ Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore

TYPE: List[Any]

Source code in src/cryptoservice/models/market_ticker.py
@classmethod
def from_binance_futures(cls, symbol: str, kline: List[Any]) -> "PerpetualMarketTicker":
    """从 Binance 永续合约K线数据创建实例.

    Args:
        symbol: 交易对名称
        kline: Binance K线数据列表 [
            Open time,
            Open,
            High,
            Low,
            Close,
            Volume,
            Close time,
            Quote asset volume,
            Number of trades,
            Taker buy base asset volume,
            Taker buy quote asset volume,
            Ignore
        ]
    """
    return cls(symbol=symbol, open_time=kline[KlineIndex.OPEN_TIME], raw_data=kline)