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.
- Security
- Installation
- Usage
- Donations
- Credits
- Contributing
- License
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
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
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
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.
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.
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"
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
pairs = client.public.asset_pairs
ticker_data = client.public.ticker('ETHXBT, LTCXBT')
ohlc_data = client.public.ohlc(pair: 'XXBTZEUR', last: '1499436000', interval: '60')
Get market depth information for given asset pairs
depth_data = client.public.order_book('ETHXBT')
Get recent trades
trades = client.public.trades('ETHXBT')
Get spread data for a given asset pair
spread = client.public.spread('ETHXBT')
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
Get account trade balance
trade_balance = client.private.trade_balance
open_orders = client.private.open_orders
closed_orders = client.private.closed_orders
Input: Comma delimited list of transaction ids (txid)
See all orders
orders = client.private.query_orders(txid: ids)
Get array of all trades
trades = client.private.trades_history
Input: Comma delimited list of transaction ids (txid)
See all orders
orders = client.private.query_orders(txid: ids)
Input: Comma delimited list of transaction (txid) ids
positions = client.private.open_positions(txid)
ledgers = client.private.ledgers
Input: Comma delimited list of ledger ids
ledgers = client.private.query_ledgers(id: ledger_ids)
ledgers = client.private.trade_volume
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)
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")
If you like the work that has been done, do not hesitate in paying me a Coffee, I'd gladly accept it :)
Bitcoin Adress: 1LxffuH2C44mFNTYe1NtDz7FeWScCFZqM8 Donate here: https://www.coinbase.com/shideneyu
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 ;) !
KrakenClient follows Semantic Versioning 2.0.
- Fork it ( https://github.com/[my-github-username]/swiffer/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
See LICENSE.md
file.