Query editor
/* ============================================================Aftermath Order Counter (Perps + afLP)Uses actual AF event names:- PostedOrder- CanceledOrder- FilledTakerOrder, FilledMakerOrders- (optional) ExecutedStopOrderTicket============================================================ */WITH aftermath_events AS (SELECTFROM_UNIXTIME(t.timestamp_ms/1000) AS event_time,CASEWHEN e.event_type LIKE '%::events::PostedOrder' THEN 'order_placed'WHEN e.event_type LIKE '%::events::CanceledOrder' THEN 'order_canceled'WHEN e.event_type LIKE '%::events::FilledTakerOrder' THEN 'order_filled'-- FilledMakerOrders is emitted 1:1 with FilledTakerOrder in the same tx;-- counting both double-counts every fill, so only the taker side is counted.-- ExecutedStopOrderTicket rides along with the Filled* pair, so it is not counted again.ELSE NULLEND AS event_typeFROM sui.transactions tJOIN sui.events eON t.transaction_digest = e.transaction_digestWHERE t.date >= CURRENT_DATE - INTERVAL '7' DAYAND (e.event_type LIKE '0x9196fffe0341b2f0ca7424926b22d9e9e35b4807a1f625fc20eeea1382d08dec%'OR e.event_type LIKE '0xbab1b714c5533a46ee27a9c124d6f9281ca54831fc288d4d0c133dae3a57254a%'OR e.event_type LIKE '%9196fffe0341b2f0ca7424926b22d9e9e35b4807a1f625fc20eeea1382d08dec%'OR e.event_type LIKE '%bab1b714c5533a46ee27a9c124d6f9281ca54831fc288d4d0c133dae3a57254a%'OR e.event_type LIKE '%3ec740df8428aa9c93aaef7f8cc1542ac3194fd014826b51bfe245346d64efc7%')AND (e.event_type LIKE '%::events::PostedOrder'OR e.event_type LIKE '%::events::CanceledOrder'OR e.event_type LIKE '%::events::FilledTakerOrder'OR e.event_type LIKE '%::events::FilledMakerOrders'OR e.event_type LIKE '%::events::ExecutedStopOrderTicket%')),latest_time AS (SELECT MAX(event_time) AS max_timeFROM aftermath_eventsWHERE event_type IS NOT NULL)SELECT-- Last 1 hourCOUNT_IF(event_type = 'order_placed' AND event_time > l.max_time - INTERVAL '1' HOUR) AS orders_placed_1h,COUNT_IF(event_type = 'order_canceled' AND event_time > l.max_time - INTERVAL '1' HOUR) AS orders_canceled_1h,COUNT_IF(event_type = 'order_filled' AND event_time > l.max_time - INTERVAL '1' HOUR) AS orders_filled_1h,-- Last 24 hoursCOUNT_IF(event_type = 'order_placed' AND event_time > l.max_time - INTERVAL '24' HOUR) AS orders_placed_24h,COUNT_IF(event_type = 'order_canceled' AND event_time > l.max_time - INTERVAL '24' HOUR) AS orders_canceled_24h,COUNT_IF(event_type = 'order_filled' AND event_time > l.max_time - INTERVAL '24' HOUR) AS orders_filled_24h,