otp.Ticks#
- class Ticks(data=None, symbol=utils.adaptive_to_default, db=utils.adaptive_to_default, start=utils.adaptive, end=utils.adaptive, tick_type=None, timezone_for_time=None, **inplace_data)#
Bases:
Data source that generates ticks.
Ticks are placed with the 1 millisecond offset from each other starting from the start of the query interval. It has ability to change distance between ticks using the special reserved field name
offset, that specify time offset from a previous tick.- Parameters
data (dict, list or pandas.DataFrame, optional) –
Ticks values
dict– <field_name>: <values>list– [[<field_names>], [<first_tick_values>], …, [<n_tick_values>]]None–inplace_datawill be used
symbol (str, list of str,
Source,query,eval query) – Symbol(s) from which data should be taken.db (str) – Database to use for tick generation
start (
datetime.datetime,otp.datetime,onetick.py.adaptive) – Timestamp for data generationend (
datetime.datetime,otp.datetime,onetick.py.adaptive) – Timestamp for data generationtick_type (str) – tick type for data generation
timezone_for_time (str) – timezone for data generation
**inplace_data (list) – <field_name>: list(<field_values>)
Examples
Pass data in
dict>>> d = otp.Ticks({'A': [1, 2, 3], 'B': [4, 5, 6]}) >>> otp.run(d) Time A B 0 2003-12-01 00:00:00.000 1 4 1 2003-12-01 00:00:00.001 2 5 2 2003-12-01 00:00:00.002 3 6
Pass
inplace_data>>> d = otp.Ticks(A=[1, 2, 3], B=[4, 5, 6]) >>> otp.run(d) Time A B 0 2003-12-01 00:00:00.000 1 4 1 2003-12-01 00:00:00.001 2 5 2 2003-12-01 00:00:00.002 3 6
Pass data in
list>>> d = otp.Ticks([['A', 'B'], ... [1, 4], ... [2, 5], ... [3, 6]]) >>> otp.run(d) Time A B 0 2003-12-01 00:00:00.000 1 4 1 2003-12-01 00:00:00.001 2 5 2 2003-12-01 00:00:00.002 3 6
Using the
offsetexample>>> data = otp.Ticks(X=[1, 2, 3], offset=[0, otp.Nano(1), 1]) >>> otp.run(data) Time X 0 2003-12-01 00:00:00.000000000 1 1 2003-12-01 00:00:00.000000001 2 2 2003-12-01 00:00:00.001000000 3
Using pandas.DataFrame. DataFrame should have a
Timecolumn containing datetime objects.>>> start_datetime = datetime(2023, 1, 1, 12) >>> time_array = [start_datetime + otp.Hour(1) + otp.Nano(1)] >>> a_array = [start_datetime - otp.Day(15) - otp.Nano(7)] >>> df = pd.DataFrame({'Time': time_array,'A': a_array}) >>> data = otp.Ticks(df) >>> otp.run(data, start=start_datetime, end=start_datetime + otp.Day(1)) Time A 0 2023-01-01 13:00:00.000000001 2022-12-17 11:59:59.999999993
See also
TICK_GENERATOR OneTick event processor