deribit-api 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: bd3cbbddf6116cff3d7c90e9fbd29349a6fa0e0fdb4cef927bf347bb1838b710
4
- data.tar.gz: be182b02dc7258aaf6f0ea70a7fa09d3e5f695db1eb311b347a2b9b1dd3a5591
2
+ SHA1:
3
+ metadata.gz: edee765ee69839379018b56f056e9070afe09f03
4
+ data.tar.gz: 7398d5ce16099b24fa6433e3456820bc3d34ad48
5
5
  SHA512:
6
- metadata.gz: 931a7625df5e7837b70f355dc941b24a2596940d37f8ec3fab690d207bb3b25ccf97366428de085e2a726c2f55d94fb0e97a7f4a61005b72effbfaaafd88ae4f
7
- data.tar.gz: ab2e646407b282cbf122c04c56a3cd4d4fad6edd560fad4f4bcc865bd07f1c42afc5fbaa703ddebe876d2da5cb9aca1139f68f1b80acbfd3a85760d3e7b8f91d
6
+ metadata.gz: 59e6f1288d0627595fe134b08d6fb8c30ebfe7d768763115d5bde0b3a2a30937a16c29af94f797d516016603f301d623195721c890fcd51e3c92e044189d2438
7
+ data.tar.gz: a18b33c6b3b17db73fd96c7df5a01b6b74f14c595f4d450d81a3e822cd312742b3c8db8a9863b3a1e8ab9002839fafd414e64cbddf92eebd4073940dffbf7d9c
@@ -5,6 +5,13 @@
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.2] - 2019-02-27
9
+ ### Added
10
+ - HTTP public endpoints
11
+ ### Changed
12
+ - use Minitest instead of RSpec
13
+ - use Faraday instead of HTTParty
14
+
8
15
  ## [0.0.1] - 2019-01-04
9
16
  ### Added
10
17
  - Initial gem release
@@ -1,44 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deribit-api (0.0.1)
4
+ deribit-api (0.0.2)
5
+ faraday
6
+ faraday_middleware
5
7
  hashie
6
- httparty
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
12
  bump (0.7.0)
12
13
  coderay (1.1.2)
13
- diff-lcs (1.3)
14
14
  docile (1.3.1)
15
+ faraday (0.15.4)
16
+ multipart-post (>= 1.2, < 3)
17
+ faraday_middleware (0.13.1)
18
+ faraday (>= 0.7.4, < 1.0)
15
19
  hashie (3.6.0)
16
- httparty (0.16.3)
17
- mime-types (~> 3.0)
18
- multi_xml (>= 0.5.2)
19
20
  json (2.1.0)
20
21
  method_source (0.9.2)
21
- mime-types (3.2.2)
22
- mime-types-data (~> 3.2015)
23
- mime-types-data (3.2018.0812)
24
- multi_xml (0.6.0)
22
+ minitest (5.11.3)
23
+ multipart-post (2.0.0)
25
24
  pry (0.12.2)
26
25
  coderay (~> 1.1.0)
27
26
  method_source (~> 0.9.0)
28
27
  rake (10.5.0)
29
- rspec (3.8.0)
30
- rspec-core (~> 3.8.0)
31
- rspec-expectations (~> 3.8.0)
32
- rspec-mocks (~> 3.8.0)
33
- rspec-core (3.8.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-expectations (3.8.2)
36
- diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.8.0)
38
- rspec-mocks (3.8.0)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.8.0)
41
- rspec-support (3.8.0)
42
28
  simplecov (0.16.1)
43
29
  docile (~> 1.1)
44
30
  json (>= 1.8, < 3)
@@ -52,10 +38,10 @@ DEPENDENCIES
52
38
  bump
53
39
  bundler
54
40
  deribit-api!
41
+ minitest
55
42
  pry
56
43
  rake
57
- rspec
58
44
  simplecov
59
45
 
60
46
  BUNDLED WITH
