Permalink
Browse files

Added get-quote and export it from package

  • Loading branch information...
1 parent 2ad1ba1 commit 90cd0e87cdb7211dc81b9517ed667ae6df7e07e7 @a0-prw committed Nov 5, 2013
Showing with 29 additions and 1 deletion.
  1. +1 −1 package.lisp
  2. +28 −0 simple-currency.lisp
View
@@ -30,7 +30,7 @@
(:nicknames :cies)
(:export :update-currency-hash
:available-currencies
- :convert :2dd-round :currency-data
+ :get-quote :convert :2dd-round :currency-data
:lookup-currency :ccy-name :ccy-ddigits
:ccy-ncode :ccy-acode :ccy-country
:display-currency :with-currency
View
@@ -130,6 +130,34 @@ codes call (AVAILABLE-CURRENCIES)."))
(values (* amount (/ 1 (getbase nfrom)))
(interval-since-update date))))
+(defgeneric get-quote (amount from to)
+ (:documentation "Return 3 values: 1) The conversion as a rational,
+ 2) the rate for converting from FROM to TO as a rational, and 3) The
+ date for this quote. NB This is a different last value than CONVERT
+ returns."))
+
+(defmethod get-quote ((amount number) (from t) (to t))
+ (declare (inline normalize-currency-designator getbase))
+ (let* ((nfrom (normalize-currency-designator from))
+ (nto (normalize-currency-designator to))
+ (rate (/ (getbase nto) (getbase nfrom)))
+ (date (gethash "date" *currencies*)))
+ (values (* amount rate) rate date)))
+
+(defmethod get-quote ((amount number) (from (eql :eur)) (to t))
+ (declare (inline normalize-currency-designator getbase))
+ (let* ((nto (normalize-currency-designator to))
+ (date (gethash "date" *currencies*))
+ (rate (getbase nto)))
+ (values (* amount rate) rate date)))
+
+(defmethod get-quote ((amount number) (from t) (to (eql :eur)))
+ (declare (inline normalize-currency-designator getbase))
+ (let* ((nfrom (normalize-currency-designator from))
+ (date (gethash "date" *currencies*))
+ (rate (/ 1 (getbase nfrom))))
+ (values (* amount rate) rate date)))
+
;; These assume that 2 digits after the decimal are correct for the
;; currency and we don't give a damn about type of rounding
;; used. Yeeha!

0 comments on commit 90cd0e8

Please sign in to comment.