John_GaltHALO LBP Buy Vol, Sell Vol, Price
    Updated 2022-04-14
    with table1 as (select
    date_trunc('hour', block_timestamp) as date,
    event_attributes:ask_asset as ask,
    event_attributes:offer_amount / pow(10, 6) as offer,
    event_attributes:return_amount / pow(10, 6) as returnn,
    case
    when ask = 'uusd' then returnn
    else 0
    end as ust_from_sold_angel,
    case
    when ask = 'terra1w8kvd6cqpsthupsk4l0clwnmek4l3zr7c84kwq' then offer
    else 0
    end as ust_to_buy_angel,
    case
    when ask = 'terra1w8kvd6cqpsthupsk4l0clwnmek4l3zr7c84kwq' then returnn
    else 0
    end as bought_angel,
    ust_to_buy_angel / nullif(bought_angel, 0) as angel_price
    from terra.msg_events
    where date(block_timestamp) between '2021-12-01' and '2021-12-30'
    and (event_attributes:ask_asset = 'terra1w8kvd6cqpsthupsk4l0clwnmek4l3zr7c84kwq' or event_attributes:ask_asset = 'uusd')
    and (event_attributes:"0_contract_address" = 'terra1hhpgcp2stvzx952zfxtxg4dhgf60yfzchesj3e'
    or event_attributes:"1_contract_address" = 'terra1hhpgcp2stvzx952zfxtxg4dhgf60yfzchesj3e')
    and event_index = 3
    ),

    table2 as (select date, sum(ust_from_sold_angel) as sell, sum(ust_to_buy_angel) as buy, avg(angel_price) as angel_price
    from table1
    group by date
    order by date
    )

    select * from table2
    Run a query to Download Data