Add deposit totals API endpoint
GET /api/deposits/totals returns fiat deposited per exchange per currency from bank_to_exchange events, aggregated via SQL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -125,6 +125,16 @@ LEFT JOIN wallets tw ON tw.id = e.to_wallet_id
|
|||||||
WHERE e.from_wallet_id = :wallet-id OR e.to_wallet_id = :wallet-id
|
WHERE e.from_wallet_id = :wallet-id OR e.to_wallet_id = :wallet-id
|
||||||
ORDER BY e.occurred_at DESC
|
ORDER BY e.occurred_at DESC
|
||||||
|
|
||||||
|
-- :name get-deposit-totals :? :*
|
||||||
|
-- :doc Total fiat deposited per exchange per currency from bank_to_exchange events
|
||||||
|
SELECT tw.name AS exchange, e.fiat_currency AS currency,
|
||||||
|
SUM(e.fiat_amount) AS total
|
||||||
|
FROM events e
|
||||||
|
JOIN wallets tw ON tw.id = e.to_wallet_id
|
||||||
|
WHERE e.event_type = 'bank_to_exchange'
|
||||||
|
GROUP BY tw.name, e.fiat_currency
|
||||||
|
ORDER BY tw.name, e.fiat_currency
|
||||||
|
|
||||||
-- :name get-wallet-balances :? :*
|
-- :name get-wallet-balances :? :*
|
||||||
-- :doc Compute sats balance per wallet from events
|
-- :doc Compute sats balance per wallet from events
|
||||||
SELECT w.id, w.name,
|
SELECT w.id, w.name,
|
||||||
|
|||||||
@@ -39,6 +39,9 @@
|
|||||||
(query-fn :insert-event! row)
|
(query-fn :insert-event! row)
|
||||||
(response/created "/api/events" {:status "ok"})))))
|
(response/created "/api/events" {:status "ok"})))))
|
||||||
|
|
||||||
|
(defn get-deposit-totals [{:keys [query-fn]} _req]
|
||||||
|
(response/ok (query-fn :get-deposit-totals {})))
|
||||||
|
|
||||||
(defn list-events [{:keys [query-fn]} req]
|
(defn list-events [{:keys [query-fn]} req]
|
||||||
(let [event-type (get-in req [:query-params "type"])]
|
(let [event-type (get-in req [:query-params "type"])]
|
||||||
(if event-type
|
(if event-type
|
||||||
|
|||||||
@@ -172,7 +172,9 @@
|
|||||||
{:get (fn [req] (tx/get-wallet-events opts req))}]
|
{:get (fn [req] (tx/get-wallet-events opts req))}]
|
||||||
["/events"
|
["/events"
|
||||||
{:get (fn [req] (tx/list-events opts req))
|
{:get (fn [req] (tx/list-events opts req))
|
||||||
:post (fn [req] (tx/create-event! opts req))}]])
|
:post (fn [req] (tx/create-event! opts req))}]
|
||||||
|
["/deposits/totals"
|
||||||
|
{:get (fn [req] (tx/get-deposit-totals opts req))}]])
|
||||||
|
|
||||||
(defn route-data [opts]
|
(defn route-data [opts]
|
||||||
(merge
|
(merge
|
||||||
|
|||||||
Reference in New Issue
Block a user