Skip to content

Instantly share code, notes, and snippets.

@jonathak
Last active September 28, 2019 21:10
Show Gist options
  • Save jonathak/a4548233b5a5ca0259e7ab525cc9da11 to your computer and use it in GitHub Desktop.
Save jonathak/a4548233b5a5ca0259e7ab525cc9da11 to your computer and use it in GitHub Desktop.
Extract Financial Data from iexcloud.io
(ns iex.core
(:require [clj-http.client :as client])
(:gen-class))
(defn try-wrap [f]
(fn [x y]
(try (f x y)
(catch Exception e "http-error"))))
(defn iex-stock-api
"returns raw response body for a call to stock APIs"
([ticker path qstr]
(let [cp { :cookie-policy :standard }]
(-> (str "https://cloud.iexapis.com/beta/stock/"
ticker "/" path "?token="
"-YOUR API TOKEN GOES HERE-"
"&" qstr)
((try-wrap client/get) cp)
((try-wrap :body) cp))))
([ticker path]
(iex-stock-api ticker path "")))
(defn cash-flow [ticker]
(iex-stock-api ticker "cash-flow" "last=12"))
(defn -main
[& args]
(println "use lein repl"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment