Skip to content

Data Models API

Auto-generated API documentation for StreamForge data models.


Kline

Kline

Bases: BaseModel

Normalized candlestick/kline data model.

Kline represents OHLC market data in a standardized format across all exchanges. It uses Pydantic for validation and supports multiple field aliases to handle different exchange data formats.

Attributes:

Name Type Description
source Optional[str]

Exchange name (e.g., 'Binance', 'Kraken', 'OKX')

symbol str

Trading pair symbol (e.g., 'BTCUSDT', 'BTC/USD')

timeframe str

Candle timeframe (e.g., '1m', '5m', '1h', '1d')

open_ts int

Opening timestamp in seconds (Unix epoch)

end_ts int

Closing timestamp in seconds (Unix epoch)

open float

Opening price

high float

Highest price during the period

low float

Lowest price during the period

close float

Closing price

volume float

Base asset volume traded

quote_volume Optional[float]

Quote asset volume traded (optional)

vwap Optional[float]

Volume-weighted average price (optional)

n_trades Optional[int]

Number of trades during the period (optional)

is_closed Optional[bool]

Whether the candle is closed/finalized (optional)

Examples:

>>> kline = Kline(
...     source="Binance",
...     symbol="BTCUSDT",
...     timeframe="1m",
...     open_ts=1609459200,
...     end_ts=1609459260,
...     open=29000.0,
...     high=29100.0,
...     low=28900.0,
...     close=29050.0,
...     volume=125.5,
...     is_closed=True
... )
>>> print(f"BTC closed at ${kline.close}")
BTC closed at $29050.0
Note

The model supports multiple field aliases (e.g., 's', 'symbol', 'ticker', 'pair') to handle different exchange data formats. Fields are automatically validated and converted to the standard format.

__eq__

__eq__(other: Any) -> bool

Compares Kline objects based on their open timestamp.

__lt__

__lt__(other: Any) -> bool

Compares Kline objects based on their open timestamp.

__gt__

__gt__(other: Any) -> bool

Compares Kline objects based on their open timestamp.

__sub__

__sub__(other: Any) -> int

Calculates the time difference in seconds between two Klines.


DataInput

DataInput dataclass

DataInput(type: str, symbols: list, timeframe: Optional[str], aggregate_list: Optional[List[str]] = list())

Configuration for a data stream subscription.

DataInput specifies what type of market data to stream from an exchange, including the symbols, timeframe, and any aggregation requirements.

Attributes:

Name Type Description
type str

Type of data stream (e.g., 'kline', 'trade', 'depth', 'ticker')

symbols list

List of trading pair symbols to subscribe to (e.g., ['BTCUSDT', 'ETHUSDT'])

timeframe Optional[str]

Timeframe interval for OHLC data (e.g., '1m', '5m', '1h', '1d')

aggregate_list Optional[List[str]]

Optional list of additional timeframes to aggregate to (e.g., ['5m', '15m', '1h'] when base is '1m')

Examples:

Basic kline stream:

>>> stream = DataInput(
...     type="kline",
...     symbols=["BTCUSDT"],
...     timeframe="1m"
... )

With aggregation:

>>> stream = DataInput(
...     type="kline",
...     symbols=["BTCUSDT", "ETHUSDT"],
...     timeframe="1m",
...     aggregate_list=["5m", "15m", "1h"]
... )
Note

The 'type' field determines which processor will handle the data. Supported types vary by exchange but commonly include: - 'kline', 'candle', 'ohlc': OHLC/candlestick data - 'trade': Individual trades - 'depth': Order book depth - 'ticker': Price ticker updates


Common Usage

Kline Model

The Kline dataclass represents OHLC/candlestick data:

from streamforge.base.normalize.ohlc.models.candle import Kline

kline = Kline(
    source="Binance",
    symbol="BTCUSDT",
    timeframe="1m",
    open_ts=1735689600000,
    end_ts=1735689659999,
    open=43250.00,
    high=43275.00,
    low=43240.00,
    close=43260.00,
    volume=12.45
)

# Access fields
print(kline.close)   # 43260.00
print(kline.symbol)  # BTCUSDT

DataInput Configuration

from streamforge import DataInput

# Basic
stream = DataInput(
    type="kline",
    symbols=["BTCUSDT"],
    timeframe="1m"
)

# With aggregation
stream = DataInput(
    type="kline",
    symbols=["BTCUSDT"],
    timeframe="1m",
    aggregate_list=["5m", "15m", "1h"]
)

Back to API Reference →