Rendering query graphs#

Rendering onetick-py query is one of the helpful debug techniques. You can use either otp.Source.render_otq for onetick-py query or render_otq function for rendering otq files.

Here’s an example for simple onetick-py query:

from IPython.display import Image
import onetick.py as otp

data = otp.DataSource(db='US_COMP_SAMPLE', tick_type='TRD', symbols='AAPL')
data1, data2 = data[(data['PRICE'] > 50)]
data = otp.merge([data1, data2])
Image(data.render_otq(output_format='png'))
20251201120020 WARNING: WARN_02203365UWTWO: Unable to connect to server process on host development-queryhost.preprod-solutions.parent.onetick.com:50016.
20251201120020 WARNING: WARN_02203365UWTWO: Unable to connect to server process on host development-queryhost.preprod-solutions.parent.onetick.com:50017.
20251201120020 WARNING: WARN_02203365UWTWO: Unable to connect to server process on host development-queryhost.preprod-solutions.parent.onetick.com:50018.
20251201120020 WARNING: WARN_02203365UWTWO: Unable to connect to server process on host development-queryhost.preprod-solutions.parent.onetick.com:50019.
20251201120020 WARNING: WARN_02203365UWTWO: Unable to connect to server process on host development-queryhost.preprod-solutions.parent.onetick.com:50020.
../../_images/e44f7a2fc6b2fc9c92bfae4fc8b8d5bd27a4d32d45b718c5c9e35c3e6aed1c3e.png

Rendering function supports graphs with nested queries:

def agg_fun(source):
    return source.agg({
        'volume': otp.agg.sum('SIZE'),
        'vwap': otp.agg.vwap('PRICE', 'SIZE')
    })

data = otp.DataSource(db='US_COMP_SAMPLE', tick_type='TRD', symbols='AAPL')
data = data[['PRICE', 'SIZE']]
data = otp.agg.generic(agg_fun, bucket_interval=otp.Minute(1)).apply(data)
Image(data.render_otq(output_format='png'))
../../_images/35c5ee5c73e3fd3d659aeb02a61f592453fa34f11a35b24cfeed2fd16fb50989.png

Query with multiple input sources:

start_time = otp.dt(2024, 2, 1, 9, 30)
end_time = otp.dt(2024, 2, 1, 9, 30, 1)

trd = otp.DataSource('US_COMP_SAMPLE', tick_type='TRD')
trd = trd[['PRICE', 'SIZE']]

qte = otp.DataSource('US_COMP_SAMPLE', tick_type='NBBO')
qte = qte[['BID_PRICE', 'ASK_PRICE']]

enh_trd = otp.join_by_time([trd, qte])
Image(enh_trd.render_otq(output_format='png', symbols=['AAPL'], start=start_time, end=end_time))
../../_images/9d0765417ff55e1df5611f7371d78fc211eefbc0d9b1c701e3f5a9a6498630b0.png

Query with Per Tick Script:

def fun(tick):
    tick['VOLUME'] = tick['PRICE'] * tick['SIZE']
    if tick['SIZE'] >= 1000:
        tick['REQ_SIZE'] = 1
    else:
        tick['REQ_SIZE'] = 0

data = otp.DataSource(db='US_COMP_SAMPLE', tick_type='TRD', symbols='AAPL')
data = data.script(fun)
Image(data.render_otq(output_format='png'))
../../_images/e25c2d3f952d84bee678de8a3769ebc80deafcff29760d7ec6f213b5289bd307.png