Skip to content

Instantly share code, notes, and snippets.

@sjl sjl/test.lisp
Last active Oct 27, 2017

Embed
What would you like to do?
(defun instrument-candles (&key
((:instrument instrument))
((:price price) "M")
((:granularity granularity) "S5")
((:count count) 500)
((:from from)
(write-to-string
(local-time:timestamp-to-unix
(local-time:timestamp- (local-time::now) 5 :minute))))
((:to to)
(write-to-string
(local-time:timestamp-to-unix (local-time::now))))
((:smooth smooth) nil)
((:include-first include-first) T)
((:daily-alignment daily-alignment) 17)
((:alignment-timezone alignment-timezone) "America/New_York")
((:weekly-alignment weekly-alignment) "Friday"))
(if (null instrument)
(format t "You need to specify an instrument!")
(let* ((endpoint (quri:render-uri
(quri:make-uri :defaults (concatenate 'string
*base-url*
"/v3/instruments/"
instrument
"/candles")
:query `(("price" . ,price)
("granularity" . ,granularity)
,@(if (not (null count))
`(("count" . ,count))
`(("from" . ,from) ("to" . ,to)))
("smooth" . ,smooth)
("includeFirst" . ,(if include-first
"true"
"false"))
("dailyAlignment" . ,daily-alignment)
("alignmentTimezone" . ,alignment-timezone)
("weeklyAlignment" . ,weekly-alignment)))))
(authorization (concatenate 'string "Bearer " key))
(result-json nil)
(result-parsed nil)
(account nil))
(handler-case
(progn
(setf result-json (dex:get endpoint
:headers `(("Content-Type" . "application/json")
("X-Accept-Datetime-Format" . "UNIX")
("Authorization" . ,authorization))
:verbose t))
(setf result-parsed (jonathan:parse result-json :as :hash-table)))
(dexador.error:http-request-forbidden (err)
(format t "error!: ~a~%" err)
nil))
result-json)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.