A client for Bitstamp API based on core.async.
[clj-bitstamp "0.4.0"]
This library is a thin wrapper around com.pusher/pusher-java-client
within a simple usage. A function new-pusher
opens a new connection with the Pusher server, subscribes a requested channel and returns a following tuple
[pusher pusher-channel status-ch data-ch]
where
pusher
a Pusher instancepusher
a subscribed Channel instancestatus-ch
an async channel containing a pusher and channel messages as a tuple [action data]
data-ch
an async channel containing data for the subscribed channel as a tuple [channel-name event-name data]
The function takes an option object:
channel-name
a channel name to subscribe, requiredpusher-key
a Pusher key, default de504dc5763aeef9ff52, optionalevent-name
an event name to bind on the subscribed channel, optionalstatus-buffer-or-n
a buffer-or-n for the status channel, optionaldata-buffer-or-n
a buffer-or-n for the data channel, optionalstr-big-decimals?
when true
coerce a volume and price (in strings) as BigDecimal
, default true
Data channel returns a tuple of channel-name, event-name (as keyword
), and data.
Status channel returns a tuple of event-name (as keyword
), and data. Expected events:
:change
:connecting
:connected
:disconnecting
:disconnected
Example:
(require '[clojure.core.async :as async])
(require '[clj-bitstamp.async :as bitstamp])
(let [[pusher pusher-channel status-ch data-ch]
(bitstamp/new-pusher {:channel-name "order_book_btceur" ;; required
:event-name "data" ;; required
:data-buffer-or-n (async/sliding-buffer 16) ;; optinal
:status-buffer-or-n 16})] ;; optional
(async/go-loop []
(let [[channel-name event-name data] (async/<! data-ch)]
(println channel-name event-name data)) ;; <-- put you logic here
(recur))
(async/go-loop []
(let [[event-name data] (async/<! status-ch)]
(println event-name data)) ;; <-- put status handler here
(recur)))
An established connection can be disconnected by
(clj-bitstamp/disconnect pusher)
and again connected withoin same pusher
instance
(clj-bitstamp/connect pusher)
BigDecimal
sCan you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close