Sbhn_NPcustom wallet profit nft
    Updated 2023-02-04
    with pricesol AS (
    select
    RECORDED_HOUR::date as date,
    avg(close) as usdprice
    from solana.core.fact_token_prices_hourly where SYMBOL='SOL'
    group by 1),

    buy as ( select
    purchaser,
    sum(sales_amount*usdprice) as vol_buy
    from solana.core.fact_nft_sales a
    join pricesol b on a.block_timestamp::date=b.date
    where succeeded='TRUE'
    and block_timestamp>=CURRENT_DATE- {{N_Days}}
    and sales_amount >0
    group by 1
    ),

    sell as ( select
    seller,
    sum(sales_amount*usdprice) as vol_sell
    from solana.core.fact_nft_sales a
    join pricesol b on a.block_timestamp::date=b.date
    where succeeded='TRUE'
    and block_timestamp>=CURRENT_DATE- {{N_Days}}
    and sales_amount >0
    group by 1
    )

    select
    purchaser as trader,
    sum(vol_sell-vol_buy) as profit
    from buy
    join sell on buy.purchaser=sell.seller
    where purchaser = '{{Wallet_Address}}'
    group by 1

    Run a query to Download Data