-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alter Swap model to make Candlestick views with
timescaledb.continuous
- Loading branch information
1 parent
4e3b8cc
commit c15bfb2
Showing
8 changed files
with
111 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
src/demo_uniswap/sql/on_reindex/01_create_mv_token_price.sql
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
src/demo_uniswap/sql/on_reindex/10_create_mv_quotes_1m.sql
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
src/demo_uniswap/sql/on_reindex/11_create_mv_quotes_1d.sql
This file was deleted.
Oops, something went wrong.
61 changes: 36 additions & 25 deletions
61
src/demo_uniswap/sql/on_reindex/20_create_ca_quotes_1m.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
-- CREATE MATERIALIZED VIEW | ||
-- candlestick_1m | ||
-- WITH (timescaledb.continuous) AS | ||
-- | ||
-- SELECT | ||
-- time_bucket('1 minute'::INTERVAL, to_timestamp(timestamp)) AS bucket, | ||
-- token0_id as token_id, | ||
-- candlestick_agg( | ||
-- to_timestamp(timestamp), | ||
-- abs(amount_usd/amount0), | ||
-- amount_usd | ||
-- ) as candlestick | ||
-- FROM swap | ||
-- WHERE | ||
-- amount_usd!=0 | ||
-- AND | ||
-- amount0!=0 | ||
-- | ||
-- GROUP BY | ||
-- bucket, | ||
-- token0_id | ||
-- ORDER BY | ||
-- bucket, | ||
-- token0_id | ||
-- WITH NO DATA; | ||
CREATE MATERIALIZED VIEW | ||
candlestick_1m | ||
WITH (timescaledb.continuous) AS | ||
|
||
SELECT | ||
time_bucket('1 minute'::INTERVAL, timestamp) AS bucket, | ||
token0_id as token_id, | ||
candlestick_agg( | ||
timestamp, | ||
abs(amount_usd/amount0), | ||
amount_usd | ||
) as candlestick | ||
FROM swap | ||
WHERE | ||
amount_usd!=0 | ||
AND | ||
amount0!=0 | ||
|
||
GROUP BY | ||
bucket, | ||
token0_id | ||
ORDER BY | ||
bucket, | ||
token0_id | ||
WITH NO DATA; | ||
|
||
CREATE INDEX candlestick_1m_bucket ON candlestick_1m(bucket); | ||
CREATE INDEX candlestick_1m_token_id ON candlestick_1m(token_id); | ||
|
||
SELECT add_continuous_aggregate_policy( | ||
'candlestick_1m', | ||
start_offset => INTERVAL '1 hour', | ||
end_offset => INTERVAL '0 minutes', | ||
schedule_interval => INTERVAL '1 minute', | ||
initial_start := '2018-07-01' | ||
); |
25 changes: 0 additions & 25 deletions
25
src/demo_uniswap/sql/on_reindex/21_create_ca_quotes_1d.sql
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/demo_uniswap/sql/on_reindex/21_create_ca_quotes_1h.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CREATE MATERIALIZED VIEW | ||
candlestick_1h | ||
WITH (timescaledb.continuous) AS | ||
|
||
SELECT | ||
time_bucket('1 hour'::INTERVAL, timestamp) AS bucket, | ||
token0_id as token_id, | ||
candlestick_agg( | ||
timestamp, | ||
abs(amount_usd/amount0), | ||
amount_usd | ||
) as candlestick | ||
FROM swap | ||
WHERE | ||
amount_usd!=0 | ||
AND | ||
amount0!=0 | ||
|
||
GROUP BY | ||
bucket, | ||
token0_id | ||
ORDER BY | ||
bucket, | ||
token0_id | ||
WITH NO DATA; | ||
|
||
CREATE INDEX candlestick_1h_bucket ON candlestick_1h(bucket); | ||
CREATE INDEX candlestick_1h_token_id ON candlestick_1h(token_id); | ||
|
||
SELECT add_continuous_aggregate_policy( | ||
'candlestick_1h', | ||
start_offset => INTERVAL '2 hour', | ||
end_offset => INTERVAL '0 minutes', | ||
schedule_interval => INTERVAL '1 hour', | ||
initial_start := '2018-07-01' | ||
); |
36 changes: 36 additions & 0 deletions
36
src/demo_uniswap/sql/on_reindex/22_create_ca_quotes_1d.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CREATE MATERIALIZED VIEW | ||
candlestick_1d | ||
WITH (timescaledb.continuous) AS | ||
|
||
SELECT | ||
time_bucket('1 day'::INTERVAL, timestamp) AS bucket, | ||
token0_id as token_id, | ||
candlestick_agg( | ||
timestamp, | ||
abs(amount_usd/amount0), | ||
amount_usd | ||
) as candlestick | ||
FROM swap | ||
WHERE | ||
amount_usd!=0 | ||
AND | ||
amount0!=0 | ||
|
||
GROUP BY | ||
bucket, | ||
token0_id | ||
ORDER BY | ||
bucket, | ||
token0_id | ||
WITH NO DATA; | ||
|
||
CREATE INDEX candlestick_1d_bucket ON candlestick_1d(bucket); | ||
CREATE INDEX candlestick_1d_token_id ON candlestick_1d(token_id); | ||
|
||
SELECT add_continuous_aggregate_policy( | ||
'candlestick_1d', | ||
start_offset => INTERVAL '2 days', | ||
end_offset => INTERVAL '0 minutes', | ||
schedule_interval => INTERVAL '1 hour', | ||
initial_start := '2018-07-01' | ||
); |