Fall back to DB for price when Binance websocket not connected

The /api/price/latest endpoint now reads the latest row from
binance_price table when the in-memory atom is empty on startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 13:11:33 +01:00
co-authored by Claude Opus 4.6
parent 0caa8db0b3
commit 94c56b7cc3
+6 -2
View File
@@ -87,10 +87,14 @@
{:on-open (fn [{:keys [^WebSocketChannel channel]}] {:on-open (fn [{:keys [^WebSocketChannel channel]}]
(start-strike-ws-loop! channel strike-atom))}})) (start-strike-ws-loop! channel strike-atom))}}))
(defn- latest-price-handler [{:keys [binance frankfurter]} _req] (defn- latest-price-handler [{:keys [binance frankfurter query-fn]} _req]
(let [price-atom (:latest-price binance) (let [price-atom (:latest-price binance)
rates-atom (:rates frankfurter) rates-atom (:rates frankfurter)
v @price-atom] v (or @price-atom
(when-let [row (query-fn :get-latest-binance-price {})]
{:price (:price row)
:prev-price (:price row)
:recorded-at (:recorded_at row)}))]
(if v (if v
{:status 200 {:status 200
:headers {"Content-Type" "application/json"} :headers {"Content-Type" "application/json"}