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

Pass asset info in trade agg #15

Merged
merged 3 commits into from
Jan 23, 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
54 changes: 54 additions & 0 deletions models/intermediate/trades/int_trade_agg_day.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ with
date('{{ dbt_airflow_macros.ds() }}') as day_agg
, ledger_closed_at
, selling_asset_id
, selling_asset_code
, selling_asset_issuer
, selling_asset_type
, buying_asset_id
, buying_asset_code
, buying_asset_issuer
, buying_asset_type
, concat(history_operation_id, `order`) as trade_key
, price_n
, price_d
Expand All @@ -29,7 +35,13 @@ with
day_agg
, ledger_closed_at
, selling_asset_id as asset_a
, selling_asset_code as asset_a_code
, selling_asset_issuer as asset_a_issuer
, selling_asset_type as asset_a_type
, buying_asset_id as asset_b
, buying_asset_code as asset_b_code
, buying_asset_issuer as asset_b_issuer
, buying_asset_type as asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -41,7 +53,13 @@ with
day_agg
, ledger_closed_at
, selling_asset_id as asset_b
, selling_asset_code as asset_b_code
, selling_asset_issuer as asset_b_issuer
, selling_asset_type as asset_b_type
, buying_asset_id as asset_a
, buying_asset_code as asset_a_code
, buying_asset_issuer as asset_a_issuer
, buying_asset_type as asset_a_type
, trade_key
, price_n
, price_d
Expand All @@ -56,7 +74,13 @@ with
day_agg
, ledger_closed_at
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -76,7 +100,13 @@ with
day_agg
, ledger_closed_at
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -91,7 +121,13 @@ with
select
day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, count(trade_key) as trade_count_daily
, sum(asset_a_amount) as asset_a_volume_daily
, sum(asset_b_amount) as asset_b_volume_daily
Expand All @@ -102,15 +138,27 @@ with
group by
day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
)

