mamad-5XN3k3Aptos CEX 4
    Updated 2024-08-06
    with pricet as (
    SELECT
    TO_TIMESTAMP(value[0]::string) as p_date,
    'APT' as symbol,
    value[1] as usd_price
    from (
    SELECT livequery.live.udf_api(
    'https://api.coingecko.com/api/v3/coins/aptos/market_chart?vs_currency=usd&days=90&interval=daily&precision=3') as resp)
    ,LATERAL FLATTEN (input => resp:data:prices)
    WHERE p_date >= Current_date() - 90
    ),

    cext as (
    SELECT
    DISTINCT ADDRESS ,
    ADDRESS_NAME
    FROM aptos.core.dim_labels
    where LABEL_TYPE = 'cex'
    and LABEL_SUBTYPE = 'hot_wallet'
    )


    select
    --distinct ADDRESS_NAME,
    count(DISTINCT TX_HASH) as txs,
    count(DISTINCT user) as users,
    sum(case when type = 'OutFlow' then vol else 0 end) as outflows,
    sum(case when type = 'InFlow' then vol else 0 end) as InFlows,
    sum(vol) as amount,
    sum(usd_vol) as usd_amount
    from(
    SELECT
    'OutFlow' as type,
    --rtrim(BLOCK_TIMESTAMP::date) as date,
    ADDRESS_NAME,
    TX_HASH,
    QueryRunArchived: QueryRun has been archived