Query editor
with open_apollox_trades as (SELECTevt_block_time, CAST(user as varchar) as trader, CAST(json_query(ot, 'lax $.qty') as decimal(38,0))/1e10 as token_amount, CAST(json_query(ot, 'lax $.entryPrice') as decimal(38,0))/1e8 as price, CAST(json_query(ot, 'strict $.pairBase' OMIT QUOTES) as varchar) as pair_address, CAST(json_query(ot, 'lax $.openFee') as decimal(38, 0))/1e18 + CAST(json_query(ot, 'lax $.executionFee') as decimal(38,0))/1e18 as fees --usd, IF(json_value(ot, 'lax $.isLong' RETURNING BOOLEAN), 'LONG', 'SHORT') as is_long, tradeHashFROM apollox_perp_v2_bnb.ApolloX_evt_OpenMarketTradeUNION ALLSELECTblock_time, CAST(bytearray_substring(topic1, 1 + 12, 20) as varchar) as trader, bytearray_to_uint256(bytearray_substring(data, 1 + 32 * 14, 32))/1e10 as token_amount, bytearray_to_uint256(bytearray_substring(data, 1 + 32 * 2, 32))/1E8 as price, CAST(bytearray_substring(data, 1 + 12 + 32 * 3 , 20) AS VARCHAR) as pair_address, bytearray_to_uint256(bytearray_substring(data, 1 + 32 * 10, 32))/1e18 + bytearray_to_uint256(bytearray_substring(data, 1 + 32 * 12, 32))/1e18 as fees, (CASE WHEN bytearray_substring(data, 32 * 10, 1) = 0x01 THEN 'LONG' ELSE 'SHORT' END) as is_long, bytearray_substring(topic2, 1, 32) as tradehashFROM bnb.logsWHERE contract_address = 0x1b6f2d3844c6ae7d56ceb3c3643b9060ba28feb0and block_number > 29747250and topic0 = 0xa858fcdefab65cbd1997932d8ac8aa1a9a8c46c90b20947575525d9a2a437f8c), token_pricing as (SELECT time, cast(token as varchar) as token, priceFROM (SELECT date_trunc('day', time) AS time, token, price, ROW_NUMBER() OVER (PARTITION BY token ORDER by time DESC) as row_numFROM (selectcall_block_time as time, token, output_price/1e8 as pricefrom--apollox_perp_v2_bnb.ApolloX_call_getPriceFromCacheOrOracleWHERE call_successUNION ALLSELECT call_block_time, token, price/1e8 as priceFROM apollox_perp_v2_bnb.ApolloX_call_confirmTriggerPriceWHERE call_success))WHERE row_num = 1), days AS (SELECT dayFROM unnest(sequence(timestamp'2023-04-11 00:00:00',CAST(NOW() as timestamp),