Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prediction market metrics to ez_drift_metrics_by_chain #412

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions models/projects/drift/core/ez_drift_metrics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{
config(
materialized="table",
snowflake_warehouse="DRIFT",
database="drift",
schema="core",
alias="ez_metrics",
)
}}

SELECT
date,
'drift' AS app,
'DeFi' AS category,
"'TRUMP-WIN-2024-BET'" AS trump_prediction_market_100k_buy_order_price,
"'KAMALA-POPULAR-VOTE-2024-BET'" AS kamala_prediction_market_100k_buy_order_price
FROM {{ ref("fact_drift_prediction_markets") }}
PIVOT(SUM(PREDICTION_MARKET_100K_BUY_ORDER_PRICE) FOR market IN (ANY ORDER BY market))
4 changes: 2 additions & 2 deletions models/staging/drift/__drift__sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ sources:
database: LANDING_DATABASE
tables:
- name: raw_drift_trading_volume
- name: raw_drift_fill_price_kamala
- name: raw_drift_fill_price_trump
- name: raw_drift_fill_price_by_market

31 changes: 8 additions & 23 deletions models/staging/drift/fact_drift_prediction_markets.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
{{ config(materialized="table") }}
with
trump_data as (
select
DATE_TRUNC('DAY', extraction_date)::date as date,
source_json as trump_price
from {{ source("PROD_LANDING", "raw_drift_fill_price_trump") }}
), kamala_data as (
select
DATE_TRUNC('DAY', extraction_date)::date as date,
source_json as kamala_price
from {{ source("PROD_LANDING", "raw_drift_fill_price_kamala") }}
)

select
trump_data.date,
'drift' as app,
'DeFi' as category,
'solana' as chain,
trump_price,
kamala_price
from trump_data
left join kamala_data
on trump_data.date = kamala_data.date

SELECT
DATEADD('DAY', -1, DATE_TRUNC('DAY', extraction_date)::date) AS date,
value:market::varchar as market,
AVG(value:average_fill_price) as prediction_market_100k_buy_order_price
FROM {{ source("PROD_LANDING", "raw_drift_fill_price_by_market") }},
lateral flatten(input => parse_json(source_json))
GROUP BY
1, 2
Loading