Skip to content

shideneyu/kraken_client

Repository files navigation

KrakenClient

Gem Version Code Climate

kraken_client_blob

KrakenClient is a Ruby wrapper of the Kraken API. Kraken is a market exchange site serving those trading with Crypto-Currencies, such as Bitcoin.

It is a robust gem, and tested using the Awesome Spectus gem.

Summary

Security

As a basic form of security KrakenClient provides a set of SHA512 checksums for every Gem release. These checksums can be found in the checksum/ directory. Although these checksums do not prevent malicious users from tampering with a built Gem they can be used for basic integrity verification purposes.

The checksum of a file can be checked using the sha512sum command. For example:

$ sha512sum pkg/kraken_client-1.1.0.gem
d1b055b091443b862d88028cb517410be016264295950de4cf7973686063e031dfc619cfa7970dca8d4081f82bf6856339b9f35fef356ecce7c42f1ebb3f3b7f  pkg/kraken_client-1.1.0.gem

Installation

Add this line to your application's Gemfile:

gem 'kraken_client', '~> 1.3.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kraken_client

And require it in your application:

irb(main):001:0> require 'kraken_client'
=> true

Usage

Configuration

You can pass multiple variables that will be used in the gem.

KrakenClient.configure do |config|
      config.api_key     = ENV['KRAKEN_API_KEY']
      config.api_secret  = ENV['KRAKEN_API_SECRET']
      config.base_uri    = 'https://api.kraken.com'
      config.api_version = 0
      config.limiter     = true
      config.tier        = 2
end

By default, the default values are the ones described in the above example.

You can also pass any of those options inline when loading an instance of KrakenClient.

KrakenClient.load({base_uri: 'https://api.kraken.com', tier: 3}).config.tier

⚠️ Important Note ⚠️: If you wish to use the Private Endpoints, you need to specify an API Key, or an exception will be raised.

Call Rate Limiter

Kraken has implemented a security which limit API users to make too much requests to the server. Each user has a counter (which is bigger depending on your tier). Each call increments your counter, and if your counter reaches its limit, you are blocked for 15 minutes.

To prevent this, KrakenClient has a safeguard, which queue the request which should in theory be blocked and is executed two second later.

If you want to disable this option, pass the limiter variable in the configuration to false.

KrakenClient.load({limiter: false}).config.tier

Also, this limiter is activated by default. You would like to specify your tier, and KrakenClient will automatically make the required adjustments. The default tier is 2.

KrakenClient.load({tier: 3}).config.tier

For more information, please consult the Kraken official documentation.

Requests

In all our examples henceforward, we consider this variable to be a loaded instance of KrakenClient

client = KrakenClient.load

If you ever need to see the full documentation for the possible parameters, please take a look at the official Kraken API docs.

A KrakenClient::MissingParameter exception will be raised along with the missing parameters if a required parameter is not passed.

Public Endpoints

Server Time

This functionality is provided by Kraken to to aid in approximating the skew time between the server and client.

time = client.public.server_time

time.unixtime #=> 1393056191
time.rfc1123 #=> "Sat, 22 Feb 2014 08:28:04 GMT"
Asset Info

Returns the assets that can be traded on the exchange. This method can be passed info, aclass (asset class), and asset options. An example below is given for each:

assets = client.public.assets
Asset Pairs
pairs = client.public.asset_pairs
Ticker Information
ticker_data = client.public.ticker('ETHXBT, LTCXBT')
OHLC Data
ohlc_data = client.public.ohlc(pair: 'XXBTZEUR', last: '1499436000', interval: '60')
Order Book

Get market depth information for given asset pairs

depth_data = client.public.order_book('ETHXBT')
Trades

Get recent trades

trades = client.public.trades('ETHXBT')
Spread

Get spread data for a given asset pair

spread = client.public.spread('ETHXBT')

Private Endpoints

Balance

Get account balance for each asset Note: Rates used for the floating valuation is the midpoint of the best bid and ask prices

balance = client.private.balance
Trade Balance

Get account trade balance

trade_balance = client.private.trade_balance
Open Orders
open_orders = client.private.open_orders
Closed Orders
closed_orders = client.private.closed_orders
Query Orders

Input: Comma delimited list of transaction ids (txid)

See all orders

orders = client.private.query_orders(txid: ids)
Trades History

Get array of all trades

trades = client.private.trades_history
Query Trades

Input: Comma delimited list of transaction ids (txid)

See all orders

orders = client.private.query_orders(txid: ids)
Open Positions

Input: Comma delimited list of transaction (txid) ids

positions = client.private.open_positions(txid)
Ledgers Info
ledgers = client.private.ledgers
Query Ledgers

Input: Comma delimited list of ledger ids

ledgers = client.private.query_ledgers(id: ledger_ids)
Trade Volume
ledgers = client.private.trade_volume
Add Order

There are 4 required parameters for buying an order. The example below illustrates the most basic order. Please see the Kraken documentation for the parameters required for more advanced order types.

# buying 0.01 XBT (bitcoin) for XRP (ripple) at market price
opts = {
  pair: 'ETHXBT',
  type: 'buy',
  ordertype: 'market',
  volume: 0.01
}

client.private.add_order(opts)
Cancel Order
Same as with `add_order`, but the only required parameter is `txid`, refering to the order identifier.
client.private.cancel_order(txid: "UKIYSP-9VN27-AJWWYC")

Donations

If you like the work that has been done, do not hesitate in paying me a Coffee, I'd gladly accept it :)

bitcoinadress

Bitcoin Adress: 1LxffuH2C44mFNTYe1NtDz7FeWScCFZqM8 Donate here: https://www.coinbase.com/shideneyu

Credits

This gem has been made by Sidney SISSAOUI (shideneyu).

Special credits goes to Alexander LEISHMAN and other kraken_ruby contributors for their gem, which helped me to have a nice skeleton to begin KrakenClient. It would have been difficult for me to sign the requests if it wasn't thanks to their work.

If you want to be part of those credits, do not hesitate to contribute by doing some pull requests ;) !

Versioning

KrakenClient follows Semantic Versioning 2.0.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/swiffer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

See LICENSE.md file.

About

kraken_client is a ruby wrapper for the Kraken API.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published