Skip to content

Commit

Permalink
Merge pull request #13 from bpringe/fix/unsubscribe
Browse files Browse the repository at this point in the history
Make websocket on-receive receive edn. Fix websocket unsubscribe.
  • Loading branch information
bpringe authored Sep 8, 2018
2 parents e2d2162 + 76771de commit 1138b05
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pom.xml.asc
.hgignore
.hg/
profiles.clj
.gorilla*
.gorilla*
examples.clj
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ for creating cryptocurrency trading bots and similar applications that utilize t
Add the dependency to your project or build file.

```clojure
[coinbase-pro-clj "0.2.0"]
[coinbase-pro-clj "1.0.0"]
```

## Quick Start

Read on for a quick start or jump to the detailed [documentation](https://bpringe.github.io/coinbase-pro-clj/index.html).
Read on for a quick start or jump to the [documentation](https://bpringe.github.io/coinbase-pro-clj/index.html) for a list of all endpoint and websocket functions with links the the Coinbase Pro API docs and code examples for each.

First, require it in the REPL:

Expand Down Expand Up @@ -57,7 +57,27 @@ From here you can call any of the functions (provided your client has a valid ke
:size 1})
```

See the [documentation](https://bpringe.github.io/coinbase-pro-clj/index.html) for a list of all endpoint functions with links the the Coinbase Pro API docs and code examples for each.
### Websocket Feed

Websocket messages are passed as edn to your `on-receive` function. When a new connection is created, the heartbeat channel is subscribed to if no `:channel` is specified.

```clojure
;; Create a new connection and subscribe to the ticker channel for BTC-USD
(def conn (cp/create-websocket-connection {:product_ids ["BTC-USD" "ETH-USD"]
:channels [{:name "ticker"}]
:url cp/websocket-url
:on-receive (fn [x] (prn 'received x))}))

;; Unsubscribe from the ticker channel for all products
(cp/unsubscribe conn {:channels [{:name "ticker"}]})

;; Subscribe to the heartbeat channel of BTC-USD
(cp/subscribe conn {:channels [{:name "heartbeat"
:product_ids ["BTC-USD"]}]})

;; Close the connection
(cp/close conn)
```

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion docs/coinbase-pro-clj.core.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>coinbase-pro-clj.core documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Coinbase-pro-clj</span> <span class="project-version">0.2.0</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1 current"><a href="coinbase-pro-clj.core.html"><div class="inner"><span>coinbase-pro-clj.core</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-cancel-all"><div class="inner"><span>cancel-all</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-cancel-order"><div class="inner"><span>cancel-order</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-close"><div class="inner"><span>close</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-create-websocket-connection"><div class="inner"><span>create-websocket-connection</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-deposit-from-coinbase"><div class="inner"><span>deposit-from-coinbase</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-deposit-from-payment-method"><div class="inner"><span>deposit-from-payment-method</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-generate-report"><div class="inner"><span>generate-report</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-24hour-stats"><div class="inner"><span>get-24hour-stats</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-account"><div class="inner"><span>get-account</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-account-history"><div class="inner"><span>get-account-history</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-account-holds"><div class="inner"><span>get-account-holds</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-accounts"><div class="inner"><span>get-accounts</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-coinbase-accounts"><div class="inner"><span>get-coinbase-accounts</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-currencies"><div class="inner"><span>get-currencies</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-fills"><div class="inner"><span>get-fills</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-historic-rates"><div class="inner"><span>get-historic-rates</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-order"><div class="inner"><span>get-order</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-order-book"><div class="inner"><span>get-order-book</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-orders"><div class="inner"><span>get-orders</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-payment-methods"><div class="inner"><span>get-payment-methods</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-products"><div class="inner"><span>get-products</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-report-status"><div class="inner"><span>get-report-status</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-ticker"><div class="inner"><span>get-ticker</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-time"><div class="inner"><span>get-time</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-trades"><div class="inner"><span>get-trades</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-trailing-volume"><div class="inner"><span>get-trailing-volume</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-place-order"><div class="inner"><span>place-order</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-rest-url"><div class="inner"><span>rest-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-sandbox-rest-url"><div class="inner"><span>sandbox-rest-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-sandbox-websocket-url"><div class="inner"><span>sandbox-websocket-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-subscribe"><div class="inner"><span>subscribe</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-unsubscribe"><div class="inner"><span>unsubscribe</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-websocket-url"><div class="inner"><span>websocket-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-withdraw-to-coinbase"><div class="inner"><span>withdraw-to-coinbase</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-withdraw-to-crypto-address"><div class="inner"><span>withdraw-to-crypto-address</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-withdraw-to-payment-method"><div class="inner"><span>withdraw-to-payment-method</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">coinbase-pro-clj.core</h1><div class="doc"><div class="markdown"><p>Public and private endpoint functions and websocket feed functionality. In all function signatures, <code>client</code> takes the following shape:</p>
<html><head><meta charset="UTF-8" /><title>coinbase-pro-clj.core documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Coinbase-pro-clj</span> <span class="project-version">1.0.0</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1 current"><a href="coinbase-pro-clj.core.html"><div class="inner"><span>coinbase-pro-clj.core</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-cancel-all"><div class="inner"><span>cancel-all</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-cancel-order"><div class="inner"><span>cancel-order</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-close"><div class="inner"><span>close</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-create-websocket-connection"><div class="inner"><span>create-websocket-connection</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-deposit-from-coinbase"><div class="inner"><span>deposit-from-coinbase</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-deposit-from-payment-method"><div class="inner"><span>deposit-from-payment-method</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-generate-report"><div class="inner"><span>generate-report</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-24hour-stats"><div class="inner"><span>get-24hour-stats</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-account"><div class="inner"><span>get-account</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-account-history"><div class="inner"><span>get-account-history</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-account-holds"><div class="inner"><span>get-account-holds</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-accounts"><div class="inner"><span>get-accounts</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-coinbase-accounts"><div class="inner"><span>get-coinbase-accounts</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-currencies"><div class="inner"><span>get-currencies</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-fills"><div class="inner"><span>get-fills</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-historic-rates"><div class="inner"><span>get-historic-rates</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-order"><div class="inner"><span>get-order</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-order-book"><div class="inner"><span>get-order-book</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-orders"><div class="inner"><span>get-orders</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-payment-methods"><div class="inner"><span>get-payment-methods</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-products"><div class="inner"><span>get-products</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-report-status"><div class="inner"><span>get-report-status</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-ticker"><div class="inner"><span>get-ticker</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-time"><div class="inner"><span>get-time</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-trades"><div class="inner"><span>get-trades</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-get-trailing-volume"><div class="inner"><span>get-trailing-volume</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-place-order"><div class="inner"><span>place-order</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-rest-url"><div class="inner"><span>rest-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-sandbox-rest-url"><div class="inner"><span>sandbox-rest-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-sandbox-websocket-url"><div class="inner"><span>sandbox-websocket-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-subscribe"><div class="inner"><span>subscribe</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-unsubscribe"><div class="inner"><span>unsubscribe</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-websocket-url"><div class="inner"><span>websocket-url</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-withdraw-to-coinbase"><div class="inner"><span>withdraw-to-coinbase</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-withdraw-to-crypto-address"><div class="inner"><span>withdraw-to-crypto-address</span></div></a></li><li class="depth-1"><a href="coinbase-pro-clj.core.html#var-withdraw-to-payment-method"><div class="inner"><span>withdraw-to-payment-method</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">coinbase-pro-clj.core</h1><div class="doc"><div class="markdown"><p>Public and private endpoint functions and websocket feed functionality. In all function signatures, <code>client</code> takes the following shape:</p>
<pre><code class="clojure">{:url
:key ; optional
:secret ; optional
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>Coinbase-pro-clj 0.2.0</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Coinbase-pro-clj</span> <span class="project-version">0.2.0</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 current"><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1 "><a href="coinbase-pro-clj.core.html"><div class="inner"><span>coinbase-pro-clj.core</span></div></a></li></ul></div><div class="namespace-index" id="content"><h1><span class="project-title"><span class="project-name">Coinbase-pro-clj</span> <span class="project-version">0.2.0</span></span></h1><h5 class="license">Released under the <a href="https://opensource.org/licenses/MIT">MIT</a></h5><div class="doc"><p>A Clojure wrapper for the Coinbase Pro API (formerly GDAX).</p></div><h2>Installation</h2><p>To install, add the following dependency to your project or build file:</p><pre class="deps">[coinbase-pro-clj "0.2.0"]</pre><h2>Namespaces</h2><div class="namespace"><h3><a href="coinbase-pro-clj.core.html">coinbase-pro-clj.core</a></h3><div class="doc"><div class="markdown"><p>Public and private endpoint functions and websocket feed functionality. In all function signatures, <code>client</code> takes the following shape:</p>
<html><head><meta charset="UTF-8" /><title>Coinbase-pro-clj 1.0.0</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Coinbase-pro-clj</span> <span class="project-version">1.0.0</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 current"><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1 "><a href="coinbase-pro-clj.core.html"><div class="inner"><span>coinbase-pro-clj.core</span></div></a></li></ul></div><div class="namespace-index" id="content"><h1><span class="project-title"><span class="project-name">Coinbase-pro-clj</span> <span class="project-version">1.0.0</span></span></h1><h5 class="license">Released under the <a href="https://opensource.org/licenses/MIT">MIT</a></h5><div class="doc"><p>A Clojure wrapper for the Coinbase Pro API (formerly GDAX).</p></div><h2>Installation</h2><p>To install, add the following dependency to your project or build file:</p><pre class="deps">[coinbase-pro-clj "1.0.0"]</pre><h2>Namespaces</h2><div class="namespace"><h3><a href="coinbase-pro-clj.core.html">coinbase-pro-clj.core</a></h3><div class="doc"><div class="markdown"><p>Public and private endpoint functions and websocket feed functionality. In all function signatures, <code>client</code> takes the following shape:</p>
<pre><code class="clojure">{:url
:key ; optional
:secret ; optional
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject coinbase-pro-clj "0.2.0"
(defproject coinbase-pro-clj "1.0.0"
:description "A Clojure wrapper for the Coinbase Pro API (formerly GDAX)."
:url "https://github.com/bpringe/coinbase-pro-clj"
:license {:name "MIT"
Expand Down
Loading

0 comments on commit 1138b05

Please sign in to comment.