Skip to content

Instantly share code, notes, and snippets.

@sjl
Last active October 27, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjl/4078ac46b050c32311c7cb816f830195 to your computer and use it in GitHub Desktop.
Save sjl/4078ac46b050c32311c7cb816f830195 to your computer and use it in GitHub Desktop.
(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