input
#
The module contains functionality related to the processing of indicators' input.
Sampler
#
Sampler(period_type: SamplingPeriodType)
Implementation of timeframe auto-sampling.
Timeframe auto-sampling allows to evaluate whether two timestamps belong into the same period or not. This is later used by indicators to "merge" several input values received within selected timeframe and keep only the last value in the given timeframe.
Each timeframe is counted from different starting point. Seconds are counted since whole minutes, minutes are counted since whole hours, hours are counted since whole days and days are counted since the beginning of the year.
Examples:
Sampling: 1 sec
Timestamp 1: 00:00:01.000000
Timestamp 2: 00:00:01.700000
Result: same timeframe
Sampling: 5 sec
Timestamp 1: 00:00:01.000000
Timestamp 2: 00:00:04.000000
Result: same timeframe
Sampling: 5 sec
Timestamp 1: 00:00:04.000000
Timestamp 2: 00:00:06.000000
Result: different timeframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
period_type |
SamplingPeriodType
|
The sampling period. |
required |
Source code in talipp/input.py
is_same_period
#
Evaluate whether two OHLCV objects belong to the same period.
OHLCV
objects have to contain time component to be comparable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
first |
OHLCV
|
The first |
required |
second |
OHLCV
|
The second |
required |
Returns:
Type | Description |
---|---|
bool
|
|
Source code in talipp/input.py
SamplingPeriodType
#
Bases: Enum
Available sampling periods.
Each sampling period consists of a unit and its span. E.g. SEC_1
means sampling every second, SEC_3
means sampling every three seconds and so on.
Note
Only those spans are allowed which divide full unit's period without remainder.
3 seconds => OK (60 % 3 = 0)
5 seconds => OK (60 % 5 = 0)
8 seconds => NOT OK (60 % 8 != 0)
4 hours => OK (24 % 4 = 0)
5 hours => NOT OK (24 % 5 != 0)