Query editor
with raw_result AS(SELECT http_get('https://arbitrum-size-api.integral.link/api/v5/graph?network=Arbitrum'||'&tokenInAddress=0x82af49447d8a07e3bd95bd0d56f35241523fbab1'||'&tokenOutAddress=0xaf88d065e77c8cc2239327c5edb3a432268e5831&timeframe=1d') as raw_json),parsed_data AS (SELECT json_extract(json_parse(raw_json), '$.data') as parsed_json from raw_result),prices as(SELECT from_iso8601_timestamp(cast(json_extract(price_feeds, '$.timestamp') as varchar)) as datetime,cast(cast(json_extract(price_feeds, '$.twap') as varchar) as uint256) as twap_price,cast(cast(json_extract(price_feeds, '$.spot') as varchar) as uint256) as spot_priceFROM parsed_data,UNNEST(CAST(parsed_json AS array(json))) t(price_feeds)),trades as(select block_time,token_pair,amount_usd,taker,maker,tx_hash,project_contract_address as pool_addressFROM dex.tradesWHERE blockchain = 'arbitrum'and project='integral'and token_bought_address=0xaf88d065e77c8cc2239327c5edb3a432268e5831and token_sold_address=0x82af49447d8a07e3bd95bd0d56f35241523fbab1and block_time>= NOW() - INTERVAL '24' hour)SELECT t.block_time as timestamp,t.pool_address,t.amount_usd,t.tx_hash,(cast(p.twap_price as double)/cast(p.spot_price as double))-1 as price_impactFROM trades tinner JOIN (SELECT p1.datetime, p1.twap_price, p1.spot_price,t.block_time,t.tx_hash,ROW_NUMBER() OVER (PARTITION BY t.tx_hash ORDER BY ABS(date_diff('MINUTE', t.block_time, p1.datetime))) AS rnFROM prices p1CROSS JOIN trades t) p ON t.tx_hash = p.tx_hash AND p.rn = 1order by timestamp desc