Ali3NVertex Traders Leaderboard (Top 100)
    Updated 2024-08-27
    -- forked from Average Traders Total Stats (Vertex Arbitrum) @ https://flipsidecrypto.xyz/edit/queries/27ae245b-8a73-45f2-9a12-a453ae6d9af8

    -- Got Some Inspirations from Vertex - Daily Stats @ https://flipsidecrypto.xyz/edit/queries/c4a68ed6-3525-4c92-983c-b1b3b13619e1
    with maintable as (
    select 'Perpetual' as Trading_Type,
    block_timestamp,
    tx_hash,
    contract_address,
    symbol,
    trader,
    amount_usd,
    fee_amount,
    is_taker
    from arbitrum.vertex.ez_perp_trades
    UNION ALL

    select 'Spot' as Trading_Type,
    block_timestamp,
    tx_hash,
    contract_address,
    symbol,
    trader,
    amount_usd,
    fee_amount,
    is_taker
    from arbitrum.vertex.ez_spot_trades)

    select trader as "Trader Wallet Address",
    sum (case when is_taker = 'true' then amount_usd else 0 end) as "Total Trading Volume [$]",
    sum (case when is_taker ='true' and trading_type = 'Spot' then amount_usd else 0 end) as "Spot Trading Volume [$]",
    sum (case when is_taker ='true' and trading_type = 'Perpetual' then amount_usd else 0 end) as "Perpetual Trading Volume [$]",
    count (distinct tx_hash) as "Total Transactions",
    count (distinct case when trading_type = 'Spot' then tx_hash end) as "Spot Transactions",
    count (distinct case when trading_type = 'Perpetual' then tx_hash end) as "Perpetual Transactions",
    sum (fee_amount) as "Total Paid Fees [$]",
    Auto-refreshes every 24 hours
    QueryRunArchived: QueryRun has been archived