gihankumarNet Flow
    Updated 2025-04-08
    WITH exchange_addresses AS (
    SELECT DISTINCT address
    FROM bitcoin.core.dim_labels
    WHERE label_type IN ('cex')
    ),

    btc_transfers AS (
    SELECT
    date_trunc('day', block_timestamp) AS date,
    from_entity,
    to_entity,
    TRANSFER_AMOUNT AS btc_transferred
    FROM bitcoin.core.fact_clustered_transfers
    WHERE TRANSFER_AMOUNT > 0
    AND block_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30 days'
    ),
    in_out_flow as(
    SELECT
    date,
    CASE
    WHEN to_entity IN (SELECT address FROM exchange_addresses) THEN 'Inflow' -- Inflow if TO address is an exchange
    WHEN from_entity IN (SELECT address FROM exchange_addresses) THEN 'Outflow' -- Outflow if FROM address is an exchange
    ELSE 'Other'
    END AS flow_type,
    SUM(btc_transferred) AS total_btc
    FROM btc_transfers
    WHERE to_entity IN (SELECT address FROM exchange_addresses)
    OR from_entity IN (SELECT address FROM exchange_addresses)
    GROUP BY 1, 2
    ORDER BY date ASC
    )
    SELECT
    date,
    SUM(CASE WHEN flow_type = 'Inflow' THEN total_btc ELSE 0 END) AS total_inflow,
    SUM(CASE WHEN flow_type = 'Outflow' THEN total_btc ELSE 0 END) AS total_outflow,
    SUM(CASE WHEN flow_type = 'Inflow' THEN total_btc ELSE 0 END) -
    Last run: 2 months ago
    DATE
    TOTAL_INFLOW
    TOTAL_OUTFLOW
    NET_FLOW
    1
    2025-03-09 00:00:00.00029178.713164153599.4734053525579.2397588
    2
    2025-03-10 00:00:00.00091788.7592385418334.5901701673454.16906838
    3
    2025-03-11 00:00:00.00081438.1982637612674.7185167368763.47974703
    4
    2025-03-12 00:00:00.00052917.035731977278.673457545638.36227447
    5
    2025-03-13 00:00:00.00098599.301393918063.9062347990535.39515912
    6
    2025-03-14 00:00:00.00050295.075282479114.9620984941180.11318398
    7
    2025-03-15 00:00:00.00034863.214067463676.1612193431187.05284812
    8
    2025-03-16 00:00:00.00022628.285086963681.9342207518946.35086621
    9
    2025-03-17 00:00:00.00098503.981834468086.0009508190417.98088365
    10
    2025-03-18 00:00:00.00069415.758082787273.4581587662142.29992402
    11
    2025-03-19 00:00:00.00050488.8850309310786.3826417639702.50238917
    12
    2025-03-20 00:00:00.00051262.5747801111375.3030521839887.27172793
    13
    2025-03-21 00:00:00.00043888.426917956148.7295571937739.69736076
    14
    2025-03-22 00:00:00.00018062.538876823226.463912314836.07496452
    15
    2025-03-23 00:00:00.00015165.875906152928.8259776712237.04992848
    16
    2025-03-24 00:00:00.00045950.7447020514841.3496917931109.39501026
    17
    2025-03-25 00:00:00.00050498.4233811511052.224141239446.19923995
    18
    2025-03-26 00:00:00.00047247.249418646508.4831850140738.76623363
    19
    2025-03-27 00:00:00.00048657.387630676302.1856730942355.20195758
    20
    2025-03-28 00:00:00.00055565.787461858697.4975167146868.28994514
    31
    2KB
    4s