Alir3zathe token price - Orion
    Updated 2022-03-16
    SELECT
    date_trunc('day', block_timestamp) as date, -- truncate date to days
    event_attributes:"ask_asset" as token, -- token contract address
    address_name as token_name, -- token contract name
    count(distinct tx_id) as buy_counts,
    count(distinct event_attributes:sender) as buyer_counts,
    sum(event_attributes:"offer_amount"/pow(10,6)) as usd_offered, -- usd_offered
    sum(event_attributes:"return_amount"/pow(10,8)) as alt_bought, -- NEED TO CHANGE DECIMAL POINT IF IT IS ORION
    usd_offered/alt_bought as avg_buy_price -- average daily price of token
    FROM terra.msg_events
    LEFT JOIN terra.labels ON address = event_attributes:"ask_asset" -- LEFT JOIN to attach address name to tokens
    WHERE event_type = 'from_contract'
    AND event_attributes:"offer_asset" = 'uusd' -- UST offered / Q:why do you need this? A:otherwise you cannot calculate price accurately
    AND tx_status = 'SUCCEEDED' -- need to filter by successful transactions
    And block_timestamp >= current_date - 30 -- filtering out observation in last 7 days / change according to your analyses
    ---if you are finding the price of 1 token only
    AND event_attributes:"ask_asset" = 'terra1mddcdx0ujx89f38gu7zspk2r2ffdl5enyz2u03' -- Change by token contract address
    --- if you are finding the price of > 1 token
    -- AND event_attributes:"ask_asset" IN ('terra13zx49nk8wjavedjzu8xkk95r3t0ta43c9ptul7', 'terra12897djskt9rge8dtmm86w654g7kzckkd698608', 'terra1dh9478k2qvqhqeajhn75a2a7dsnf74y5ukregw')
    GROUP BY 1,2,3
    order by 1 ASC
    Run a query to Download Data