Query editor
with instrument as (select *from dune.contango_xyz.result_v2_instruments_on_all_chainswhere chain = '{{chain}}'),oi_delta as (selectdate_trunc('day', trade.timestamp) as timestamp,instrument.symbol_hash as symbol_hash, trade.symbol, trade.direction, trade.correlated, trade.moneymarket,sum(trade.quantity) as deltafrom"query_3274457(chain='{{chain}}')" as tradejoin instrumenton instrument.symbol_hash = trade.symbol_hashgroup by 1,2,3,4,5,6),instrument_oi_dirty as (selecttimeseries.timestamp as timestamp,instrument.base_symbol as token, oi_delta.symbol, oi_delta.direction, oi_delta.correlated, oi_delta.moneymarket,sum(oi_delta.delta) over (partition by instrument.symbol_hashorder by timeseries.timestamp) as oifrom"query_3276786" as timeseriescross join instrumentleft join oi_deltaon oi_delta.timestamp = timeseries.timestampand oi_delta.symbol_hash = instrument.symbol_hash),instrument_oi as (selecttimestamp,token, symbol,direction, correlated, moneymarket,case when oi < 0 then 0 else oi end as oifrom instrument_oi_dirty),instrument_oi_usd as (selecttimestamp, oi.symbol, oi.direction, oi.correlated, oi.moneymarket,oi.oi * price.price as oi_usdfrominstrument_oi as oijoin "query_3276880" as priceon price.symbol = oi.tokenand price.day = oi.timestamp)select'{{chain}}' as chain,timeseries.timestamp as timestamp, oi.symbol, oi.direction, oi.correlated, oi.moneymarket,coalesce(sum(oi.oi_usd), 0) as oi_usdfrom"query_3276786" as timeseriesleft join instrument_oi_usd as oi