CryptoLionlimit orders
    Updated 2022-10-04
    with a as (
    SELECT DISTINCT
    date_trunc('day', block_timestamp) as day,
    pool_name,
    pool_address,
    last_value(token0_balance_usd + token1_balance_usd) over (partition by pool_name order by day) as liq,
    last_value(virtual_liquidity_adjusted) over (partition by pool_name order by day) as vliq,
    last_value(price_0_1) over (partition by pool_name order by day) as cp
    FROM uniswapv3.pool_stats ps1
    WHERE block_timestamp >= getdate() - interval '2 day'
    AND token0_balance_usd >= 0
    AND token1_balance_usd >= 0
    --
    -- AND pool_name LIKE 'WBTC-WETH%'
    --
    HAVING day = '2021-06-12'
    ORDER BY 4 DESC
    LIMIT 15),

    b as (
    SELECT DISTINCT
    -- block_timestamp,
    last_value(liquidity_provider) over (partition by liquidity_provider, po.pool_name order by block_timestamp) as liq_provider,
    last_value(po.pool_name) over (partition by liquidity_provider, po.pool_name order by block_timestamp) as pool_name,
    last_value(liquidity_adjusted) over (partition by liquidity_provider, po.pool_name order by block_timestamp) as liq_adj,
    last_value(price_lower_0_1) over (partition by liquidity_provider, po.pool_name order by block_timestamp) as pl,
    last_value(price_upper_0_1) over (partition by liquidity_provider, po.pool_name order by block_timestamp) as pu
    FROM uniswapv3.positions po
    INNER JOIN a on po.pool_name = a.pool_name
    WHERE
    is_active = 'TRUE'
    )

    -- SELECT *
    -- FROM a

    Run a query to Download Data