/* obtain window function metrics for the asset pair */
, trade_day_agg_window as (
select
day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, ledger_closed_at
, first_value(price_n) over (
partition by
Expand Down Expand Up @@ -155,7 +203,13 @@ with
select
trade_day_agg_group.day_agg
, trade_day_agg_group.asset_a
, trade_day_agg_group.asset_a_code
, trade_day_agg_group.asset_a_issuer
, trade_day_agg_group.asset_a_type
, trade_day_agg_group.asset_b
, trade_day_agg_group.asset_b_code
, trade_day_agg_group.asset_b_issuer
, trade_day_agg_group.asset_b_type
, trade_day_agg_group.trade_count_daily
, trade_day_agg_group.asset_a_volume_daily
, trade_day_agg_group.asset_b_volume_daily
Expand Down
54 changes: 54 additions & 0 deletions models/intermediate/trades/int_trade_agg_month.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ with
ledger_closed_at
, cast(ledger_closed_at as date) as day_agg
, selling_asset_id
, selling_asset_code
, selling_asset_issuer
, selling_asset_type
, buying_asset_id
, buying_asset_code
, buying_asset_issuer
, buying_asset_type
, concat(history_operation_id, `order`) as trade_key
, price_n
, price_d
Expand All @@ -29,7 +35,13 @@ with
day_agg
, ledger_closed_at
, selling_asset_id as asset_a
, selling_asset_code as asset_a_code
, selling_asset_issuer as asset_a_issuer
, selling_asset_type as asset_a_type
, buying_asset_id as asset_b
, buying_asset_code as asset_b_code
, buying_asset_issuer as asset_b_issuer
, buying_asset_type as asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -41,7 +53,13 @@ with
day_agg
, ledger_closed_at
, selling_asset_id as asset_b
, selling_asset_code as asset_b_code
, selling_asset_issuer as asset_b_issuer
, selling_asset_type as asset_b_type
, buying_asset_id as asset_a
, buying_asset_code as asset_a_code
, buying_asset_issuer as asset_a_issuer
, buying_asset_type as asset_a_type
, trade_key
, price_n
, price_d
Expand All @@ -56,7 +74,13 @@ with
day_agg
, ledger_closed_at
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -76,7 +100,13 @@ with
day_agg
, ledger_closed_at
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -91,7 +121,13 @@ with
select
date('{{ dbt_airflow_macros.ds() }}') as day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, count(trade_key) as trade_count_monthly
, sum(asset_a_amount) as asset_a_volume_monthly
, sum(asset_b_amount) as asset_b_volume_monthly
Expand All @@ -102,15 +138,27 @@ with
where cast(ledger_closed_at as date) >= date_sub(date('{{ dbt_airflow_macros.ds() }}'), interval 30 day)
group by
asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
)

/* obtain window function metrics for the asset pair */
, trade_day_agg_window as (
select
day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, ledger_closed_at
, first_value(price_n) over (
partition by
Expand Down Expand Up @@ -156,7 +204,13 @@ with
select
trade_day_agg_group.day_agg
, trade_day_agg_group.asset_a
, trade_day_agg_group.asset_a_code
, trade_day_agg_group.asset_a_issuer
, trade_day_agg_group.asset_a_type
, trade_day_agg_group.asset_b
, trade_day_agg_group.asset_b_code
, trade_day_agg_group.asset_b_issuer
, trade_day_agg_group.asset_b_type
, trade_day_agg_group.trade_count_monthly
, trade_day_agg_group.asset_a_volume_monthly
, trade_day_agg_group.asset_b_volume_monthly
Expand Down
54 changes: 54 additions & 0 deletions models/intermediate/trades/int_trade_agg_week.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ with
ledger_closed_at
, cast(ledger_closed_at as date) as day_agg
, selling_asset_id
, selling_asset_code
, selling_asset_issuer
, selling_asset_type
, buying_asset_id
, buying_asset_code
, buying_asset_issuer
, buying_asset_type
, concat(history_operation_id, `order`) as trade_key
, price_n
, price_d
Expand All @@ -29,7 +35,13 @@ with
day_agg
, ledger_closed_at
, selling_asset_id as asset_a
, selling_asset_code as asset_a_code
, selling_asset_issuer as asset_a_issuer
, selling_asset_type as asset_a_type
, buying_asset_id as asset_b
, buying_asset_code as asset_b_code
, buying_asset_issuer as asset_b_issuer
, buying_asset_type as asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -41,7 +53,13 @@ with
day_agg
, ledger_closed_at
, selling_asset_id as asset_b
, selling_asset_code as asset_b_code
, selling_asset_issuer as asset_b_issuer
, selling_asset_type as asset_b_type
, buying_asset_id as asset_a
, buying_asset_code as asset_a_code
, buying_asset_issuer as asset_a_issuer
, buying_asset_type as asset_a_type
, trade_key
, price_n
, price_d
Expand All @@ -56,7 +74,13 @@ with
day_agg
, ledger_closed_at
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -76,7 +100,13 @@ with
day_agg
, ledger_closed_at
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, trade_key
, price_n
, price_d
Expand All @@ -91,7 +121,13 @@ with
select
date('{{ dbt_airflow_macros.ds() }}') as day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, count(trade_key) as trade_count_weekly
, sum(asset_a_amount) as asset_a_volume_weekly
, sum(asset_b_amount) as asset_b_volume_weekly
Expand All @@ -102,15 +138,27 @@ with
where cast(ledger_closed_at as date) >= date_sub(date('{{ dbt_airflow_macros.ds() }}'), interval 7 day)
group by
asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
)

/* obtain window function metrics for the asset pair */
, trade_day_agg_window as (
select
day_agg
, asset_a
, asset_a_code
, asset_a_issuer
, asset_a_type
, asset_b
, asset_b_code
, asset_b_issuer
, asset_b_type
, ledger_closed_at
, first_value(price_n) over (
partition by
Expand Down Expand Up @@ -156,7 +204,13 @@ with
select
trade_day_agg_group.day_agg
, trade_day_agg_group.asset_a
, trade_day_agg_group.asset_a_code
, trade_day_agg_group.asset_a_issuer
, trade_day_agg_group.asset_a_type
, trade_day_agg_group.asset_b
, trade_day_agg_group.asset_b_code
, trade_day_agg_group.asset_b_issuer
, trade_day_agg_group.asset_b_type
, trade_day_agg_group.trade_count_weekly
, trade_day_agg_group.asset_a_volume_weekly
, trade_day_agg_group.asset_b_volume_weekly
Expand Down
Loading