Query editor
-- Funding Rate-- funding_rate = skew / k-- skew = (long - short) / MAX(long, short) (requires open interest for shorts and longs?)-- k = risk parameter-- funding rate = payments / global notional sizeWITH init_payments as (--v2.2SELECTmarket, evt_block_time, CAST(json_value(accumulationResult, 'lax $.fundingLong') AS BIGINT) + CAST(json_value(accumulationResult, 'lax $.interestLong') AS BIGINT) as Long_payments, CAST(json_value(accumulationResult, 'lax $.fundingShort') AS BIGINT) + CAST(json_value(accumulationResult, 'lax $.interestShort') AS BIGINT) as Short_paymentsFROM perennial_v2_arbitrum.Market_evt_PositionProcessed aLEFT JOIN query_3866227 b on a.contract_address = b.contract_addressUNION ALL--v2.1 and priorSELECTmarket,block_time,-- Calculate Long_payments(COALESCE(CAST(json_extract_scalar(a."accumulationresult", '$.fundingLong') AS BIGINT), 0) +COALESCE(CAST(json_extract_scalar(a."accumulationresult", '$.interestLong') AS BIGINT), 0)) AS Long_payments,-- Calculate Short_payments(COALESCE(CAST(json_extract_scalar(a."accumulationresult", '$.fundingShort') AS BIGINT), 0) +COALESCE(CAST(json_extract_scalar(a."accumulationresult", '$.interestShort') AS BIGINT), 0)) AS Short_paymentsFROMquery_3906510 aWHEREjson_extract_scalar(a."accumulationresult", '$.fundingLong') IS NOT NULLOR json_extract_scalar(a."accumulationresult", '$.interestLong') IS NOT NULLOR json_extract_scalar(a."accumulationresult", '$.fundingShort') IS NOT NULLOR json_extract_scalar(a."accumulationresult", '$.interestShort') IS NOT NULL-- SELECT-- market,-- block_time,-- CASE-- WHEN json_extract_scalar(json_element, '$.type.meta.name') = 'fundingLong'-- THEN CAST(json_extract_scalar(json_element, '$.value') AS BIGINT)-- ELSE 0-- END +-- CASE-- WHEN json_extract_scalar(json_element, '$.type.meta.name') = 'interestLong'-- THEN CAST(json_extract_scalar(json_element, '$.value') AS BIGINT)-- ELSE 0-- END AS Long_payments,-- CASE-- WHEN json_extract_scalar(json_element, '$.type.meta.name') = 'fundingShort'-- THEN CAST(json_extract_scalar(json_element, '$.value') AS BIGINT)