Query editor
-- User Movements - Flex Frenzy Trading Competition - WIF-- Detailed volume logs for a single user (increase, decrease, liquidation)WITH config AS (SELECTTIMESTAMP '2025-12-04 00:01:00' AS start_time,TIMESTAMP '2025-12-13 23:59:59' AS end_time,{{user_address}} AS user_address),-- Market names with asset informationmarket_name AS (SELECTindex,assetId AS asset,CASEWHEN assetClass = 0 THEN 'Crypto'WHEN assetClass = 1 THEN 'Equities'WHEN assetClass = 2 THEN 'Forex'WHEN assetClass = 3 THEN 'Commodity'END AS assetClassFROM (SELECTindex,-- Remove null bytes (chr(0)) from the hex-decoded asset name (invisible characters)REPLACE(from_utf8(from_hex(REPLACE(CAST(json_value(newConfig, 'strict $.assetId') AS VARCHAR), '0x', ''))),chr(0),'') AS assetId,CAST(json_value(newConfig, 'strict $.assetClass') AS DECIMAL)AS assetClassFROM flexperp_base.ConfigStorage_evt_LogAddMarketConfig)),-- Get WIF market indexwif_market AS (SELECT index AS marketIndexFROM market_nameWHERE asset = 'WIF'),-- Find first valid trade for each positionfirst_valid_positions AS (SELECT DISTINCTprimaryAccount,subAccountId,marketIndex,positionId,first_value(evt_block_time) OVER (PARTITION BY primaryAccount, subAccountId, marketIndex, positionIdORDER BY evt_block_time ASC) AS first_open_timeFROM flexperp_base.TradeService_evt_LogIncreasePositionWHERE size = increasedSizeAND realizedPnl = 0AND price = avgEntryPriceAND evt_block_time >= (SELECT start_time FROM config)AND evt_block_time <= (SELECT end_time FROM config)