Kraken Ruby Client

A work-in-progress Ruby API wrapper for the Kraken Bitcoin Exchange.

Emphasis on speed, simplicity, no meta-programming, and few dependencies.

Kraken Ruby Client:

Currently developed with Ruby 2.5. Written for Ruby 2.4 and up.

Getting started

Clone the repository, and in the local directory, run gem install curb ; bundle install.

Launch the interactive Ruby shell:

$ irb -I lib

Inside the interactive Ruby console, ensure that require 'curb' does not raise any errors. If it does, Curb may not be properly installed or your system may be missing necessary dependencies. See the Curb documentation for more info.

Examples of using the public API:

require 'kraken_ruby_client'; client =



Enter the interactive Ruby shell:

$ irb -I lib

To use the private API to access your account:

require 'kraken_ruby_client'
client = 'YOUR_API_KEY', api_secret: 'YOUR_API_SECRET')

Fetch account balances:


Fetch all closed orders and a display a readable summary:

closed_orders = client.closed_orders.dig('result', 'closed') # All closed orders
closed_orders.first # Show the most recent closed order

# Show a readable list of the last 5 closed orders:
closed_orders.first(5).each { |order| puts "#{order[0]} #{order[1].dig('descr', 'order')}" }

Fetch all open orders, the most recent open order, and total open order count:

open_orders = client.open_orders.dig('result', 'open') # All open orders
open_orders.first # Most recent open order
open_orders.count # Number of open orders

List the open orders for a specific pair and the last order for the pair:

pair = 'ETCUSD' { |_, v| v.dig('descr', 'pair') == pair } # All
orders.detect { |_, v| v.dig('descr', 'pair') == pair } # Most recent order

Place a market buy order:

client.add_order(pair: 'XBTEUR', type: 'buy', ordertype: 'market', volume: 0.5)

Place a margin sell order (short):

client.add_order(pair: 'DASHEUR', type: 'sell', ordertype: 'market', volume: 1, leverage: 2)

Cancel an order:


Running the test suite

To run all tests: rake test

To run one test file: rake test TEST=test/public_api_test.rb

To run an individual test in a test file: rake test TEST=test/public_api_test.rb TESTOPTS=--name=test_get_server_time


To support the project:

  • Use Kraken Ruby Client in your apps, and please file an issue if you encounter anything that's broken or missing. A failing test to demonstrate the issue is awesome. A pull request with passing tests is even better!


This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see

The author may be contacted by email at [email protected].

Copyright © 2018 Jon Atack (@jonatack)