61
- 1.17.1
47
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Iulian Costan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/1e100fc78c8ebaa8b4b5/maintainability)](https://codeclimate.com/github/icostan/deribit-api-ruby/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1e100fc78c8ebaa8b4b5/test_coverage)](https://codeclimate.com/github/icostan/deribit-api-ruby/test_coverage)
6
6
  [![Gem Version](https://badge.fury.io/rb/deribit-api.svg)](https://badge.fury.io/rb/deribit-api)
7
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/deribit-api)
8
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/icostan/deribit-api-ruby/blob/master/LICENSE)
7
9
 
8
10
  Ruby library for [Deribit API](https://docs.deribit.com)
9
11
 
@@ -25,14 +27,70 @@ Or install it yourself as:
25
27
 
26
28
  ## Usage
27
29
 
30
+ ### Overview
31
+
28
32
  ```ruby
29
- require 'deribit'
33
+ require 'deribit-api'
30
34
 
31
35
  client = Deribit::Client.new
32
36
 
33
- trades = client.getlasttrades
34
- trades.size
37
+ trades = client.trades 'options', count: 3
35
38
  trades.first
39
+ => #<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>
40
+ trades.first.instrument
41
+ => "BTC-29MAR19-4500-C"
42
+ ```
43
+
44
+ ### API Endpoints
45
+
46
+ #### Instruments
47
+
48
+ ```ruby
49
+ instruments = client.instruments
50
+ puts instruments.first
51
+ ```
52
+
53
+ #### Currencies
54
+
55
+ ```ruby
56
+ currencies = client.currencies
57
+ puts currencies.first
58
+ ```
59
+
60
+ #### Orderbook
61
+
62
+ ```ruby
63
+ orderbook = client.orderbook 'BTC-PERPETUAL', depth: 3
64
+ puts orderbook.bids.first
65
+ ```
66
+
67
+ #### Trades
68
+
69
+ ```ruby
70
+ trades = client.trades 'options', count: 3
71
+ puts trades.first
72
+ ```
73
+
74
+ #### Summary
75
+
76
+
77
+ ```ruby
78
+ summaries = client.summary :futures
79
+ puts summaries.first
80
+ ```
81
+
82
+ #### Announcements
83
+
84
+ ```ruby
85
+ announcements = client.announcements
86
+ puts announcements.first
87
+ ```
88
+
89
+ #### Settlements
90
+
91
+ ```ruby
92
+ settlements = client.settlements
93
+ puts settlements.first
36
94
  ```
37
95
 
38
96
  ## Development
@@ -43,7 +101,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
43
101
 
44
102
  ## Contributing
45
103
 
46
- Bug reports and pull requests are welcome on GitHub at https://github.com/icostan/deribit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+ 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](http://contributor-covenant.org) code of conduct.
47
105
 
48
106
  ## Code of Conduct
49
107
 
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
5
9
 
6
- task :default => :spec
10
+ task default: :test
@@ -0,0 +1,9 @@
1
+ * Tasks :DERIBIT:
2
+ ** DONE Initial deribit gem release
3
+ CLOSED: [2019-01-04 Fri] SCHEDULED: <2019-01-04 Fri>
4
+ ** DONE public HTTP API
5
+ CLOSED: [2019-02-27 Wed] SCHEDULED: <2019-02-27 Wed>
6
+ ** TODO private HTTP API
7
+ ** FIX API
8
+ ** DONE use minitest
9
+ CLOSED: [2019-02-26 Tue] SCHEDULED: <2019-02-26 Tue>
@@ -35,12 +35,13 @@ Gem::Specification.new do |spec|
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ['lib']
37
37
 
38
- spec.add_dependency 'httparty'
38
+ spec.add_dependency 'faraday'
39
+ spec.add_dependency 'faraday_middleware'
39
40
  spec.add_dependency 'hashie'
40
41
 
41
42
  spec.add_development_dependency 'bundler'
42
43
  spec.add_development_dependency 'rake'
43
- spec.add_development_dependency 'rspec'
44
+ spec.add_development_dependency 'minitest'
44
45
  spec.add_development_dependency 'bump'
45
46
  spec.add_development_dependency 'pry'
46
47
  spec.add_development_dependency 'simplecov'
@@ -0,0 +1 @@
1
+ require_relative 'deribit'
@@ -1,10 +1,12 @@
1
- require 'httparty'
1
+ require 'faraday'
2
+ require 'faraday_middleware'
2
3
  require 'hashie'
3
4
 
4
5
  require 'deribit/version'
5
6
  require 'deribit/client'
6
7
 
8
+ # Root module
7
9
  module Deribit
10
+ # Base error class
8
11
  class Error < StandardError; end
9
- # Your code goes here...
10
12
  end
@@ -1,36 +1,147 @@
1
1
  module Deribit
2
+ # @author Iulian Costan
2
3
  class Client
3
- include HTTParty
4
- base_uri 'https://test.deribit.com/api/v1/public'
4
+ # URL for testnet
5
+ TESTNET_URL = 'https://test.deribit.com'
6
+ # URL for mainnet
7
+ MAINNET_URL = 'https://www.deribit.com'
5
8
 
6
- def initialize
7
- @options = {}
9
+ # Create new instance
10
+ # @param testnet [Boolean] set to true for testing
11
+ # @param debug [Boolean] set to true for debug output
12
+ # @return [Deribit::Client] the instance of client
13
+ def initialize(testnet: false, debug: false)
14
+ url = testnet ? TESTNET_URL : MAINNET_URL
15
+ @connection = Faraday::Connection.new(url: url) do |f|
16
+ f.request :json
17
+ f.response :mashify
18
+ f.response :json
19
+ f.response :logger if debug
20
+ f.adapter Faraday.default_adapter
21
+ end
8
22
  end
9
23
 
10
- def getinstruments
11
- execute '/getinstruments'
24
+ # Retrieves the current time (in ms).
25
+ # @return [Integer] current time in milliseconds
26
+ # @see https://docs.deribit.com/rpc-endpoints.html#time
27
+ def time
28
+ execute :time
12
29
  end
13
30
 
14
- def getlasttrades(type = :all)
15
- execute '/getlasttrades', query: { instrument: type }
31
+ # Tests the connection to the API server, and returns its version.
32
+ # @param exception [any] Provide this parameter force an error message.
33
+ # @return [Hashie::Mash] test data
34
+ # @see https://docs.deribit.com/rpc-endpoints.html#test
35
+ def test(exception: false)
36
+ execute :test, params: { exception: exception }, raw_body: true
16
37
  end
17
38
 
18
- def getsummary(type = :all)
19
- execute '/getsummary', query: { instrument: type }
39
+ # This API endpoint always responds with "pong".
40
+ # @return [Hashie::Mash] ping
41
+ # @see https://docs.deribit.com/rpc-endpoints.html#ping
42
+ def ping
43
+ execute :ping
20
44
  end
21
45
 
46
+ # Retrieves available trading instruments.
47
+ # @param expired [Boolean] Set to true to show expired instruments instead of active ones.
48
+ # @return [Array] the list of instruments
49
+ # @see https://docs.deribit.com/rpc-endpoints.html#getinstruments
50
+ def instruments(expired: false)
51
+ execute :getinstruments, params: { expired: expired }
52
+ end
53
+
54
+ # Retrieves all cryptocurrencies supported by the API.
55
+ # @return [Array] the list of cryptocurrencies
56
+ # @see https://docs.deribit.com/rpc-endpoints.html#getcurrencies
57
+ def currencies
58
+ execute :getcurrencies
59
+ end
60
+
61
+ # Retrieves the current index price for the BTC-USD instruments.
62
+ # @return [Hashie::Mash] index price for BTC-USD instrument
63
+ # @see https://docs.deribit.com/rpc-endpoints.html#index
64
+ def index
65
+ execute :index
66
+ end
67
+
68
+ # Retrieves the order book, along with other market values for a given instrument.
69
+ # @param instrument [String] The instrument name for which to retrieve the order book, (see #instruments) to obtain instrument names.
70
+ # @param depth [Integer] the depth of the order book
71
+ # @return [Hashie::Mash] the order book
72
+ # @see https://docs.deribit.com/rpc-endpoints.html#getorderbook
73
+ def orderbook(instrument, depth: 10)
74
+ raise ArgumentError, 'instrument param is required' unless instrument
75
+
76
+ execute :getorderbook, params: { instrument: instrument, depth: depth }
77
+ end
78
+
79
+ # Retrieve the latest trades that have occurred for a specific instrument.
80
+ # @param instrument [String] Either the name of the instrument, or "all" for all active instruments, "futures" for all active futures, or "options" for all active options.
81
+ # @param filters [Hash] the filters
82
+ # @option filters [Integer] :count (10) The number of trades returned (clamped to max 1000)
83
+ # @option filters [Integer] :startId The ID of the first trade to be returned
84
+ # @option filters [Integer] :endId The ID of the last trade to be returned
85
+ # @option filters [Integer] :startSeq The trade sequence of the first trade to be returned
86
+ # @option filters [Integer] :endSeq The trade sequence of the last trade to be returned
87
+ # @option filters [Integer] :startTimestamp The timestamp (in ms) of the first trade to be returned
88
+ # @option filters [Integer] :endTimestamp The timestamp (in ms) of the last trade to be returned
89
+ # @option filters [Boolean] :includeOld (false) to get archived trades for expired instruments when true (added from performance considerations)
90
+ # @return [Array] the list of trades
91
+ # @see https://docs.deribit.com/rpc-endpoints.html#getlasttrades
92
+ def trades(instrument, filters = {})
93
+ raise ArgumentError, 'instrument param is required' unless instrument
94
+
95
+ execute :getlasttrades, params: filters.merge(instrument: instrument)
96
+ end
97
+
98
+ # Retrieves the summary information such as open interest, 24h volume, etc. for a specific instrument.
99
+ # @param instrument [String] Either the name of the instrument, or 'all' for all active instruments, 'futures' for all active futures, or 'options' for all active options.
100
+ # @return [Array, Hashie::Hash] the summary as array or hash based on instrument param
101
+ # @see https://docs.deribit.com/rpc-endpoints.html#getsummary
102
+ def summary(instrument)
103
+ raise ArgumentError, 'instrument argument is required' unless instrument
104
+
105
+ execute :getsummary, params: { instrument: instrument }
106
+ end
107
+
108
+ # Retrieves aggregated 24h trade volumes for different instrument types.
109
+ # @return [Hashie::Mash] the statistics
110
+ # @see https://docs.deribit.com/rpc-endpoints.html#stats
22
111
  def stats
23
- execute '/stats'
112
+ execute :stats
113
+ end
114
+
115
+ # Retrieves announcements from last 30 days.
116
+ # @return [Array] the list of announcements
117
+ # @see https://docs.deribit.com/rpc-endpoints.html#getannouncements
118
+ def announcements
119
+ execute :getannouncements
120
+ end
121
+
122
+ # Retrieves settlement, delivery and bankruptcy events that have occurred.
123
+ # @param filters [Hash] the filters
124
+ # @option filters [String] :instrument The instrument name, or "all" to retrieve settlements for all instruments
125
+ # @option filters [Integer] :count (10) The number of entries to be returned. This is clamped to max 1000
126
+ # @option filters [String] :type The type of settlements to return. Possible values "settlement", "delivery", "bankruptcy"
127
+ # @option filters [Integer] :startTstamp The latest timestamp to return result for
128
+ # @option filters [String] :continuation Continuation token for pagination. Each response contains a token to be used for continuation
129
+ # @return [Hashie::Hash] the settlements
130
+ # @see https://docs.deribit.com/rpc-endpoints.html#getlastsettlements
131
+ def settlements(filters = {})
132
+ execute :getlastsettlements, params: filters
24
133
  end
25
134
 
26
135
  private
27
136
 
28
- def execute(uri, options = {})
29
- response = self.class.get uri, options
30
- fail response.message unless response.success?
31
- fail response.body unless response['success']
137
+ def execute(action, params: {}, raw_body: false)
138
+ path = "/api/v1/public/#{action}"
139
+ response = @connection.get path, params
140
+ raise response.message unless response.success?
141
+ raise response.body.message unless response.body.success
32
142
 
33
- Hashie::Mash.new(response.to_hash).result
143
+ body = response.body
144
+ raw_body ? body : body.result
34
145
  end
35
146
  end
36
147
  end
@@ -1,3 +1,3 @@
1
1
  module Deribit
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deribit-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iulian Costan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rspec
84
+ name: minitest
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -130,18 +144,20 @@ extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
132
146
  - ".gitignore"
133
- - ".rspec"
134
147
  - ".ruby-version"
135
148
  - ".travis.yml"
136
149
  - CHANGELOG.md
137
150
  - CODE_OF_CONDUCT.md
138
151
  - Gemfile
139
152
  - Gemfile.lock
153
+ - LICENSE
140
154
  - README.md
141
155
  - Rakefile
156
+ - TODOs.org
142
157
  - bin/console
143
158
  - bin/setup
144
159
  - deribit.gemspec
160
+ - lib/deribit-api.rb
145
161
  - lib/deribit.rb
146
162
  - lib/deribit/client.rb
147
163
  - lib/deribit/version.rb
@@ -168,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
184
  version: '0'
169
185
  requirements: []
170
186
  rubyforge_project:
171
- rubygems_version: 2.7.6
187
+ rubygems_version: 2.6.14.1
172
188
  signing_key:
173
189
  specification_version: 4
174
190
  summary: Ruby library for Deribit API
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper