Skip to content

Instantly share code, notes, and snippets.

@lithiumfrost
Created October 3, 2022 20:18
Show Gist options
  • Save lithiumfrost/1002e5466af49d61633784ddcdad43a5 to your computer and use it in GitHub Desktop.
Save lithiumfrost/1002e5466af49d61633784ddcdad43a5 to your computer and use it in GitHub Desktop.
Get Exchange Rates
(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