Liking cljdoc? Tell your friends :D

Deribit clients

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

HTTP client

Check the map bitmex/routes for complete correspondence between keywords and endpoints.

(def client (deribit/rest-client {:key api-key :secret api-secret}))

@(client ::deribit/index {:currency "BTC"})
@(client ::deribit/positions {:currency "BTC"})

Websocket client

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 :instrument {: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