Deribit
API Client for v1 Deribit API
Installation
Add this line to your application's Gemfile:
gem 'deribit'
And then execute:
$ bundle
Or install it yourself as:
$ gem install deribit
Usage
Example
require 'deribit'
# main server
api = Deribit::API.new("KEY", "SECRET")
# test server
api = Deribit::API.new("KEY", "SECRET", test_server: true)
api.index
api.account_info
API
Deribit::API.new(key, secret)
Constructor creates new API client.
Parameters
Name | Type | Decription |
---|---|---|
key |
string |
Optional, Access Key needed to access Private functions |
secret |
string |
Optional, Access Secret needed to access Private functions |
Methods
-
instruments(expired: false, only_active: true)
- Doc, publicReturns active instruments Parameters
Name Type Decription expired
boolean
Optional, for returning all expired instruments. only_active
boolean
Optional, returns only isActive true instruments -
orderbook(instrument)
- Doc, publicRetrieve the orderbook for a given instrument.
Parameters
Name Type Decription instrument
string
Required, instrument name -
index
- Doc, publicGet price index, BTC-USD rates.
-
currencies
- Doc, publicGet all supported currencies.
-
last_trades(instrument, count: count, since: since)
- Doc, publicRetrieve the latest trades that have occured for a specific instrument.
Parameters
Name Type Decription instrument
string
Required, instrument name count
integer
Optional, count of trades returned (limitation: max. count is 100) since
integer
Optional, “since” trade id, the server returns trades newer than that “since” -
summary(instrument)
- Doc, publicRetrieve the summary info such as Open Interest, 24H Volume etc for a specific instrument.
Parameters
Name Type Decription instrument
string
Required, instrument name -
account
- Doc, PrivateGet user account summary.
-
buy(instrument, quantity, price, type: "limit", stopPx: stopPx, post_only: post_only, label: label, max_show: max_show, adv: adv)
- Doc, privatePlace a buy order in an instrument.
Parameters
Name Type Decription instrument
string
Required, instrument name quantity
integer
Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) price
float
Required, USD for futures, BTC for options post_only
boolean
Optional, if true then the order will be POST ONLY label
string
Optional, user defined maximum 32-char label for the order type
string
Required, "limit", "market" or for futures only: "stop_limit" stopPx
string
Required, needed for stop_limit order, defines stop price max_show
string
Optional, optional parameter, if "0" then the order will be hidden adv
string
Optional, can be "implv", "usd", or absent (advanced order type) -
sell(instrument, quantity, price, post_only: post_only, label: label, max_show: max_show, adv: adv)
- Doc, privatePlace a sell order in an instrument.
Parameters
Name Type Decription instrument
string
Required, instrument name quantity
integer
Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) price
float
Required, USD for futures, BTC for options post_only
boolean
Optional, if true then the order will be POST ONLY label
string
Optional, user defined maximum 32-char label for the order max_show
string
Optional, optional parameter, if "0" then the order will be hidden adv
string
Optional, can be "implv", "usd", or absent (advanced order type) -
edit(order_id, quantity, price, post_only: post_only, adv: adv)
- DocEdit price and/or quantity of the own order. (Authorization is required).
Parameters
Name Type Decription order_id
integer
Required, ID of the order returned by "sell" or "buy" request quantity
integer
Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) price
float
Required, USD for futures, BTC for options post_only
boolean
Optional, if true then the order will be POST ONLY adv
string
Optional, can be "implv", "usd", or absent (advanced order type)
cancel(order_id)
- Doc, private
Cancell own order by id.
Parameters
Name | Type | Decription |
---|---|---|
order_id |
integer |
Required, ID of the order returned by "sell" or "buy" request |
-
open_orders(instrument)
- Doc, privateRetrieve open orders.
Parameters
Name Type Description instrument
string
Optional, instrument name, use if want orders for specific instrument -
positions
- Doc, privateRetreive positions.
-
trade_history(count: count, instrument: instrument, start_trade_id: start_trade_id)
- Doc, privateGet private trade history of the account. (Authorization is required). The result is ordered by trade identifiers (trade id-s).
Parameters
Name Type Description count
integer
Optional, number of results to fetch. Default: 20 instrument
string
Optional, name of instrument, also aliases “all”, “futures”, “options” are allowed. Default: "all" start_trade_id
integer
Optional, number of requested records
Websocket API
require 'deribit'
ws = Deribit::WS.new("KEY", "SECRET")
ws.account
#subscribe
ws.subscribe(['BTC-30NOV18-6500-P'], events: [:order_book])
Handler
Create inheritance class for handling WS notifications
class MyHandler < Deribit::WS::Handler
# event handler
def order_book_event(json)
# your actions here
# json example for order_book_event
# {"state"=>"open", "settlementPrice"=>0.2105, "instrument"=>"BTC-30NOV18-6500-P", "bids"=>[{"quantity"=>10.0, "amount"=>10.0, "price"=>0.2785, "cm"=>10.0, "cm_amount"=>10.0}, {"quantity"=>1.0, "amount"=>1.0, "price"=>0.05, "cm"=>11.0, "cm_amount"=>11.0}], "asks"=>[{"quantity"=>9.0, "amount"=>9.0, "price"=>0.2935, "cm"=>9.0, "cm_amount"=>9.0}], "tstamp"=>1542650516519, "last"=>0.285, "low"=>0.285, "high"=>0.285, "mark"=>0.286, "uPx"=>5060.54, "uIx"=>"index_price", "iR"=>0, "markIv"=>106.0, "askIv"=>110.45, "bidIv"=>0.0, "delta"=>-0.90264, "gamma"=>0.00019, "vega"=>1.48288, "theta"=>-7.42706}
end
# action handler
def instruments(json)
# your actions here
end
end
Available events you can check in the guide https://deribit.com/main#/pages/docs/api WebSockets API section.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/vizakenjack/deribit. This project is intended to be a safe, welcoming space for collaboration.