flyingfishc - Stats by indexToken
    Updated 2024-01-29
    -- forked from b - Stats by Wallet @ https://flipsidecrypto.xyz/edit/queries/1259b517-e7fe-498b-9753-a15858791d0d

    -- forked from a Base Query For Pairs Traded @ https://flipsidecrypto.xyz/edit/queries/2cf751c5-e596-48a6-b857-db02672f8fc5

    with raw_data AS (
    SELECT
    block_timestamp
    , origin_from_address AS wallet
    , decoded_log:indexToken AS index_token
    , name
    , symbol
    , decoded_log:amountIn / pow(10, 6) AS pos_size
    , decoded_log:sizeDelta / pow(10, 30) AS open_size
    , open_size / pos_size AS leverage
    , decoded_log:isLong::boolean AS is_long
    , decoded_log:executionFee / pow(10, 18) AS execution_fee
    , tx_hash
    FROM arbitrum.core.ez_decoded_event_logs
    LEFT JOIN arbitrum.core.dim_contracts on index_token = address
    -- WHERE block_timestamp::date > current_date - 2
    WHERE block_timestamp > '2023-08-30'
    AND origin_to_address = '0x75f688604a58c720e7e4496139765498a2563c78' -- Pear Contract Address
    AND event_name = 'CreateIncreasePosition'
    AND tx_status = 'SUCCESS'
    ORDER BY event_index
    )
    SELECT
    name
    , symbol
    , count(DISTINCT wallet) AS unique_users
    , count(DISTINCT tx_hash) AS pear_trades
    , sum(iff(is_long, 1, 0)) AS long_pos
    , sum(iff(is_long, 0, 1)) AS short_pos
    , sum(iff(is_long, pos_size, 0)) AS long_collateral
    , sum(iff(is_long, 0, pos_size)) AS short_collateral
    , sum(pos_size) AS total_collateral
    Last run: over 1 year agoAuto-refreshes every 24 hours
    NAME
    SYMBOL
    UNIQUE_USERS
    PEAR_TRADES
    LONG_POS
    SHORT_POS
    LONG_COLLATERAL
    SHORT_COLLATERAL
    TOTAL_COLLATERAL
    AVG(LEVERAGE)
    1
    Wrapped BTCWBTC792991231761428.2399142047.0908043475.330718974.27288688
    2
    Wrapped EtherWETH84281188932170.906191055.1661093226.072299169.547663124
    3
    ChainLink TokenLINK461095356611.261963651.390641262.65260316.980287977
    4
    UniswapUNI33751758194.719466671.47998866.19944618.975447643
    4
    337B
    6s