Accessing a Lower Level API#
Some of OneTick’s functionality may not be explicitly added to onetick-py but can be access through a lower-level API called onetick.query.
See OneTick server documentation for details.
import onetick.py as otp
from onetick.py.otq import otq
trd = otp.DataSource('US_COMP_SAMPLE', tick_type='TRD')
trd.sink(otq.Variance(input_field_name='PRICE', output_field_name='VAR_PRICE', bucket_interval=60))
trd = trd.table(VAR_PRICE=float, strict=False) # need to explicitly add the fields added by the `sink` methods to the schema
trd['STD'] = otp.math.sqrt(trd['VAR_PRICE'])
otp.run(trd, start=otp.dt(2024, 2, 1, 10), end=otp.dt(2024, 2, 1, 16), symbols='AAPL')
| Time | VAR_PRICE | STD | |
|---|---|---|---|
| 0 | 2024-02-01 10:01:00 | 0.008904 | 0.094364 |
| 1 | 2024-02-01 10:02:00 | 0.007217 | 0.084955 |
| 2 | 2024-02-01 10:03:00 | 0.001647 | 0.040586 |
| 3 | 2024-02-01 10:04:00 | 0.003179 | 0.056387 |
| 4 | 2024-02-01 10:05:00 | 0.006869 | 0.082880 |
| ... | ... | ... | ... |
| 355 | 2024-02-01 15:56:00 | 0.000592 | 0.024340 |
| 356 | 2024-02-01 15:57:00 | 0.000574 | 0.023961 |
| 357 | 2024-02-01 15:58:00 | 0.002291 | 0.047864 |
| 358 | 2024-02-01 15:59:00 | 0.000648 | 0.025451 |
| 359 | 2024-02-01 16:00:00 | 0.002055 | 0.045332 |
360 rows × 3 columns