Persist Frankfurter EUR/DKK rates in currencies table
Store daily exchange rates in PostgreSQL with EUR/DKK cross rate. Seed rates atom from DB on startup so WebSocket works immediately even if Frankfurter is unreachable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TABLE currencies;
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE currencies (
|
||||
rate_date DATE PRIMARY KEY,
|
||||
eur NUMERIC(12,6) NOT NULL,
|
||||
dkk NUMERIC(12,6) NOT NULL,
|
||||
eur_dkk NUMERIC(12,6) NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
@@ -50,3 +50,14 @@ INSERT INTO strike_price (rates, quote_sats) VALUES (:rates, :quote-sats)
|
||||
-- :name get-latest-strike-price :? :1
|
||||
-- :doc Get the most recent Strike ticker snapshot
|
||||
SELECT rates, recorded_at FROM strike_price ORDER BY id DESC LIMIT 1
|
||||
|
||||
-- :name upsert-currency-rates! :! :n
|
||||
-- :doc Upsert daily currency rates from Frankfurter
|
||||
INSERT INTO currencies (rate_date, eur, dkk, eur_dkk, updated_at)
|
||||
VALUES (:rate-date, :eur, :dkk, :eur-dkk, NOW())
|
||||
ON CONFLICT (rate_date) DO UPDATE
|
||||
SET eur = EXCLUDED.eur, dkk = EXCLUDED.dkk, eur_dkk = EXCLUDED.eur_dkk, updated_at = NOW()
|
||||
|
||||
-- :name get-latest-currency-rates :? :1
|
||||
-- :doc Get the most recent currency rates
|
||||
SELECT eur, dkk, eur_dkk, updated_at FROM currencies ORDER BY rate_date DESC LIMIT 1
|
||||
|
||||
@@ -61,7 +61,8 @@
|
||||
{:query-fn #ig/ref :db.sql/query-fn}
|
||||
|
||||
:frankfurter/rates
|
||||
{:url #or [#env FRANKFURTER_URL "http://localhost:8080"]}
|
||||
{:url #or [#env FRANKFURTER_URL "http://localhost:8080"]
|
||||
:query-fn #ig/ref :db.sql/query-fn}
|
||||
|
||||
:strike/ticker
|
||||
{:query-fn #ig/ref :db.sql/query-fn
|
||||
|
||||
Reference in New Issue
Block a user