Skip to content

Instantly share code, notes, and snippets.

@lispyclouds
Last active September 5, 2016 16:27
Show Gist options
  • Save lispyclouds/9c56c2e00150cc4d17f5f66990061aa2 to your computer and use it in GitHub Desktop.
Save lispyclouds/9c56c2e00150cc4d17f5f66990061aa2 to your computer and use it in GitHub Desktop.
Code to fetch the highest stock
(ns stocks.core
(:gen-class)
(:require [clj-http.client :as client])
(:require [cheshire.core :refer :all]))
(def url "http://dev.markitondemand.com/MODApis/Api/v2/Quote/json?symbol=%s")
(defn get-stock-value-of
[symbol]
(let [response (-> ((client/get (format url symbol)) :body)
(parse-string true))]
{:name (response :Name) :price (response :LastPrice)}))
(defn find-higest-stock
[stocks]
(first (sort-by :price #(> %1 %2) (pmap get-stock-value-of stocks))))
(defn -main
[& args]
(println (find-higest-stock ["AMZN" "YHOO" "FB" "GOOGL" "MSFT"]))
(shutdown-agents))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment