Kraken Ruby Client is a Ruby API wrapper for the Kraken cryptocurrency exchange. Emphasis on speed, simplicity & minimal dependencies. Ruby 2.4, 2.5, and 2.6.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Kraken Ruby Client

A Ruby API wrapper for the Kraken cryptocurrency exchange.

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

Kraken Ruby Client:

Currently developed with Ruby 2.6. 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 from the terminal with

$ irb -I lib

or with the rake task

$ rake console

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.

Public API examples

require 'kraken_ruby_client'
client =


Private API examples

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

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


Public API

Get OHLC (Open, High, Low, Close) data

# Get OHLC (Open, High, Low, Close) data
# URL:
# Input:
#   +pair+     = required asset pair for which to query OHLC data
#   +interval+ = optional time frame interval in minutes. Defaults to 1.
#                Permitted values: 1, 5, 15, 30, 60, 240, 1440, 10080, 21600
#                Returns an Invalid Arguments error for other values.
#   +since+    = optional Unix Time from when to return committed OHLC data
# Returns a hash with keys `error' and `result'.
#   +result+ is an array containing pair name, OHLC data, and last Unixtime.
#   The OHLC data array contains:
#     time, open, high, low, close, VWAP, price, volume, count.
#   The last entry in the OHLC data array is for the current, not-yet-
#   committed frame and is always present, regardless of the value of since.
#   +last+ is to be used as `since' when getting new committed OHLC data.

client.ohlc('xbtjpy', interval: 5)
client.ohlc('ETHGBP', since: 1548525720)
client.ohlc('xmrusd', interval: 15, since: 1548525720)

Private API

Fetch account balances


Fetch closed orders

# 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')}" }

# More elaborate version with order date and improved readibility for the last 10 closed orders
closed_orders.first(10).each do |order|
  action, price, *rest = order[1].dig('descr', 'order').split
  puts "#{order[0]}   #{[1]['opentm'])}   #{action}#{' ' if action.size == 3}  #{price[0..4]} #{rest.join(' ')}"

Fetch open orders

# 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 an asset pair and the most recent order for the pair:
pair = 'ETCUSD' { |_, v| v.dig('descr', 'pair') == pair } # All open orders
orders.detect { |_, v| v.dig('descr', 'pair') == pair } # Most recent open 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 or just rake

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

To run an individual test in a test file: rake 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

Copyright © 2016-2019 Jon Atack (@jonatack)