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)[source]#

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>]]

    • DataFrame – DataFrame with Time column

    • Noneinplace_data will 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 or utils.adaptive) – Timestamp for data generation

  • end (datetime.datetime, otp.datetime or utils.adaptive) – Timestamp for data generation

  • tick_type (str) – tick type for data generation

  • timezone_for_time (str) – timezone for data generation

  • **inplace_data (dict) – <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 offset example

>>> 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

>>> 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