Query editor
with-- remove duplications due to two prices with different letter case. e.g. USDT and USDtnormalised_hourly_prices as (selectlower(symbol) as symbol,hour,avg(price) as pricefrom dune.contango_xyz.result_v2_hourly_pricesgroup bylower(symbol),hour)selectposition_update.chain as chain,position_update.evt_block_time as timestamp,instrument.symbol as symbol,instrument.direction as direction,instrument.correlated as correlated,moneymarket.name as moneymarket,position_update.quantityDelta / instrument.base_unit as quantity,casewhen instrument.direction = 'long' then position_update.quantityDelta / instrument.base_unitelse position_update.quantityDelta / instrument.base_unit * base_price.price / quote_price.priceend as parsed_quantity,position_update.quantityDelta / instrument.base_unit * base_price.price as quantity_usd,position_update.owner as trader,position_update.evt_tx_hash as tx_hash,instrument.symbol_hash as symbol_hash,position_update.positionId as positionId,position_update.typefromdune.contango_xyz.result_v2_transactions_liquidations_on_all_chains as position_updatejoin dune.contango_xyz.result_v2_money_markets as moneymarketon moneymarket.id = substr(position_update.positionId, 17, 1)join dune.contango_xyz.result_v2_instruments_on_all_chains as instrumenton instrument.symbol_hash = substr(position_update.positionId, 1, 16)and instrument.chain = position_update.chainjoin normalised_hourly_prices as base_priceon lower(base_price.symbol) = lower(instrument.base_symbol)and base_price.hour = date_trunc('hour', position_update.evt_block_time)join normalised_hourly_prices as quote_priceon lower(quote_price.symbol) = lower(instrument.quote_symbol)and quote_price.hour = date_trunc('hour', position_update.evt_block_time)whereposition_update.type != 'Modification'order bytimestamp desc,chain;