magindigoTotals by Perps Market copy
    Updated 2025-01-14
    -- forked from flyingfish / Totals by Perps Market @ https://flipsidecrypto.xyz/flyingfish/q/SCdhzn5Ad5rB/totals-by-perps-market

    with get_data as (
    select
    -- live.udf_api('https://perp-api.jup.ag/trpc/trades?batch=1&input=%7B%220%22%3A%7B%22json%22%3A%7B%22wallet%22%3A%22{{address}}%22%2C%22limit%22%3A{__{trades_count}__}%2C%22offset%22%3A0%7D%7D%7D') as resp
    live.udf_api('https://perp-api.jup.ag/trpc/trades?batch=1&input=%7B%220%22%3A%7B%22json%22%3A%7B%22wallet%22%3A%22{{address}}%22%2C%22limit%22%3A10000%2C%22offset%22%3A0%7D%7D%7D') as resp
    )

    , date_filtered as (
    select
    iff('{{full_trade_history}}' = 'Yes', '2023-07-18', '{{start_date}}') as start_date_filter
    , iff('{{full_trade_history}}' = 'Yes', current_date, '{{end_date}}') as end_date_filter

    )
    , parsed_data as (

    select
    value:updatedAt::timestamp as timestamp
    , value:side as side
    , value:requestType as request_type
    , value:requestChange as request_change
    , value:custody as custody
    , value:mint as market
    , value:collateralMint as collateral_mint
    , value:collateralUsd as collateral_usd
    , value:sizeUsd as size_usd
    , zeroifnull(value:feeUsd) as fee_usd
    , zeroifnull(value:liquidationFeeUsd) as liquidation_fee_usd
    , value:price as price
    , value:priceSlippage as price_slippage
    , zeroifnull(value:pnlUsd) as pnl
    , value:positionKey as position_key
    , value:txId as tx_id
    from get_data
    , lateral flatten (input => resp:data[0]:result:data:json:trades)
    )
    Last run: about 2 months ago
    Perps Market
    Actions count
    Collateral Deployed
    Total Size
    Open Interest
    Profit & Loss
    Total Trading Fees
    NET Profit & Loss
    1
    ETH519765.89474738.41014546.6822476.17712070.505
    2
    SOL414581141.55619564643.540637681.36557326.39580354.975
    2
    129B
    18s