As Of (Prevailing)#
Time Window Match#
Data can be retrieved by specifying start
and end
times to the specified time window.
def at_trade():
pt = otq.Passthrough().tick_type('TRD')
graph = otq.Graph(pt)
return graph
query = at_trade()
result = otq.run(query,
http_address=rest_url,access_token=access_token,
output_mode="pandas",
start=datetime(2024,1,3,9,31,0),
end = datetime(2024,1,3,9,32,0),
timezone='America/New_York',
symbols='US_COMP_SAMPLE::CSCO'
)
Time |
PRICE |
SIZE |
EXCHANGE |
COND |
PARTICIPANT_TIME |
TRF_TIME |
STOP_STOCK |
SOURCE |
TRF |
TTE |
TICKER |
CORR |
SEQ_NUM |
TRADE_ID |
DELETED_TIME |
TICK_STATUS |
OMDSEQ |
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 |
2024-01-03 09:31:03.089024823 |
50.16 |
1 |
D |
@ I |
2024-01-03 09:31:03.087872000 |
2024-01-03 09:31:03.088991986 |
N |
Q |
0 |
CSCO |
0 |
220506 |
1005 |
1969-12-31 19:00:00 |
0 |
0 |
|
1 |
2024-01-03 09:31:04.039361452 |
50.1501 |
210 |
D |
@ |
2024-01-03 09:31:04.037865000 |
2024-01-03 09:31:04.039020746 |
N |
N |
0 |
CSCO |
0 |
220747 |
44 |
1969-12-31 19:00:00 |
0 |
0 |
|
2 |
2024-01-03 09:31:04.062783595 |
50.15 |
100 |
Q |
@F |
2024-01-03 09:31:04.062767563 |
1969-12-31 19:00:00.000000000 |
N |
1 |
CSCO |
0 |
220756 |
811 |
1969-12-31 19:00:00 |
0 |
0 |
||
3 |
2024-01-03 09:31:04.062785486 |
50.15 |
100 |
Q |
@F |
2024-01-03 09:31:04.062767563 |
1969-12-31 19:00:00.000000000 |
N |
1 |
CSCO |
0 |
220757 |
812 |
1969-12-31 19:00:00 |
0 |
1 |
||
4 |
2024-01-03 09:31:04.062794245 |
50.15 |
100 |
Q |
@F |
2024-01-03 09:31:04.062777010 |
1969-12-31 19:00:00.000000000 |
N |
1 |
CSCO |
0 |
220758 |
813 |
1969-12-31 19:00:00 |
0 |
2 |
||
5 |
2024-01-03 09:31:04.062795879 |
50.15 |
1 |
Q |
@F I |
2024-01-03 09:31:04.062777010 |
1969-12-31 19:00:00.000000000 |
N |
1 |
CSCO |
0 |
220759 |
814 |
1969-12-31 19:00:00 |
0 |
3 |
||
6 |
2024-01-03 09:31:04.062797669 |
50.15 |
100 |
Q |
@F |
2024-01-03 09:31:04.062777010 |
1969-12-31 19:00:00.000000000 |
N |
1 |
CSCO |
0 |
220760 |
815 |
1969-12-31 19:00:00 |
0 |
4 |
||
7 |
2024-01-03 09:31:04.063084832 |
50.15 |
199 |
K |
@F |
2024-01-03 09:31:04.062893000 |
1969-12-31 19:00:00.000000000 |
N |
1 |
CSCO |
0 |
220761 |
209 |
1969-12-31 19:00:00 |
0 |
0 |
||
8 |
2024-01-03 09:31:04.063111506 |
50.15 |
100 |
U |
@ |
2024-01-03 09:31:04.062892258 |
1969-12-31 19:00:00.000000000 |
N |
0 |
CSCO |
0 |
220762 |
156 |
1969-12-31 19:00:00 |
0 |
1 |
||
9 |
2024-01-03 09:31:04.063111609 |
50.15 |
100 |
U |
@ |
2024-01-03 09:31:04.062892258 |
1969-12-31 19:00:00.000000000 |
N |
0 |
CSCO |
0 |
220763 |
157 |
1969-12-31 19:00:00 |
0 |
2 |
Most Recent / Prevailing Value#
To return the most recent / prevailing value as of the specified time (e.g. snapshot time), set the start
and end
to the same timestamp, and update the Passthrough node to include:
go_back_to_first_tick
- The maximum time in seconds to look back and search for prevailing prices
back_tick_if_none_at_start_time
- Set toTrue
to enable the lookback.
The lookback stops on the first match, so althrough the maximum period of time may be large typically the lookback may be only a few seconds.
def prevailing_trade():
pt = otq.Passthrough(go_back_to_first_tick=86400,back_tick_if_none_at_start_time=True).tick_type('TRD')
graph = otq.Graph(pt)
return graph
result = otq.run(prevailing_trade(),
http_address=rest_url,access_token=access_token,
output_mode="pandas",
start=datetime(2024,1,3,9,31,0),
end = datetime(2024,1,3,9,31,0),
timezone='America/New_York',
symbols='US_COMP_SAMPLE::CSCO'
)
Time |
PRICE |
SIZE |
EXCHANGE |
COND |
PARTICIPANT_TIME |
TRF_TIME |
STOP_STOCK |
SOURCE |
TRF |
TTE |
TICKER |
CORR |
SEQ_NUM |
TRADE_ID |
DELETED_TIME |
TICK_STATUS |
OMDSEQ |
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 |
2024-01-03 09:31:00 |
50.16 |
10 |
U |
@ I |
2024-01-03 09:30:59.206796705 |
1969-12-31 19:00:00 |
N |
0 |
CSCO |
0 |
218800 |
155 |
1969-12-31 19:00:00 |
0 |
0 |
As Of Join#
To retrieve trades joined to prevailing quotes an asof
join is specified using the join_by_time
class, specifying the trades branch as the leading source, with leading_sources
.
Each branch must be named with the node_name
attribute. The graph is then defined with both inputs being passed to the join_by_time
node.
def trades_with_quotes():
trd_in= otq.Passthrough(fields='PRICE,SIZE').tick_type('TRD').node_name('trd')
qte_in= otq.Passthrough(fields='BID_PRICE,ASK_PRICE').tick_type('QTE').node_name('qte')
jbt = otq.JoinByTime(leading_sources='trd',add_source_prefix=False)
trd_in >> jbt
qte_in >> jbt
graph = otq.Graph(jbt)
return graph
result = otq.run(trades_with_quotes(),
http_address=rest_url,access_token=access_token,
output_mode="pandas",
start=datetime(2024,1,3,9,30,0),
end = datetime(2024,1,3,10,30,0),
timezone='America/New_York',
symbols='US_COMP_SAMPLE::CSCO'
Time |
trd.TIMESTAMP |
PRICE |
SIZE |
qte.TIMESTAMP |
BID_PRICE |
ASK_PRICE |
|
---|---|---|---|---|---|---|---|
0 |
2024-01-03 09:30:00.065443591 |
2024-01-03 09:30:00.065443591 |
50.02 |
2 |
2024-01-03 09:30:00.059591977 |
49.5 |
50.18 |
1 |
2024-01-03 09:30:00.111130049 |
2024-01-03 09:30:00.111130049 |
50.16 |
3 |
2024-01-03 09:30:00.088783491 |
49.98 |
50.19 |
2 |
2024-01-03 09:30:00.127459523 |
2024-01-03 09:30:00.127459523 |
50.17 |
100 |
2024-01-03 09:30:00.088783491 |
49.98 |
50.19 |
3 |
2024-01-03 09:30:00.128498068 |
2024-01-03 09:30:00.128498068 |
50.17 |
5 |
2024-01-03 09:30:00.128494915 |
50.0 |
50.17 |
4 |
2024-01-03 09:30:00.135190071 |
2024-01-03 09:30:00.135190071 |
50.13 |
46 |
2024-01-03 09:30:00.128494915 |
50.0 |
50.17 |
5 |
2024-01-03 09:30:00.232554141 |
2024-01-03 09:30:00.232554141 |
50.13 |
117 |
2024-01-03 09:30:00.128494915 |
50.0 |
50.17 |
6 |
2024-01-03 09:30:00.232556132 |
2024-01-03 09:30:00.232556132 |
50.05 |
83 |
2024-01-03 09:30:00.128494915 |
50.0 |
50.17 |
7 |
2024-01-03 09:30:00.280877749 |
2024-01-03 09:30:00.280877749 |
50.002 |
200 |
2024-01-03 09:30:00.128494915 |
50.0 |
50.17 |
8 |
2024-01-03 09:30:00.321495830 |
2024-01-03 09:30:00.321495830 |
50.002 |
9 |
2024-01-03 09:30:00.128494915 |
50.0 |
50.17 |
9 |
2024-01-03 09:30:00.372805563 |
2024-01-03 09:30:00.372805563 |
50.085 |
1 |
2024-01-03 09:30:00.327674861 |
50.0 |
50.17 |