contango.stream.historical_stream
contango.stream.historical_stream
HistoricalStream
HistoricalStream(source: Stream[R], window: int)
Bases: Stream[R], Generic[R]
Wraps any stream and records a window of its past values.
Attributes:
| Name | Type | Description |
|---|---|---|
R |
The return type for the historical stream. |
Initializes HistoricalStream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Stream[R]
|
The stream source to wrap. |
required |
window
|
int
|
The maximum amount of lookback for the history of the stream. |
required |
Source code in src\contango\stream\historical_stream.py
21 22 23 24 25 26 27 28 29 30 | |
value
property
value: R
Returns the most recent value of the historical stream.
previous
previous(n: int = 1) -> R | None
Returns the previous n amount of values backwards. For example, n=1 will be the previous value relative to the current one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The amount of lookback. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
R |
R | None
|
The stream value at n amount of lookback. |
None |
R | None
|
If the history deque is shorter than the amount of lookback. |
Source code in src\contango\stream\historical_stream.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
update
update(event: MarketDataEvent) -> R
Updates the state of the historical stream given a market data event.
Source code in src\contango\stream\historical_stream.py
32 33 34 35 36 37 38 | |