Add kraken_minute table with 15-second polling
1-minute OHLC candles from Kraken, polled every 15 seconds to keep the in-progress candle fresh. Unlike hourly/daily pollers, this one keeps the last candle and upserts it as it updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS kraken_minute;
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE kraken_minute (
|
||||
ts BIGINT NOT NULL PRIMARY KEY,
|
||||
open NUMERIC(18,8) NOT NULL,
|
||||
high NUMERIC(18,8) NOT NULL,
|
||||
low NUMERIC(18,8) NOT NULL,
|
||||
close NUMERIC(18,8) NOT NULL,
|
||||
vwap NUMERIC(18,8) NOT NULL,
|
||||
volume NUMERIC(24,8) NOT NULL,
|
||||
trade_count INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
@@ -155,6 +155,23 @@ SELECT id, event_id, occurred_at, exchange, fiat_amount, fiat_currency,
|
||||
FROM deposits
|
||||
ORDER BY occurred_at DESC, id DESC
|
||||
|
||||
-- :name upsert-kraken-minute! :! :n
|
||||
-- :doc Upsert a Kraken minute OHLC candle
|
||||
INSERT INTO kraken_minute (ts, open, high, low, close, vwap, volume, trade_count)
|
||||
VALUES (:ts, :open, :high, :low, :close, :vwap, :volume, :trade-count)
|
||||
ON CONFLICT (ts) DO UPDATE
|
||||
SET open = EXCLUDED.open,
|
||||
high = EXCLUDED.high,
|
||||
low = EXCLUDED.low,
|
||||
close = EXCLUDED.close,
|
||||
vwap = EXCLUDED.vwap,
|
||||
volume = EXCLUDED.volume,
|
||||
trade_count = EXCLUDED.trade_count
|
||||
|
||||
-- :name get-latest-kraken-minute :? :1
|
||||
-- :doc Get the most recent Kraken minute candle timestamp
|
||||
SELECT ts FROM kraken_minute ORDER BY ts DESC LIMIT 1
|
||||
|
||||
-- :name get-wallet-balances :? :*
|
||||
-- :doc Compute sats balance per wallet from events
|
||||
SELECT w.id, w.name,
|
||||
|
||||
@@ -63,6 +63,10 @@
|
||||
{:query-fn #ig/ref :db.sql/query-fn
|
||||
:enabled? #or [#env KRAKEN_ENABLED "true"]}
|
||||
|
||||
:kraken/ohlc-minute
|
||||
{:query-fn #ig/ref :db.sql/query-fn
|
||||
:enabled? #or [#env KRAKEN_ENABLED "true"]}
|
||||
|
||||
:frankfurter/rates
|
||||
{:url #or [#env FRANKFURTER_URL "http://localhost:8080"]
|
||||
:query-fn #ig/ref :db.sql/query-fn}
|
||||
|
||||
Reference in New Issue
Block a user