ArioVertex - Weekly trading volume and traders by type
    Updated 2024-09-27
    with main as (
    SELECT
    'Spot' as Type,
    block_timestamp,
    TRADER,
    tx_hash,
    AMOUNT_USD,
    FEE_AMOUNT
    from arbitrum.vertex.ez_spot_trades
    where IS_TAKER = 'TRUE'

    union all

    SELECT
    'Perp' as Type,
    block_timestamp,
    TRADER,
    tx_hash,
    AMOUNT_USD,
    FEE_AMOUNT
    from arbitrum.vertex.ez_perp_trades
    where IS_TAKER = 'TRUE'
    )
    select
    date_trunc(week, block_timestamp) as date,
    count(DISTINCT case when Type = 'Spot' then TRADER end) as "Spot Trader",
    count(DISTINCT case when Type = 'Perp' then TRADER end) as "Perp Trader",
    "Spot Trader" + "Perp Trader" as "Total # Traders",
    count(DISTINCT case when Type = 'Spot' then tx_hash end) as "Spot Trade",
    count(DISTINCT case when Type = 'Perp' then tx_hash end) as "Perp Trade",
    "Spot Trade" + "Perp Trade" as "Total # Trades",
    sum(case when Type = 'Spot' then zeroifnull(AMOUNT_USD) end) as "Spot Volume",
    sum(case when Type = 'Perp' then zeroifnull(AMOUNT_USD) end) as "Perp Volume",
    sum(zeroifnull(AMOUNT_USD)) as "Total Trading Volume",
    sum(case when Type = 'Spot' then zeroifnull(FEE_AMOUNT) end) as "Spot Fee",
    sum(case when Type = 'Perp' then zeroifnull(FEE_AMOUNT) end) as "Perp Fee",
    QueryRunArchived: QueryRun has been archived