otp.Source.limit#
- Source.limit(tick_limit, tick_offset=None, inplace=False)#
Propagates ticks until the count limit is reached.
Once the limit is reached, hidden ticks will still continue to propagate until the next regular tick appears.
- Parameters
tick_limit (int) – The number of regular ticks to propagate. Must be a non-negative integer or -1, which means no limit.
tick_offset (int) – The number of regular ticks to skip before starting to propagate. Must be a non-negative integer. By default no ticks are skipped.
inplace (bool) – The flag controls whether operation should be applied inplace or not. If
inplace=True, then it returns nothing. Otherwise method returns a new modified object.self (Source) –
- Return type
SourceorNone
Examples
Simple example, get first 3 ticks:
data = otp.Ticks(X=[1, 2, 3, 4, 5, 6]) data = data.limit(3) df = otp.run(data) print(df)
Time X 0 2003-12-01 00:00:00.000 1 1 2003-12-01 00:00:00.001 2 2 2003-12-01 00:00:00.002 3
Disable limit by setting it to -1:
data = otp.Ticks(X=[1, 2, 3, 4, 5, 6]) data = data.limit(-1) df = otp.run(data) print(df)
Time X 0 2003-12-01 00:00:00.000 1 1 2003-12-01 00:00:00.001 2 2 2003-12-01 00:00:00.002 3 3 2003-12-01 00:00:00.003 4 4 2003-12-01 00:00:00.004 5 5 2003-12-01 00:00:00.005 6
Setting parameter
tick_offsetcan be used to skip first ticks before propagating them.For example, we can skip first 2 ticks and propagate all other:
data = otp.Ticks(X=[1, 2, 3, 4, 5, 6]) data = data.limit(-1, tick_offset=2) df = otp.run(data) print(df)
Time X 0 2003-12-01 00:00:00.002 3 1 2003-12-01 00:00:00.003 4 2 2003-12-01 00:00:00.004 5 3 2003-12-01 00:00:00.005 6
Or we can return ticks from the middle of the stream by skipping first 2 ticks and then returning next 2 ticks like this:
data = otp.Ticks(X=[1, 2, 3, 4, 5, 6]) data = data.limit(2, tick_offset=2) df = otp.run(data) print(df)
Time X 0 2003-12-01 00:00:00.002 3 1 2003-12-01 00:00:00.003 4
See also
LIMIT OneTick event processor