Prevailing quote at the time of a trade#

import onetick.py as otp

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

qte = otp.DataSource('TAQ_NBBO', 
                     tick_type='NBBO', 
                     back_to_first_tick=otp.Minute(10))

qte = qte[['ASK_PRICE', 'BID_PRICE']]
qte['quote_time'] = qte['Time']

enriched_trades = otp.join_by_time([trd, qte])
    
otp.run(enriched_trades,
        symbols=['SPY'],
        start=otp.dt(2023, 5, 15, 9, 30),
        end=otp.dt(2023, 5, 15, 9, 30, 1),    
        timezone='EST5EDT')
Time PRICE SIZE ASK_PRICE BID_PRICE quote_time
0 2023-05-15 09:30:00.000178688 412.22 100 412.25 412.22 2023-05-15 09:30:00.000174080
1 2023-05-15 09:30:00.000776704 412.22 247 412.24 412.21 2023-05-15 09:30:00.000715520
2 2023-05-15 09:30:00.003603456 412.22 100 412.24 412.22 2023-05-15 09:30:00.003562496
3 2023-05-15 09:30:00.006352128 412.24 1 412.25 412.22 2023-05-15 09:30:00.006343936
4 2023-05-15 09:30:00.007128064 412.24 3 412.25 412.22 2023-05-15 09:30:00.007110656
... ... ... ... ... ... ...
310 2023-05-15 09:30:00.934032640 412.27 160 412.28 412.26 2023-05-15 09:30:00.934030080
311 2023-05-15 09:30:00.975609344 412.24 2 412.28 412.27 2023-05-15 09:30:00.970691840
312 2023-05-15 09:30:00.980264448 412.27 1 412.28 412.27 2023-05-15 09:30:00.979763456
313 2023-05-15 09:30:00.985391616 412.28 100 412.28 412.27 2023-05-15 09:30:00.985296640
314 2023-05-15 09:30:00.985394944 412.28 100 412.28 412.27 2023-05-15 09:30:00.985296640

315 rows × 6 columns