Streaming API
The ferro_ta.streaming module provides stateful, bar-by-bar indicator computation
for live/real-time trading. Each class maintains an internal buffer and returns NaN
during the warmup period.
Streaming / Incremental Indicators — bar-by-bar stateful classes.
All streaming classes are implemented in Rust (PyO3) for maximum performance.
The Python module re-exports the Rust classes from the _ferro_ta extension.
The extension must be built; there is no Python fallback.
Usage
>>> from ferro_ta.data.streaming import StreamingSMA, StreamingEMA, StreamingRSI
>>> import numpy as np
>>> sma = StreamingSMA(period=3)
>>> for close in [10.0, 11.0, 12.0, 13.0, 14.0]:
... val = sma.update(close)
... print(f"{close} → {val:.4f}" if not np.isnan(val) else f"{close} → NaN")
10.0 → NaN
11.0 → NaN
12.0 → 11.0000
13.0 → 12.0000
14.0 → 13.0000
Available classes
StreamingSMA — Simple Moving Average StreamingEMA — Exponential Moving Average StreamingRSI — Relative Strength Index (Wilder seeding) StreamingATR — Average True Range (Wilder seeding) StreamingBBands — Bollinger Bands (upper, middle, lower) StreamingMACD — MACD line, signal, histogram StreamingStoch — Slow Stochastic (slowk, slowd) StreamingVWAP — Volume Weighted Average Price (cumulative) StreamingSupertrend — ATR-based Supertrend
Rust backend
All classes are PyO3 classes compiled into the _ferro_ta extension module.
Import them directly from the extension for zero-overhead access:
from ferro_ta._ferro_ta import StreamingSMA
- class ferro_ta.streaming.StreamingATR(period=14)
Bases:
objectAverage True Range with TA-Lib–compatible Wilder seeding.
- period
- reset()
- update(high, low, close)
Add a new bar (high, low, close) and return ATR (NaN during warmup).
- class ferro_ta.streaming.StreamingBBands(period=20, nbdevup=2.0, nbdevdn=2.0)
Bases:
objectBollinger Bands — streaming variant using Welford’s online algorithm.
- period
- reset()
- update(value)
Add a new bar; return (upper, middle, lower). NaN tuple during warmup.
- class ferro_ta.streaming.StreamingEMA(period)
Bases:
objectExponential Moving Average with SMA seeding.
- period
- reset()
- update(value)
Add a new bar and return the current EMA (NaN during warmup).
- class ferro_ta.streaming.StreamingMACD(fastperiod=12, slowperiod=26, signalperiod=9)
Bases:
objectMACD — fast EMA, slow EMA, signal EMA.
- reset()
- update(value)
Add a new close; return (macd_line, signal_line, histogram).
- class ferro_ta.streaming.StreamingRSI(period=14)
Bases:
objectRelative Strength Index with TA-Lib–compatible Wilder seeding.
- period
- reset()
- update(value)
Add a new close and return RSI in [0, 100] (NaN during warmup).
- class ferro_ta.streaming.StreamingSMA(period)
Bases:
objectSimple Moving Average — O(1) per update via running sum.
Returns NaN during the first period - 1 bars.
- period
- reset()
Reset state to initial condition.
- update(value)
Add a new bar and return the current SMA (NaN during warmup).
- class ferro_ta.streaming.StreamingStoch(fastk_period=5, slowk_period=3, slowd_period=3)
Bases:
objectSlow Stochastic (SMA-smoothed).
- reset()
- update(high, low, close)
Add a new bar (high, low, close); return (slowk, slowd).
- class ferro_ta.streaming.StreamingSupertrend(period=7, multiplier=3.0)
Bases:
objectATR-based Supertrend — streaming variant.
- period
- reset()
- update(high, low, close)
Add a new bar (high, low, close); return (supertrend_line, direction).
- class ferro_ta.streaming.StreamingVWAP
Bases:
objectCumulative Volume Weighted Average Price.
- reset()
Reset for a new session.
- update(high, low, close, volume)
Add a new bar (high, low, close, volume) and return cumulative VWAP.