brian-terraVertex - Monthly Stats copy
    Updated 2024-03-11
    -- forked from Vertex - Monthly Stats @ https://flipsidecrypto.xyz/edit/queries/f5569d41-4c99-4462-90f8-7567d9400030

    -- forked from Vertex - Daily Stats @ https://flipsidecrypto.xyz/edit/queries/c4a68ed6-3525-4c92-983c-b1b3b13619e1

    WITH qMain as (
    SELECT DISTINCT
    block_timestamp,
    tx_hash,
    contract_address,
    symbol,
    trader,
    amount_usd,
    fee_amount,
    'perp' AS label
    FROM arbitrum.vertex.ez_perp_trades

    UNION ALL

    SELECT DISTINCT
    block_timestamp,
    tx_hash,
    contract_address,
    symbol,
    trader,
    amount_usd,
    fee_amount,
    'spot' AS label
    FROM arbitrum.vertex.ez_spot_trades
    )

    select sum(total_amount_both) from

    (SELECT date_trunc('month', block_timestamp) AS month,
    COUNT(DISTINCT CASE WHEN label = 'spot' THEN trader END) AS distinct_spot_traders,
    COUNT(DISTINCT CASE WHEN label = 'perp' THEN trader END) AS distinct_perp_traders,
    COUNT(DISTINCT trader) AS distinct_total_traders,
    QueryRunArchived: QueryRun has been archived