|
@@ -3,6 +3,8 @@
|
|
|
(defparameter +yahoo-url+ "https://query.yahooapis.com/v1/public/yql" "Yahoo Finance API endpoint")
|
|
(defparameter +yahoo-url+ "https://query.yahooapis.com/v1/public/yql" "Yahoo Finance API endpoint")
|
|
|
(defparameter +yahoo-query+ "select Name,Rate from yahoo.finance.xchange where pair in (~{\"~A\"~^,~})")
|
|
(defparameter +yahoo-query+ "select Name,Rate from yahoo.finance.xchange where pair in (~{\"~A\"~^,~})")
|
|
|
|
|
|
|
|
|
|
+(defparameter +brent-url+ "http://www.cmegroup.com/CmeWS/mvc/Quotes/Future/424/G")
|
|
|
|
|
+
|
|
|
(defvar *rate-pairs* '("USDRUB" "EURRUB" "GBPRUB"))
|
|
(defvar *rate-pairs* '("USDRUB" "EURRUB" "GBPRUB"))
|
|
|
|
|
|
|
|
(defun get-rates (&optional (pairs *rate-pairs*))
|
|
(defun get-rates (&optional (pairs *rate-pairs*))
|
|
@@ -20,12 +22,25 @@
|
|
|
collect (cons (aget "Name" rate)
|
|
collect (cons (aget "Name" rate)
|
|
|
(read-from-string (aget "Rate" rate))))))
|
|
(read-from-string (aget "Rate" rate))))))
|
|
|
|
|
|
|
|
|
|
+(defun get-brent ()
|
|
|
|
|
+ (handler-case
|
|
|
|
|
+ (read-from-string
|
|
|
|
|
+ (aget "last" (first (aget "quotes"
|
|
|
|
|
+ (yason:parse
|
|
|
|
|
+ (flexi-streams:octets-to-string
|
|
|
|
|
+ (drakma:http-request +brent-url+
|
|
|
|
|
+ :force-binary t
|
|
|
|
|
+ :decode-content t)
|
|
|
|
|
+ :external-format :utf-8)
|
|
|
|
|
+ :object-as :alist)))))
|
|
|
|
|
+ (error (e) (log:error e))))
|
|
|
|
|
+
|
|
|
(defun get-serie (series name)
|
|
(defun get-serie (series name)
|
|
|
(loop for (time . rates) in series
|
|
(loop for (time . rates) in series
|
|
|
when (aget name rates)
|
|
when (aget name rates)
|
|
|
collect (list time (aget name rates))))
|
|
collect (list time (aget name rates))))
|
|
|
|
|
|
|
|
-(defun make-chart (series &key (usd t) (eur t) (gbp t))
|
|
|
|
|
|
|
+(defun make-chart (series &key (usd t) (eur t) (gbp t) (brent t))
|
|
|
(let ((flat (remove-if #'null (if (alexandria:circular-list-p series)
|
|
(let ((flat (remove-if #'null (if (alexandria:circular-list-p series)
|
|
|
(flat-circular series)
|
|
(flat-circular series)
|
|
|
series))))
|
|
series))))
|
|
@@ -33,6 +48,8 @@
|
|
|
(when usd (adw-charting:add-series "USD/RUB" (get-serie flat "USD/RUB")))
|
|
(when usd (adw-charting:add-series "USD/RUB" (get-serie flat "USD/RUB")))
|
|
|
(when eur (adw-charting:add-series "EUR/RUB" (get-serie flat "EUR/RUB")))
|
|
(when eur (adw-charting:add-series "EUR/RUB" (get-serie flat "EUR/RUB")))
|
|
|
(when gbp (adw-charting:add-series "GBP/RUB" (get-serie flat "GBP/RUB")))
|
|
(when gbp (adw-charting:add-series "GBP/RUB" (get-serie flat "GBP/RUB")))
|
|
|
|
|
+ (when brent (adw-charting:add-series "Brent last day futures"
|
|
|
|
|
+ (get-serie flat "Brent")))
|
|
|
(adw-charting:set-axis
|
|
(adw-charting:set-axis
|
|
|
:x "Time" :draw-gridlines-p t
|
|
:x "Time" :draw-gridlines-p t
|
|
|
:label-formatter #'(lambda (v) (local-time:format-timestring nil (local-time:unix-to-timestamp v)
|
|
:label-formatter #'(lambda (v) (local-time:format-timestring nil (local-time:unix-to-timestamp v)
|