diff --git a/resources/queries.sql b/resources/queries.sql index 57d5f30..af2111c 100644 --- a/resources/queries.sql +++ b/resources/queries.sql @@ -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 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 :? :* -- :doc Compute sats balance per wallet from events SELECT w.id, w.name, diff --git a/src/clj/pmagnus/btcdata/web/controllers/transactions.clj b/src/clj/pmagnus/btcdata/web/controllers/transactions.clj index e903ab6..014e8a5 100644 --- a/src/clj/pmagnus/btcdata/web/controllers/transactions.clj +++ b/src/clj/pmagnus/btcdata/web/controllers/transactions.clj @@ -39,6 +39,9 @@ (query-fn :insert-event! row) (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] (let [event-type (get-in req [:query-params "type"])] (if event-type diff --git a/src/clj/pmagnus/btcdata/web/routes/api.clj b/src/clj/pmagnus/btcdata/web/routes/api.clj index 1da7611..ee53c53 100644 --- a/src/clj/pmagnus/btcdata/web/routes/api.clj +++ b/src/clj/pmagnus/btcdata/web/routes/api.clj @@ -172,7 +172,9 @@ {:get (fn [req] (tx/get-wallet-events opts req))}] ["/events" {: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] (merge