Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt authored Feb 20, 2024
1 parent 3c48b8f commit 304fc23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- This file should undo anything in `up.sql`
ALTER MATERIALIZED VIEW twap_2_hours_agg SET SCHEMA (
SELECT
pair_id,
time_bucket('2 hours'::interval, timestamp) as bucket,
average(time_weight('Linear', timestamp, price))::numeric as price_twap,
COUNT(DISTINCT source) as num_sources
FROM entries
GROUP BY bucket, pair_id
)
16 changes: 16 additions & 0 deletions pragma-entities/migrations/2024-02-20-090454_fix_twap_aggs/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Your SQL goes here
ALTER MATERIALIZED VIEW twap_2_hours_agg SET SCHEMA (
SELECT
pair_id,
time_bucket('2 hours'::interval, timestamp) as bucket,
interpolated_average(
time_weight('Linear', timestamp, price),
bucket,
'2 hours'::interval,
lag(agg) OVER (ORDER BY bucket),
lead(agg) OVER (ORDER BY bucket)
)::numeric as price_twap,
COUNT(DISTINCT source) as num_sources
FROM entries
GROUP BY bucket, pair_id
)

0 comments on commit 304fc23

Please sign in to comment.