Liking cljdoc? Tell your friends :D

Build Status Clojars Project


A Clojure wrapper for the Coinbase Pro API (formerly GDAX). The point of this library is to make it convenient to harness the power of Clojure for creating cryptocurrency trading bots and similar applications that utilize the Coinbase Pro exchange. Results are given in edn, and authentication is handled by the library.


Add the dependency to your project or build file.

[coinbase-pro-clj "1.0.0"]

Quick Start

Read on for a quick start or jump to the documentation 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:

(require '[coinbase-pro-clj.core :as cp])

Or in your application:

(ns my-app.core
  (:require [coinbase-pro-clj.core :as cp]))

Each function takes in a client, which requires a :url and optional authentication values. The authentication values are only required for authenticated endpoints. These can be obtained by logging into Coinbase Pro and creating them in the API settings section. URL vars are provided by the library for convenience.

(def client {:url cp/rest-url ; Other values include websocket-url, sandbox-rest-url, and sanbox-websocket-url.
             :key "Coinbase Pro key"
             :secret "Coinbase Pro secret"
             :passphrase "Coinbase Pro passphrase"})

From here you can call any of the functions (provided your client has a valid key, secret, and passphrase for authenticated endpoints). Here are a few examples:

;; Public endpoints
(cp/get-products client)

(cp/get-ticker client "BTC-USD")

;; Private endpoints (require authentication values in client)
(cp/get-orders client)

(cp/place-order client {:side "buy"
                        :product_id "BTC-USD"
                        :price 5000
                        :size 1})

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.

;; 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)


If you notice anything that is unclear or incorrect in this readme or the docs, feel free to create a pull request, or you can open an issue for me to correct it. If you would like a feature added or notice a bug, please open an issue. Thanks for contributing. =)


If you have any questions or want to discuss the library, you can chat me up (@bringe) in the #crypto-currencies channel of the Clojurians Slack.


Copyright © 2018 Brandon Ringe

Distributed under the MIT License

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close