I wanted to create this wrapper because I enjoy programming in Clojure. You can freely use this wrapper, but bare in mind that it is not bullet-proof. I thought that I would use this wrapper to scrape some data for machine learning projects.
Besides, I wanted to:
Add this to your project.clj:
[clojure-poloniex "0.1.0-SNAPSHOT"]
Simply require an API (public, trading, push) For methods with parameters use :params {:currency-pair "BTC_LTC"}
For trading methods, it is necessary to add :creds {:key "Your API key" :secret "Your secret key"}
For push methods, it is important to run them as scheduled job for a certain amount of time. Supply your own callbacks for the push methods using WampCallback.
;the first argument is for the on-next event
;the second is for the on-error
(WampCallback. #(println %) #(println %))
To get order book and trade updates for desired currency pair, define an API method, as follows:
(define-push-api-method "btc-xmr"
:scheduler (Schedulers/computation)
:wsurl *wsurl*
:realm *realm*)
Default callbacks only print the received responses. Just override the callbacks at runtime as needed. See Examples below.
(return-ticker)
(return-chart-data :params {:currency-pair "BTC_LTC" :period 300})
(return-balances :creds {:key "Your API key" :secret "Your API secret"})
(return-open-orders :creds {:key "Your API key" :secret "Your API secret"}
:params {:currencyPair "BTC_LTC"})
; Using Push API is a bit more complicated.
(ns poloniex-api.examples.wamp
(:use
[poloniex-api.callbacks]
[poloniex-api.ws-client])
(:import (java.util.concurrent Executors TimeUnit)))
(defn run [& {:keys [push-method timeout-in-secs]}]
(let [executor (Executors/newSingleThreadExecutor)]
(try
(open push-method)
(.awaitTermination executor timeout-in-secs (TimeUnit/SECONDS))
(close push-method)
(catch Exception e
(println "Caught exception: " e))
(finally (close push-method)))))
; Schedule a push method for a given amount of time to collect data.
(run :push-method (btc-ltc) :callbacks (WampCallback. #(prn %) #(prn %))
:timeout-in-secs 7)
$ lein test
Can you improve this documentation? These fine people already did:
Adam Bober, 7696122 & adamboberEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close