Deribit

Build Status Maintainability Test Coverage Inline docs Gem Version Yard Docs License: MIT

Ruby library for Deribit API

Installation

Add this line to your application's Gemfile:

gem 'deribit-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install deribit-api

Usage

Overview

require 'deribit-api'

Create a simple client to access public APIs

client = Deribit::Client.new
trades = client.trades 'options', count: 3
trades.first
  => #<Hashie::Mash amount=3.0 direction="buy" indexPrice=3817.31 instrument="BTC-29MAR19-4500-C" iv=60.33 price=0.016 quantity=3.0 tickDirection=0 timeStamp=1551274556589 tradeId=16055937 tradeSeq=712>
trades.first.instrument
  => "BTC-29MAR19-4500-C"

Pass key and secret to access private APIs

client = Deribit::Client.new key: 'KEY', secret: 'SECRET'
account = client.account
 => #<Hashie::Mash PNL=0.0 SRPL=0.0 SUPL=0.0 availableFunds=9.99995789 balance=9.99995789 currency="BTC" deltaTotal=0.0 depositAddress="2N6SU5Yjn7AfYcT89QyeeHvHyZoqTt2GLyi" equity=9.999957896 futuresPNL=0.0 futuresSRPL=0.0 futuresSUPL=0.0 initialMargin=0.0 maintenanceMargin=0.0 marginBalance=9.99995789 optionsD=0.0 optionsG=0.0 optionsPNL=0.0 optionsSRPL=0.0 optionsSUPL=0.0 optionsTh=0.0 optionsV=0.0 sessionFunding=0.0>
account.equity
  => 9.999957896

Examples

Fetch all tradable instruments:

instruments = client.instruments
puts instruments.first

Orderbook for BTCUSD perpetual instrument:

orderbook = client.orderbook 'BTC-PERPETUAL', depth: 3
puts orderbook.asks.first

Orderbook streaming via websocket:

@client.orderbook 'ETH-PERPETUAL' do |orderbook|
  puts orderbook
end

Place a BTCUSD limit buy order 100 contracts @ 2500:

response = client.buy 'BTC-PERPETUAL', 100, price: 2500
puts response.order.state

Get last 10 option trades via HTTP:

trades = client.trades 'options', count: 10
puts trades.first

Stream ongoing trades via websocket:

@client.trades do |trade|
 puts trade
end

Options trading summary:

summaries = client.summary :options
puts summaries.first

API Endpoints

All endpoints marked with [X] are fully implemented and ready to use, see the features table below:

API endpoints Private? HTTP API Websocket API FIX API
Time [X] [X]
Setheartbeat N/A [X]
Cancelheartbeat N/A [X]
Test [X] [X]
Ping [X] [X]
Instruments [X] [X]
Currencies [X] [X]
Index [X] [X]
Orderbook [X] [X]
Trades [X] [X]
Summary [X] [X]
Announcements [X] [X]
Settlements [X] [X]
Account YES [X] [X]
Buy YES [X] [X]
Sell YES [X] [X]
Edit YES [X] [X]
Cancel YES [X] [X]
Cancel all YES [X] [X]
Orders YES [X] [X]
Positions YES [X] [X]
Orders history YES [X] [X]
Order YES [X] [X]
Trades history YES [X] [X]
New announcements YES [X] [X]
Logout YES N/A [X]
Cancel on disconnect YES N/A [X]
Get email lang YES [X] [X]
Set email lang YES [X] [X]
Set announcements read YES [X] [X]
Settlements history YES [X] [X]
Subscribe N/A
Unsubscribe N/A

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/icostan/deribit-api-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the Deribit project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.