/clojure-poloniex

An unofficial Clojure Poloniex API wrapper

Primary LanguageClojure

Unofficial Clojure Poloniex API wrapper

Build Status

Motivation

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:

  • improve my skills in Clojure
  • have better understading of a WAMP protocol
  • eventually find some time to do something open-source
  • have a good time!

Usage

Add this to your project.clj:

[clojure-poloniex "0.1.0-SNAPSHOT"]

Simply require an API namespace (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 one is for the on-error
(WampCallback. #(println %) #(println %))

To get order book and trade updates for desired currency pair, define an API method. Default callbacks only print the received responses.

(define-push-api-method "btc-xmr")

; The url and realm are predefined but can overriden:
(define-push-api-method "btc-ltc" :wsurl "your url" :realm "your realm")

Examples

Public API

(return-ticker)

(return-chart-data :params {:currency-pair ["BTC" "LTC"] :period 300})

Trading API

(return-balances :creds {:key "Your API key" :secret "Your API secret"})

(return-open-orders :creds {:key "Your API key" :secret "Your API secret"}
                    :params {:currency-pair ["BTC" "LTC"] })

Push API

; Running a push method infinitely with custom callbacks
(btc-ltc :callbacks (WampCallback. #(println %) #(println %)))

; Run a push method for a given amount of time with default callbacks.
(with-open [push-method (trollbox)]
  (Thread/sleep 10000))

Test

$ lein test