otp.Source.script#

Source.script(func, inplace=False)[source]#

Implements a script for every tick

Allows to pass a func that will be applied per every tick. A func can be python callable in this case it will be transferred to per tick script. The script written in per tick script language can be passed itself as a string or path to a file with the code. onetick-py doesn’t validate the script, but configure schema accordingly.

Limitations Integrations with any 3rd party Python packages are not supported. For example, a case when you want to apply some open source ML library. It happens because the code is translated into the OneTick API calls and if there is no support for the 3rd party package then it can’t be integrated.

Parameters

func (callable, str or path) –

  • a callable that takes only one parameter - actual tick that behaves like a Source instance

  • or the sciprt on per tick script language

  • or a path to file with onetick script

Returns

instance where every tick is passed through the func

Return type

Source

Examples

>>> t = otp.Ticks({'X': [1, 2, 3], 'Y': [4, 5, 6]})
>>> def fun(tick):
...     tick['Z'] = 0
...     if tick['X'] + tick['Y'] == 5:
...         tick['Z'] = 1
...     elif tick['X'] + tick['Y'] * 2 == 15:
...         tick['Z'] = 2
>>> t = t.script(fun)
>>> t()
                     Time  X  Y  Z
0 2003-12-01 00:00:00.000  1  4  1
1 2003-12-01 00:00:00.001  2  5  0
2 2003-12-01 00:00:00.002  3  6  2