Limit minute poller to last 5 candles after initial fetch
Reduces unnecessary upserts on each 15-second poll cycle by only processing the 5 most recent candles from Kraken's response. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,13 +55,14 @@
|
||||
|
||||
(defn- poll!
|
||||
"Fetch OHLC data including the last in-progress candle, upsert all.
|
||||
On initial fetch saves everything; subsequent fetches only take last 5.
|
||||
Returns the count of saved candles."
|
||||
[client query-fn since-atom]
|
||||
[client query-fn since-atom initial?]
|
||||
(let [result (fetch-ohlc client @since-atom)
|
||||
last-ts (:last result)
|
||||
pair-key (first (remove #{:last} (keys result)))
|
||||
raw (get result pair-key)
|
||||
candles (map parse-candle raw)]
|
||||
candles (map parse-candle (if initial? raw (take-last 5 raw)))]
|
||||
(when (seq candles)
|
||||
(save-candles! query-fn candles)
|
||||
(when last-ts
|
||||
@@ -74,14 +75,14 @@
|
||||
[client query-fn since-atom running?]
|
||||
(future
|
||||
(try
|
||||
(poll! client query-fn since-atom)
|
||||
(poll! client query-fn since-atom true)
|
||||
(catch Exception e
|
||||
(log/error e "Kraken minute initial poll failed")))
|
||||
(while @running?
|
||||
(Thread/sleep 15000)
|
||||
(when @running?
|
||||
(try
|
||||
(poll! client query-fn since-atom)
|
||||
(poll! client query-fn since-atom false)
|
||||
(catch Exception e
|
||||
(log/error e "Kraken minute poll failed")))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user