with
cex_address as (
select distinct
address,
label,
label_subtype,
address_name
from algorand.labels
where label_type = 'cex'
and label not like '%group%'
),
cex_transfers as (
select
block_timestamp,
tx_id,
sender,
receiver,
amount,
label as cex,
case when p.receiver=c.address then 'to cex'
else 'from cex' end as type
from algorand.payment_transaction p join cex_address c on p.receiver=c.address
where block_timestamp >= '2022-02-06' and block_timestamp <= '2022-02-19'
)
select
date(block_timestamp) as date,
cex,
count(tx_id) as txs,
sum(amount) as amt
from cex_transfers
where type = 'to cex'
group by 1, 2
order by date