elsina2024-07-04: netflow poaitions by token
    Updated 2024-08-13
    with positions as (
    SELECT
    date_trunc('day', block_timestamp) as date,
    'long' as position,
    COUNT(DISTINCT tx_hash) AS transaction_count,
    COUNT(DISTINCT trader) AS unique_trader_count,
    SUM(amount_usd) AS transaction_volume
    FROM
    blast.blitz.ez_perp_trades
    WHERE
    trader != '0x0000000000000000000000000000000000000000' and
    trade_type = 'buy/long' and
    symbol = '{{token_name}}'
    group by date

    union

    SELECT
    date_trunc('day', block_timestamp) as date,
    'short' as position,
    COUNT(DISTINCT tx_hash) AS transaction_count,
    COUNT(DISTINCT trader) AS unique_trader_count,
    -SUM(amount_usd) AS transaction_volume
    FROM
    blast.blitz.ez_perp_trades
    WHERE
    trader != '0x0000000000000000000000000000000000000000' and
    trade_type = 'sell/short' and
    symbol = '{{token_name}}'
    group by date
    ),
    net as (
    select
    date,
    sum(transaction_volume) as net_flow
    from positions
    QueryRunArchived: QueryRun has been archived