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:
@@ -155,10 +155,15 @@ SELECT id, event_id, occurred_at, exchange, fiat_amount, fiat_currency,
|
|||||||
FROM deposits
|
FROM deposits
|
||||||
ORDER BY occurred_at DESC, id DESC
|
ORDER BY occurred_at DESC, id DESC
|
||||||
|
|
||||||
-- :name get-kraken-hour-latest-60 :? :*
|
-- :name get-kraken-hour-latest-24 :? :*
|
||||||
-- :doc Get the 60 most recent Kraken hourly candles
|
-- :doc Get the 24 most recent Kraken hourly candles
|
||||||
SELECT ts, open, high, low, close, vwap, volume, trade_count, created_at
|
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
|
-- :name upsert-kraken-minute! :! :n
|
||||||
-- :doc Upsert a Kraken minute OHLC candle
|
-- :doc Upsert a Kraken minute OHLC candle
|
||||||
|
|||||||
@@ -144,21 +144,25 @@
|
|||||||
:headers {"Content-Type" "application/json"}
|
:headers {"Content-Type" "application/json"}
|
||||||
:body (json/write-str {:error "Invalid date format, use YYYY-MM-DD"})}))))
|
: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]
|
(defn- kraken-hour-handler [{:keys [query-fn]} _req]
|
||||||
(let [rows (query-fn :get-kraken-hour-latest-60 {})]
|
{:status 200
|
||||||
{:status 200
|
:headers {"Content-Type" "application/json"}
|
||||||
:headers {"Content-Type" "application/json"}
|
:body (json/write-str (mapv ohlc-row->map (query-fn :get-kraken-hour-latest-24 {})))})
|
||||||
:body (json/write-str
|
|
||||||
(mapv (fn [r]
|
(defn- kraken-minute-handler [{:keys [query-fn]} _req]
|
||||||
{:ts (:ts r)
|
{:status 200
|
||||||
:open (str (:open r))
|
:headers {"Content-Type" "application/json"}
|
||||||
:high (str (:high r))
|
:body (json/write-str (mapv ohlc-row->map (query-fn :get-kraken-minute-latest-60 {})))})
|
||||||
:low (str (:low r))
|
|
||||||
:close (str (:close r))
|
|
||||||
:vwap (str (:vwap r))
|
|
||||||
:volume (str (:volume r))
|
|
||||||
:trade_count (:trade_count r)})
|
|
||||||
rows))}))
|
|
||||||
|
|
||||||
(defn- api-routes [opts]
|
(defn- api-routes [opts]
|
||||||
[["/swagger.json"
|
[["/swagger.json"
|
||||||
@@ -194,7 +198,9 @@
|
|||||||
["/deposits/rebuild"
|
["/deposits/rebuild"
|
||||||
{:post (fn [req] (tx/rebuild-deposits! opts req))}]
|
{:post (fn [req] (tx/rebuild-deposits! opts req))}]
|
||||||
["/kraken-hour"
|
["/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]
|
(defn route-data [opts]
|
||||||
(merge
|
(merge
|
||||||
|
|||||||
Reference in New Issue
Block a user