aggregate_ohlcΒΆ
Defined in dccd.domain.transforms
- aggregate_ohlc(trades, span)[source]
Aggregate trades into OHLC bars of span seconds.
- Parameters:
- tradeslist[Trade]
Input trades, sorted ascending by
ts(nanoseconds UTC).- spanint
Bar duration in seconds.
- Returns:
- list[OHLCBar]
One bar per non-empty span window, ascending.
Examples
>>> from dccd.domain.records import Trade >>> trades = [ ... Trade(ts=1_000_000_000_000_000_000, price=100.0, amount=1.0, side='buy'), ... Trade(ts=1_000_000_060_000_000_000, price=110.0, amount=2.0, side='sell'), ... ] >>> bars = aggregate_ohlc(trades, span=60) >>> len(bars) 2