Created
October 3, 2022 20:18
-
-
Save lithiumfrost/1002e5466af49d61633784ddcdad43a5 to your computer and use it in GitHub Desktop.
Get Exchange Rates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import 'java.time.format.DateTimeFormatter | |
'java.time.LocalDateTime) | |
(require '[org.httpkit.client :as hk]) | |
(def previous-year | |
(let [date (LocalDateTime/now) | |
formatter (DateTimeFormatter/ofPattern "yyyy")] | |
(-> (.format date formatter) | |
(Integer/parseInt) | |
(- 1)))) | |
(let [x (hk/request {:url (str "https://api.fiscaldata.treasury.gov/services/api/" | |
"fiscal_service/v1/accounting/od/rates_of_exchange") | |
:method :get | |
:query-params {"fields" "country_currency_desc,exchange_rate" | |
"filter" (str "country_currency_desc:in:(Canada-Dollar,Euro Zone-Euro)," | |
"record_date:eq:" previous-year "-12-31")}})] | |
(let [{data "data"} (json/parse-string (:body @x))] | |
(doseq [currency data] | |
(let [{name "country_currency_desc" rate "exchange_rate"} currency] | |
(println (str name " : " rate)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment