Add /api/kraken-minute endpoint and limit kraken-hour to 24 rows

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 13:37:00 +01:00
co-authored by Claude Opus 4.6
parent 42454646bb
commit b6c8745a86
2 changed files with 29 additions and 18 deletions
+8 -3
View File
@@ -155,10 +155,15 @@ SELECT id, event_id, occurred_at, exchange, fiat_amount, fiat_currency,
FROM deposits
ORDER BY occurred_at DESC, id DESC
-- :name get-kraken-hour-latest-60 :? :*
-- :doc Get the 60 most recent Kraken hourly candles
-- :name get-kraken-hour-latest-24 :? :*
-- :doc Get the 24 most recent Kraken hourly candles
SELECT ts, open, high, low, close, vwap, volume, trade_count, created_at
FROM kraken_hour ORDER BY ts DESC LIMIT 60
FROM kraken_hour ORDER BY ts DESC LIMIT 24
-- :name get-kraken-minute-latest-60 :? :*
-- :doc Get the 60 most recent Kraken minute candles
SELECT ts, open, high, low, close, vwap, volume, trade_count, created_at
FROM kraken_minute ORDER BY ts DESC LIMIT 60
-- :name upsert-kraken-minute! :! :n
-- :doc Upsert a Kraken minute OHLC candle
+21 -15
View File
@@ -144,21 +144,25 @@
:headers {"Content-Type" "application/json"}
:body (json/write-str {:error "Invalid date format, use YYYY-MM-DD"})}))))
(defn- ohlc-row->map [r]
{:ts (:ts r)
:open (str (:open r))
:high (str (:high r))
:low (str (:low r))
:close (str (:close r))
:vwap (str (:vwap r))
:volume (str (:volume r))
:trade_count (:trade_count r)})
(defn- kraken-hour-handler [{:keys [query-fn]} _req]
(let [rows (query-fn :get-kraken-hour-latest-60 {})]
{:status 200
:headers {"Content-Type" "application/json"}
:body (json/write-str
(mapv (fn [r]
{:ts (:ts r)
:open (str (:open r))
:high (str (:high r))
:low (str (:low r))
:close (str (:close r))
:vwap (str (:vwap r))
:volume (str (:volume r))
:trade_count (:trade_count r)})
rows))}))
{:status 200
:headers {"Content-Type" "application/json"}
:body (json/write-str (mapv ohlc-row->map (query-fn :get-kraken-hour-latest-24 {})))})
(defn- kraken-minute-handler [{:keys [query-fn]} _req]
{:status 200
:headers {"Content-Type" "application/json"}
:body (json/write-str (mapv ohlc-row->map (query-fn :get-kraken-minute-latest-60 {})))})
(defn- api-routes [opts]
[["/swagger.json"
@@ -194,7 +198,9 @@
["/deposits/rebuild"
{:post (fn [req] (tx/rebuild-deposits! opts req))}]
["/kraken-hour"
{:get (fn [req] (kraken-hour-handler opts req))}]])
{:get (fn [req] (kraken-hour-handler opts req))}]
["/kraken-minute"
{:get (fn [req] (kraken-minute-handler opts req))}]])
(defn route-data [opts]
(merge