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:
@@ -87,10 +87,14 @@
|
||||
{:on-open (fn [{:keys [^WebSocketChannel channel]}]
|
||||
(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)
|
||||
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
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/json"}
|
||||
|
||||
Reference in New Issue
Block a user