Liking cljdoc? Tell your friends :D

Deribit client

(require '[polvo.utils.deribit :as deribit])

HTTP API

deribit/routes

Correspondence between keywords and endpoints.

deribit/http-request [route & params]

A direct interface allowing access to HTTP API. Kebab-case params on request are automatically converted to camel case params (for instance, :stop-price becomes "stopPrice").

(deribit/http-request :currencies)
(deribit/http-request :currencies :as-is? true)
(deribit/http-request :positions :params {:currency "BTC"} :key "<ACCESS-KEY>" :secret "<ACCESS-SECRET>")

deribit/http-client [param-dict & _ :as params]

A more convenient interface allowing pre-specification of :api-key, :api-secret, :as-is? and :testing? options.

(def cli (deribit/http-client :key "<ACCESS-KEY>" :secret "<ACCESS-SECRET>"))
(cli :currencies)
(cli :positions {:currency "BTC"}) ; passing parameters as a map
(cli :positions :currency "BTC") ; with a client you can also use keyword parameters

Websockets API

deribit/ws-client [& params]

Creates a websocket client. Handlers are passed to gniazdo.core/client (see stalefruits/gniazdo. Returns a map with keys :client (the actual client) and :opts with metadata.

(require '[clojure.data.json :as json])

(defn print-response [msg]
  (-> msg
      (get "result")
      println))

(defn print-stream [msg]
  (do
    (println (str "channel: " (-> msg (get "params") (get "channel"))))
    (println (clojure.pprint/pprint (-> msg (get "params") (get "data"))))
    (println)))

(def cli (deribit/ws-client :key "<ACCESS-KEY>"
                    :secret "<ACCESS-SECRET>"
                    :handlers {:on-receive (fn [response]
                                             (let [msg (json/read-str response)]
                                               (if (contains? msg "result")
                                                 (print-response msg)
                                                 (print-stream msg))))
                               :on-error   #(println (str "error: " %))}))

deribit/send [ws-client route & [params & {:keys [id] :or {id nil}}]

Sends a message asyncronously using a map created with deribit/ws-client. You can optionally identify requests with an integer :id.

(deribit/send cli :time) ; cli as defined above
(deribit/send cli :instruments {:currency "BTC"} :id 2)
(deribit/send cli :public-subscribe {:channels ["book.BTC-PERPETUAL.raw"]})

deribit/expand [x]

Helper for generating combinatorial channel names.

(deribit/expand [:book [:btc-perpetual :eth-perpetual] :raw])
; => ["book.BTC-PERPETUAL.raw" "book.ETH-PERPETUAL.raw"]
(deribit/expand [:book [:btc-perpetual :eth-perpetual] [:raw :100ms]])
; => ["book.BTC-PERPETUAL.raw" "book.BTC-PERPETUAL.100ms" "book.ETH-PERPETUAL.raw" "book.ETH-PERPETUAL.100ms"]
(deribit/expand [:price-index [:btc-usd :eth-usd]])
; => ["deribit_price_index.btc_usd" "deribit_price_index.eth_usd"]

deribit/kw->subscription

Available conversions from keywords to channels.

Helpers

deribit/parse-instrument [instrument]

Parses a instrument name. Returns nil if instrument name is invalid.

(deribit/parse-instrument "BTC-PERPETUAL")
; => {:instrument "BTC-PERPETUAL", :kind "perpetual", :currency "BTC"}
(deribit/parse-instrument "BTC-5AUG16")
; => {:instrument "BTC-5AUG16", :kind "future", :currency "BTC", :expiration-date "2016-08-05"}
(deribit/parse-instrument "BTC-5AUG16-580-P")
; =>
; {:instrument "BTC-5AUG16-580-P",
;  :kind "option",
;  :currency "BTC",
;  :expiration-date "2016-08-05",
;  :strike 580,
;  :option-type "put"}
(deribit/parse-instrument "BTC-25DSSD16")
; => nil
(deribit/parse-instrument "BTC-32DSSD16")
; => nil

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close