Query editor
with price_data as (selectdate_diff('minute', minute, now()) as age_minutes,pricefrom prices.usdwhere blockchain = 'ethereum' and symbol = 'WETH'order by minute desc limit 1), raw_data as (SELECTsplit_part(JSON_EXTRACT_SCALAR(t.coin_data, '$.provider'), '/', 3) AS provider,JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.paymentMethod') AS payment_method,JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.fiat.symbol') AS fiat_currency,cast(JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.amountIn') as double) AS amount_in,JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.crypto.symbol') AS symbol,cast(JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.amountOut') as double) AS amount_out,cast(JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.networkFee') as double) AS network_fee,cast(JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.providerFee') as double) + cast(JSON_EXTRACT_SCALAR(t.coin_data, '$.quote.extraFee') as double) AS provider_fee,(select price from price_data) as market_eth_usd_price,(select age_minutes from price_data) as market_eth_price_age_minFROM UNNEST(TRY_CAST(JSON_PARSE(JSON_QUERY(HTTP_GET('https://on-ramp.metaswap.codefi.network/providers/all/quote?regionId=/regions/us-ca&paymentMethodId=/payments/{{payment_method}}&cryptoCurrencyId=/currencies/crypto/1/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&fiatCurrencyId=/currencies/fiat/usd&amount={{amount}}'),'lax $.success')) AS ARRAY(JSON))) AS t(coin_data)), data as (select*,network_fee + provider_fee as total_fee,amount_in - (network_fee + provider_fee) as subtotal,casewhen symbol = 'ETH' then market_eth_usd_pricewhen symbol = 'USDC' then 1end as market_usd_price,casewhen symbol = 'ETH' then market_eth_price_age_minwhen symbol = 'USDC' then 0end as market_price_age_minutesfrom raw_data)selectprovider,symbol as token,amount_out as amount_received,total_fee,(total_fee/amount_in)+(((subtotal/amount_out)/market_usd_price)-1) as total_cost_rate,((subtotal/amount_out)/market_usd_price)-1 as provider_spread,provider_fee/amount_in as provider_fee_rate,network_fee/amount_in as network_fee_rate,(subtotal/amount_out) as provider_token_usd_price,market_price_age_minutes,market_usd_price,now() as quote_timefrom dataorder by amount_out desc