deribit-api 0.0.2 → 0.0.3
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 +5 -5
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +42 -4
- data/README.md +61 -27
- data/Rakefile +1 -0
- data/TODOs.org +6 -1
- data/bin/console +7 -3
- data/deribit.gemspec +3 -0
- data/lib/deribit.rb +1 -0
- data/lib/deribit/authentication.rb +43 -0
- data/lib/deribit/client.rb +201 -27
- data/lib/deribit/version.rb +1 -1
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 05d5477493865ee6cbb3377f3e3b00b7cf46b4e6b68d521e55330e391a3aa5cd
|
4
|
+
data.tar.gz: bbd48b6395cca467b1f5cb86ab3d7aeea3d888d69a8bddbd98178cbf841af849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0af359c229cc8e7651fe2cbf2c0609ffefce77d09bca0a750cb884d33fb2d17b2de56fd19c1aa7414375ca99149ac581b016c7893732afaaaf86c248398aff6
|
7
|
+
data.tar.gz: 876927c4c4acc286246a5315b66efa642053a925777953fce590ffc6af2627ba0a38ff95e7e49508517646512d8437fde4e3e8b9a15e7891892d23eaec950e51
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@
|
|
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.3] - 2019-03-06
|
9
|
+
### Added
|
10
|
+
- private HTTP API endpoints
|
11
|
+
### Fixed
|
12
|
+
- ENV vars loading in bin/console
|
13
|
+
|
8
14
|
## [0.0.2] - 2019-02-27
|
9
15
|
### Added
|
10
16
|
- HTTP public endpoints
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
deribit-api (0.0.
|
4
|
+
deribit-api (0.0.3)
|
5
5
|
faraday
|
6
6
|
faraday_middleware
|
7
7
|
hashie
|
@@ -9,27 +9,62 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
|
12
|
+
ast (2.4.0)
|
13
|
+
axiom-types (0.1.1)
|
14
|
+
descendants_tracker (~> 0.0.4)
|
15
|
+
ice_nine (~> 0.11.0)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
17
|
+
bump (0.8.0)
|
18
|
+
codeclimate-engine-rb (0.4.1)
|
19
|
+
virtus (~> 1.0)
|
13
20
|
coderay (1.1.2)
|
21
|
+
coercible (1.0.0)
|
22
|
+
descendants_tracker (~> 0.0.1)
|
23
|
+
descendants_tracker (0.0.4)
|
24
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
14
25
|
docile (1.3.1)
|
26
|
+
dotenv (2.7.1)
|
27
|
+
equalizer (0.0.11)
|
15
28
|
faraday (0.15.4)
|
16
29
|
multipart-post (>= 1.2, < 3)
|
17
30
|
faraday_middleware (0.13.1)
|
18
31
|
faraday (>= 0.7.4, < 1.0)
|
19
32
|
hashie (3.6.0)
|
20
|
-
|
33
|
+
ice_nine (0.11.2)
|
34
|
+
json (2.2.0)
|
35
|
+
kwalify (0.7.2)
|
21
36
|
method_source (0.9.2)
|
22
37
|
minitest (5.11.3)
|
23
38
|
multipart-post (2.0.0)
|
39
|
+
parser (2.6.0.0)
|
40
|
+
ast (~> 2.4.0)
|
24
41
|
pry (0.12.2)
|
25
42
|
coderay (~> 1.1.0)
|
26
43
|
method_source (~> 0.9.0)
|
27
|
-
|
44
|
+
pry-doc (1.0.0)
|
45
|
+
pry (~> 0.11)
|
46
|
+
yard (~> 0.9.11)
|
47
|
+
psych (3.1.0)
|
48
|
+
rainbow (3.0.0)
|
49
|
+
rake (12.3.2)
|
50
|
+
reek (5.3.1)
|
51
|
+
codeclimate-engine-rb (~> 0.4.0)
|
52
|
+
kwalify (~> 0.7.0)
|
53
|
+
parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
|
54
|
+
psych (~> 3.1.0)
|
55
|
+
rainbow (>= 2.0, < 4.0)
|
28
56
|
simplecov (0.16.1)
|
29
57
|
docile (~> 1.1)
|
30
58
|
json (>= 1.8, < 3)
|
31
59
|
simplecov-html (~> 0.10.0)
|
32
60
|
simplecov-html (0.10.2)
|
61
|
+
thread_safe (0.3.6)
|
62
|
+
virtus (1.0.5)
|
63
|
+
axiom-types (~> 0.1)
|
64
|
+
coercible (~> 1.0)
|
65
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
66
|
+
equalizer (~> 0.0, >= 0.0.9)
|
67
|
+
yard (0.9.18)
|
33
68
|
|
34
69
|
PLATFORMS
|
35
70
|
ruby
|
@@ -38,9 +73,12 @@ DEPENDENCIES
|
|
38
73
|
bump
|
39
74
|
bundler
|
40
75
|
deribit-api!
|
76
|
+
dotenv
|
41
77
|
minitest
|
42
78
|
pry
|
79
|
+
pry-doc
|
43
80
|
rake
|
81
|
+
reek
|
44
82
|
simplecov
|
45
83
|
|
46
84
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/icostan/deribit-api-ruby)
|
4
4
|
[](https://codeclimate.com/github/icostan/deribit-api-ruby/maintainability)
|
5
5
|
[](https://codeclimate.com/github/icostan/deribit-api-ruby/test_coverage)
|
6
|
+
[](http://inch-ci.org/github/icostan/deribit-api-ruby)
|
6
7
|
[](https://badge.fury.io/rb/deribit-api)
|
7
8
|
[](https://www.rubydoc.info/gems/deribit-api)
|
8
9
|
[](https://github.com/icostan/deribit-api-ruby/blob/master/LICENSE)
|
@@ -31,9 +32,12 @@ Or install it yourself as:
|
|
31
32
|
|
32
33
|
```ruby
|
33
34
|
require 'deribit-api'
|
35
|
+
```
|
34
36
|
|
35
|
-
client
|
37
|
+
Create a simple client to access public APIs
|
36
38
|
|
39
|
+
```ruby
|
40
|
+
client = Deribit::Client.new
|
37
41
|
trades = client.trades 'options', count: 3
|
38
42
|
trades.first
|
39
43
|
=> #<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>
|
@@ -41,57 +45,87 @@ trades.first.instrument
|
|
41
45
|
=> "BTC-29MAR19-4500-C"
|
42
46
|
```
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
#### Instruments
|
48
|
+
Pass key and secret to access private APIs
|
47
49
|
|
48
50
|
```ruby
|
49
|
-
|
50
|
-
|
51
|
+
client = Deribit::Client.new key: 'KEY', secret: 'SECRET'
|
52
|
+
account = client.account
|
53
|
+
=> #<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>
|
54
|
+
account.equity
|
55
|
+
=> 9.999957896
|
51
56
|
```
|
52
57
|
|
53
|
-
|
58
|
+
### Examples
|
59
|
+
|
60
|
+
Fetch all tradable instruments:
|
54
61
|
|
55
62
|
```ruby
|
56
|
-
|
57
|
-
puts
|
63
|
+
instruments = client.instruments
|
64
|
+
puts instruments.first
|
58
65
|
```
|
59
66
|
|
60
|
-
|
67
|
+
Orderbook for BTCUSD perpetual instrument:
|
61
68
|
|
62
69
|
```ruby
|
63
70
|
orderbook = client.orderbook 'BTC-PERPETUAL', depth: 3
|
64
|
-
puts orderbook.
|
71
|
+
puts orderbook.asks.first
|
65
72
|
```
|
66
73
|
|
67
|
-
|
74
|
+
Place a BTCUSD limit buy order 100 contracts @ 2500:
|
68
75
|
|
69
76
|
```ruby
|
70
|
-
|
71
|
-
puts
|
77
|
+
response = client.buy 'BTC-PERPETUAL', 100, price: 2500
|
78
|
+
puts response.order.state
|
72
79
|
```
|
73
80
|
|
74
|
-
|
75
|
-
|
81
|
+
Get last 10 option trades:
|
76
82
|
|
77
83
|
```ruby
|
78
|
-
|
79
|
-
puts
|
84
|
+
trades = client.trades 'options', count: 10
|
85
|
+
puts trades.first
|
80
86
|
```
|
81
87
|
|
82
|
-
|
88
|
+
Options trading summary:
|
83
89
|
|
84
90
|
```ruby
|
85
|
-
|
86
|
-
puts
|
91
|
+
summaries = client.summary :options
|
92
|
+
puts summaries.first
|
87
93
|
```
|
88
94
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
+
## API Endpoints
|
96
|
+
|
97
|
+
All endpoints marked with [X] are fully implemented and ready to use, see the features table below:
|
98
|
+
|
99
|
+
API endpoints | Private? | HTTP API | Websocket API | FIX API
|
100
|
+
---| :---: | :---: | :---: |
|
101
|
+
Time || [X] ||
|
102
|
+
Test || [X] ||
|
103
|
+
Ping || [X] ||
|
104
|
+
Instruments || [X] ||
|
105
|
+
Currencies || [X] ||
|
106
|
+
Index || [X] ||
|
107
|
+
Orderbook || [X] ||
|
108
|
+
Trades || [X] ||
|
109
|
+
Summary || [X] ||
|
110
|
+
Announcements || [X] ||
|
111
|
+
Settlements || [X] ||
|
112
|
+
Account | YES | [X] ||
|
113
|
+
Buy | YES | [X] ||
|
114
|
+
Sell | YES | [X] ||
|
115
|
+
Edit | YES | [X] ||
|
116
|
+
Cancel | YES | [X] ||
|
117
|
+
Cancel all | YES | [X] ||
|
118
|
+
Orders | YES | [X] ||
|
119
|
+
Positions | YES | [X] ||
|
120
|
+
Orders history | YES | [X] ||
|
121
|
+
Order | YES | [X] ||
|
122
|
+
Trades history | YES | [X] ||
|
123
|
+
New announcements | YES | [X] ||
|
124
|
+
Cancel on disconnect | YES | [X] ||
|
125
|
+
Get email lang | YES | [X] ||
|
126
|
+
Set email lang | YES | [X] ||
|
127
|
+
Set announcements read | YES | [X] ||
|
128
|
+
Settlements history | YES | [X] ||
|
95
129
|
|
96
130
|
## Development
|
97
131
|
|
data/Rakefile
CHANGED
data/TODOs.org
CHANGED
@@ -3,7 +3,12 @@
|
|
3
3
|
CLOSED: [2019-01-04 Fri] SCHEDULED: <2019-01-04 Fri>
|
4
4
|
** DONE public HTTP API
|
5
5
|
CLOSED: [2019-02-27 Wed] SCHEDULED: <2019-02-27 Wed>
|
6
|
-
**
|
6
|
+
** DONE private HTTP API
|
7
|
+
CLOSED: [2019-03-05 Tue] SCHEDULED: <2019-03-04 Mon>
|
7
8
|
** FIX API
|
8
9
|
** DONE use minitest
|
9
10
|
CLOSED: [2019-02-26 Tue] SCHEDULED: <2019-02-26 Tue>
|
11
|
+
** extract RPC client
|
12
|
+
** Websocket API
|
13
|
+
** response middleware
|
14
|
+
** check key/secret present for private endpoints
|
data/bin/console
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'dotenv'
|
4
|
+
Dotenv.load
|
5
|
+
Dotenv.require_keys('API_KEY', 'API_SECRET')
|
6
|
+
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'deribit'
|
5
9
|
|
6
10
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
11
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +14,5 @@ require "deribit"
|
|
10
14
|
# require "pry"
|
11
15
|
# Pry.start
|
12
16
|
|
13
|
-
require
|
17
|
+
require 'irb'
|
14
18
|
IRB.start(__FILE__)
|
data/deribit.gemspec
CHANGED
@@ -40,9 +40,12 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency 'hashie'
|
41
41
|
|
42
42
|
spec.add_development_dependency 'bundler'
|
43
|
+
spec.add_development_dependency 'dotenv'
|
43
44
|
spec.add_development_dependency 'rake'
|
44
45
|
spec.add_development_dependency 'minitest'
|
45
46
|
spec.add_development_dependency 'bump'
|
46
47
|
spec.add_development_dependency 'pry'
|
48
|
+
spec.add_development_dependency 'pry-doc'
|
49
|
+
spec.add_development_dependency 'reek'
|
47
50
|
spec.add_development_dependency 'simplecov'
|
48
51
|
end
|
data/lib/deribit.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module Deribit
|
5
|
+
# Deribit authentication implemented as Faraday middleware
|
6
|
+
# @see https://docs.deribit.com/rpc-authentication.html
|
7
|
+
class Authentication < Faraday::Middleware
|
8
|
+
def initialize(app, key, secret)
|
9
|
+
super(app)
|
10
|
+
@key = key
|
11
|
+
@secret = secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
return @app.call(env) if @key.nil? || @secret.nil?
|
16
|
+
|
17
|
+
nonce = Time.now.to_i
|
18
|
+
env['request_headers']['X-Deribit-Sig'] = signature env, nonce
|
19
|
+
|
20
|
+
@app.call env
|
21
|
+
end
|
22
|
+
|
23
|
+
def signature(env, nonce)
|
24
|
+
params = {
|
25
|
+
_: nonce,
|
26
|
+
_ackey: @key,
|
27
|
+
_acsec: @secret,
|
28
|
+
_action: env['url'].path
|
29
|
+
}
|
30
|
+
# add POST params
|
31
|
+
params.merge! JSON.parse(env['body']) if env['body']
|
32
|
+
|
33
|
+
signature_string = params.map{ |key, value| "#{key}=#{value}" }.sort.join '&'
|
34
|
+
# add GET query
|
35
|
+
signature_string += "&#{env['url'].query}" if env['url'].query
|
36
|
+
|
37
|
+
signature_digest = Digest::SHA256.digest signature_string
|
38
|
+
signature_hash = Base64.encode64 signature_digest
|
39
|
+
|
40
|
+
"#{@key}.#{nonce}.#{signature_hash.chomp}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/deribit/client.rb
CHANGED
@@ -7,15 +7,18 @@ module Deribit
|
|
7
7
|
MAINNET_URL = 'https://www.deribit.com'
|
8
8
|
|
9
9
|
# Create new instance
|
10
|
+
# @param key [String] Deribit Access Key
|
11
|
+
# @param secret [String] Deribit Secret Key
|
10
12
|
# @param testnet [Boolean] set to true for testing
|
11
13
|
# @param debug [Boolean] set to true for debug output
|
12
14
|
# @return [Deribit::Client] the instance of client
|
13
|
-
def initialize(testnet: false, debug: false)
|
15
|
+
def initialize(key: nil, secret: nil, testnet: false, debug: false)
|
14
16
|
url = testnet ? TESTNET_URL : MAINNET_URL
|
15
17
|
@connection = Faraday::Connection.new(url: url) do |f|
|
16
18
|
f.request :json
|
17
19
|
f.response :mashify
|
18
20
|
f.response :json
|
21
|
+
f.use Deribit::Authentication, key, secret
|
19
22
|
f.response :logger if debug
|
20
23
|
f.adapter Faraday.default_adapter
|
21
24
|
end
|
@@ -25,7 +28,7 @@ module Deribit
|
|
25
28
|
# @return [Integer] current time in milliseconds
|
26
29
|
# @see https://docs.deribit.com/rpc-endpoints.html#time
|
27
30
|
def time
|
28
|
-
|
31
|
+
get :time
|
29
32
|
end
|
30
33
|
|
31
34
|
# Tests the connection to the API server, and returns its version.
|
@@ -33,14 +36,14 @@ module Deribit
|
|
33
36
|
# @return [Hashie::Mash] test data
|
34
37
|
# @see https://docs.deribit.com/rpc-endpoints.html#test
|
35
38
|
def test(exception: false)
|
36
|
-
|
39
|
+
get :test, params: { exception: exception }, raw_body: true
|
37
40
|
end
|
38
41
|
|
39
42
|
# This API endpoint always responds with "pong".
|
40
43
|
# @return [Hashie::Mash] ping
|
41
44
|
# @see https://docs.deribit.com/rpc-endpoints.html#ping
|
42
45
|
def ping
|
43
|
-
|
46
|
+
get :ping
|
44
47
|
end
|
45
48
|
|
46
49
|
# Retrieves available trading instruments.
|
@@ -48,21 +51,21 @@ module Deribit
|
|
48
51
|
# @return [Array] the list of instruments
|
49
52
|
# @see https://docs.deribit.com/rpc-endpoints.html#getinstruments
|
50
53
|
def instruments(expired: false)
|
51
|
-
|
54
|
+
get :getinstruments, params: { expired: expired }
|
52
55
|
end
|
53
56
|
|
54
57
|
# Retrieves all cryptocurrencies supported by the API.
|
55
58
|
# @return [Array] the list of cryptocurrencies
|
56
59
|
# @see https://docs.deribit.com/rpc-endpoints.html#getcurrencies
|
57
60
|
def currencies
|
58
|
-
|
61
|
+
get :getcurrencies
|
59
62
|
end
|
60
63
|
|
61
64
|
# Retrieves the current index price for the BTC-USD instruments.
|
62
65
|
# @return [Hashie::Mash] index price for BTC-USD instrument
|
63
66
|
# @see https://docs.deribit.com/rpc-endpoints.html#index
|
64
67
|
def index
|
65
|
-
|
68
|
+
get :index
|
66
69
|
end
|
67
70
|
|
68
71
|
# Retrieves the order book, along with other market values for a given instrument.
|
@@ -73,26 +76,27 @@ module Deribit
|
|
73
76
|
def orderbook(instrument, depth: 10)
|
74
77
|
raise ArgumentError, 'instrument param is required' unless instrument
|
75
78
|
|
76
|
-
|
79
|
+
get :getorderbook, params: { instrument: instrument, depth: depth }
|
77
80
|
end
|
78
81
|
|
79
82
|
# Retrieve the latest trades that have occurred for a specific instrument.
|
80
83
|
# @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
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
84
|
+
# @!macro deribit.filters
|
85
|
+
# @param filters [Hash] extra filters to apply
|
86
|
+
# @option filters [Integer] :count (10) The number of trades returned (clamped to max 1000)
|
87
|
+
# @option filters [Integer] :startId The ID of the first trade to be returned
|
88
|
+
# @option filters [Integer] :endId The ID of the last trade to be returned
|
89
|
+
# @option filters [Integer] :startSeq The trade sequence of the first trade to be returned
|
90
|
+
# @option filters [Integer] :endSeq The trade sequence of the last trade to be returned
|
91
|
+
# @option filters [Integer] :startTimestamp The timestamp (in ms) of the first trade to be returned
|
92
|
+
# @option filters [Integer] :endTimestamp The timestamp (in ms) of the last trade to be returned
|
93
|
+
# @option filters [Boolean] :includeOld (false) to get archived trades for expired instruments when true (added from performance considerations)
|
90
94
|
# @return [Array] the list of trades
|
91
95
|
# @see https://docs.deribit.com/rpc-endpoints.html#getlasttrades
|
92
|
-
def trades(instrument, filters = {})
|
96
|
+
def trades(instrument = :all, filters = {})
|
93
97
|
raise ArgumentError, 'instrument param is required' unless instrument
|
94
98
|
|
95
|
-
|
99
|
+
get :getlasttrades, params: filters.merge(instrument: instrument)
|
96
100
|
end
|
97
101
|
|
98
102
|
# Retrieves the summary information such as open interest, 24h volume, etc. for a specific instrument.
|
@@ -102,21 +106,21 @@ module Deribit
|
|
102
106
|
def summary(instrument)
|
103
107
|
raise ArgumentError, 'instrument argument is required' unless instrument
|
104
108
|
|
105
|
-
|
109
|
+
get :getsummary, params: { instrument: instrument }
|
106
110
|
end
|
107
111
|
|
108
112
|
# Retrieves aggregated 24h trade volumes for different instrument types.
|
109
113
|
# @return [Hashie::Mash] the statistics
|
110
114
|
# @see https://docs.deribit.com/rpc-endpoints.html#stats
|
111
115
|
def stats
|
112
|
-
|
116
|
+
get :stats
|
113
117
|
end
|
114
118
|
|
115
119
|
# Retrieves announcements from last 30 days.
|
116
120
|
# @return [Array] the list of announcements
|
117
121
|
# @see https://docs.deribit.com/rpc-endpoints.html#getannouncements
|
118
122
|
def announcements
|
119
|
-
|
123
|
+
get :getannouncements
|
120
124
|
end
|
121
125
|
|
122
126
|
# Retrieves settlement, delivery and bankruptcy events that have occurred.
|
@@ -129,19 +133,189 @@ module Deribit
|
|
129
133
|
# @return [Hashie::Hash] the settlements
|
130
134
|
# @see https://docs.deribit.com/rpc-endpoints.html#getlastsettlements
|
131
135
|
def settlements(filters = {})
|
132
|
-
|
136
|
+
get :getlastsettlements, params: filters
|
137
|
+
end
|
138
|
+
|
139
|
+
# Retrieves user account summary.
|
140
|
+
# @param ext [Boolean] Requests additional fields
|
141
|
+
# @return [Hashie::Mash] the account details
|
142
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#account
|
143
|
+
def account(ext: false)
|
144
|
+
get :account, auth: true
|
145
|
+
end
|
146
|
+
|
147
|
+
# Places a buy order for an instrument.
|
148
|
+
# @param instrument [String] Name of the instrument to buy
|
149
|
+
# @param quantity [Integer] The number of contracts to buy
|
150
|
+
# @!macro deribit.options
|
151
|
+
# @param options [Hash] more options for the order
|
152
|
+
# @option options [String] :type (limit) The order type, possible types: "limit", "stop_limit", "market", "stop_market"
|
153
|
+
# @option options [Float] :price The order price (Only valid for limit and stop_limit orders)
|
154
|
+
# @option options [String] :label user defined label for the order (maximum 32 characters)
|
155
|
+
# @option options [String] :time_in_force (good_til_cancelled) Specifies how long the order remains in effect, possible values "good_til_cancelled", "fill_or_kill", "immediate_or_cancel"
|
156
|
+
# @option options [Integer] :max_show Maximum quantity within an order to be shown to other customers, 0 for invisible order.
|
157
|
+
# @option options [String] :post_only (true) If true, the order is considered post-only. If the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the bid.
|
158
|
+
# @option options [Float] :stopPx Stop price required for stop limit orders (Only valid for stop orders)
|
159
|
+
# @option options [String] :execInst (index_price) Defines trigger type, required for "stop_limit" order type, possible values "index_price", "mark_price" (Only valid for stop orders)
|
160
|
+
# @option options [String] :adv Advanced option order type, can be "implv", "usd". (Only valid for options)
|
161
|
+
# @return [Hashie::Mash] the details of new order
|
162
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#buy
|
163
|
+
def buy(instrument, quantity, options = {})
|
164
|
+
post :buy, instrument: instrument, quantity: quantity, price: options[:price]
|
165
|
+
end
|
166
|
+
|
167
|
+
# Places a sell order for an instrument.
|
168
|
+
# @param instrument [String] Name of the instrument to sell
|
169
|
+
# @param quantity [Integer] The number of contracts to sell
|
170
|
+
# @!macro deribit.options
|
171
|
+
# @return [Hashie::Mash] the details of new order
|
172
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#sell
|
173
|
+
def sell(instrument, quantity, options = {})
|
174
|
+
post :sell, options.merge(instrument: instrument, quantity: quantity)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Changes price and/or quantity of the own order.
|
178
|
+
# @param order_id [String] ID of the order to edit
|
179
|
+
# @param quantity [Integer] The new order quantity
|
180
|
+
# @param price [Float] The new order price
|
181
|
+
# @param options [Hash] extra options
|
182
|
+
# @option options [Boolean] :post_only If true, the edited order is considered post-only. If the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the bid (for buy orders) or just above the ask (for sell orders).
|
183
|
+
# @option options [String] :adv The new advanced order type (only valid for option orders)
|
184
|
+
# @option options [Float] :stopPx The new stop price (only valid for stop limit orders)
|
185
|
+
# @return [Hashie::Mash] the edited order
|
186
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#edit
|
187
|
+
def edit(order_id, quantity, price, options = {})
|
188
|
+
post :edit, options.merge(orderId: order_id, quantity: quantity, price: price)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Cancels an order, specified by order id.
|
192
|
+
# @param order_id [String] The order id of the order to be cancelled
|
193
|
+
# @return [Hashie::Mash] details of the cancelled order
|
194
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#cancel
|
195
|
+
def cancel(order_id)
|
196
|
+
post :cancel, orderId: order_id
|
197
|
+
end
|
198
|
+
|
199
|
+
# Cancels all orders, optionally filtered by instrument or instrument type.
|
200
|
+
# @param type [all futures options] Which type of orders to cancel. Valid values are "all", "futures", "options"
|
201
|
+
# @param options [Hash] extra options
|
202
|
+
# @option options [String] :instrument The name of the instrument for which to cancel all orders
|
203
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#cancelall
|
204
|
+
def cancelall(type = :all, options = {})
|
205
|
+
post :cancelall, options.merge(type: type)
|
206
|
+
end
|
207
|
+
|
208
|
+
# Retrieves open orders.
|
209
|
+
# @param options [Hash]
|
210
|
+
# @option options [String] :instrument Instrument to return open orders for
|
211
|
+
# @option options [string] ;orderId order ID
|
212
|
+
# @option options [String] :type Order types to return. Valid values include "limit", "stop_limit", "any"
|
213
|
+
# @return [Array] the list of open orders
|
214
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#getopenorders
|
215
|
+
def orders(options = {})
|
216
|
+
get :getopenorders, auth: true, params: options
|
217
|
+
end
|
218
|
+
|
219
|
+
# Retrieves current positions.
|
220
|
+
# @return [Array] the list of positions
|
221
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#positions
|
222
|
+
def positions
|
223
|
+
get :positions, auth: true
|
224
|
+
end
|
225
|
+
|
226
|
+
# Retrieves history of orders that have been partially or fully filled.
|
227
|
+
# @param options [Hash]
|
228
|
+
# @option options [String] :instrument Instrument to return open orders for
|
229
|
+
# @option options [String] :count The number of items to be returned.
|
230
|
+
# @option options [string] :offset The offset for pagination
|
231
|
+
# @return [Array] the list of history orders
|
232
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#orderhistory
|
233
|
+
def orders_history(options = {})
|
234
|
+
get :orderhistory, auth: true, params: options
|
235
|
+
end
|
236
|
+
|
237
|
+
# Retrieve order details state by order id.
|
238
|
+
# @param order_id [String] the ID of the order to be retrieved
|
239
|
+
# @return [Array] the details of the order
|
240
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#orderstate
|
241
|
+
def order(order_id)
|
242
|
+
get :orderstate, auth: true, params: { orderId: order_id }
|
243
|
+
end
|
244
|
+
|
245
|
+
# Retrieve the trade history of the account
|
246
|
+
# @param instrument [String] Either the name of the instrument, or "all" for instruments, "futures" for all futures, or "options" for all options.
|
247
|
+
# @!macro deribit.filters
|
248
|
+
# @return [Array] the list of trades
|
249
|
+
# @see https://docs.deribit.com/rpc-endpoints.html?q=#tradehistory
|
250
|
+
def trades_history(instrument = :all, filters = {})
|
251
|
+
get :tradehistory, auth: true, params: filters.merge(instrument: instrument)
|
252
|
+
end
|
253
|
+
|
254
|
+
# Retrieves announcements that have not been marked read by the current user.
|
255
|
+
# @return [Array] the list of new announcements
|
256
|
+
def new_announcements
|
257
|
+
get :newannouncements, auth: true
|
258
|
+
end
|
259
|
+
|
260
|
+
# Enables or disables "COD" (cancel on disconnect) for the current connection.
|
261
|
+
# @param state [String] Whether COD is to be enabled for this connection. "enabled" or "disabled"
|
262
|
+
def cancelondisconnect(state)
|
263
|
+
get :cancelondisconnect, auth: true, params: { state: state }
|
264
|
+
end
|
265
|
+
|
266
|
+
# Retrieves the language to be used for emails.
|
267
|
+
# @return [String] the language name (e.g. "en", "ko", "zh")
|
268
|
+
def getemaillang
|
269
|
+
get :getemaillang, auth: true
|
270
|
+
end
|
271
|
+
|
272
|
+
# Changes the language to be used for emails.
|
273
|
+
# @param lang [String] the abbreviated language name. Valid values include "en", "ko", "zh"
|
274
|
+
def setemaillang(lang)
|
275
|
+
post :setemaillang, lang: lang
|
276
|
+
end
|
277
|
+
|
278
|
+
# Marks an announcement as read, so it will not be shown in newannouncements
|
279
|
+
# @param announcement_id [String] the ID of the announcement
|
280
|
+
# @return [String] ok
|
281
|
+
def setannouncementasread(announcement_id)
|
282
|
+
post :setannouncementasread, announcementid: announcement_id
|
283
|
+
end
|
284
|
+
|
285
|
+
# Retrieves settlement, delivery and bankruptcy events that have affected your account.
|
286
|
+
# @param filters [Hash] the filters
|
287
|
+
# @option filters [String] :instrument The instrument name, or "all" to retrieve settlements for all instruments
|
288
|
+
# @option filters [Integer] :count (10) The number of entries to be returned. This is clamped to max 1000
|
289
|
+
# @option filters [String] :type The type of settlements to return. Possible values "settlement", "delivery", "bankruptcy"
|
290
|
+
# @option filters [Integer] :startTstamp The latest timestamp to return result for
|
291
|
+
# @option filters [String] :continuation Continuation token for pagination. Each response contains a token to be used for continuation
|
292
|
+
# @return [Hashie::Hash] the settlements
|
293
|
+
# @see https://docs.deribit.com/rpc-endpoints.html#settlementhistory
|
294
|
+
def settlements_history(filters = {})
|
295
|
+
get :settlementhistory, auth: true, params: filters
|
133
296
|
end
|
134
297
|
|
135
298
|
private
|
136
299
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
300
|
+
def get(action, params: {}, raw_body: false, auth: false)
|
301
|
+
response = @connection.get path(action, auth), params
|
302
|
+
# TODO: move to middleware
|
140
303
|
raise response.message unless response.success?
|
141
304
|
raise response.body.message unless response.body.success
|
142
|
-
|
143
305
|
body = response.body
|
144
306
|
raw_body ? body : body.result
|
145
307
|
end
|
308
|
+
|
309
|
+
def post(action, params)
|
310
|
+
response = @connection.post path(action, true), params
|
311
|
+
raise response.message unless response.success?
|
312
|
+
raise response.body.message unless response.body.success
|
313
|
+
response.body.result
|
314
|
+
end
|
315
|
+
|
316
|
+
def path(action, auth = false)
|
317
|
+
access = auth ? 'private' : 'public'
|
318
|
+
"/api/v1/#{access}/#{action}"
|
319
|
+
end
|
146
320
|
end
|
147
321
|
end
|
data/lib/deribit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deribit-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2019-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,34 @@ dependencies:
|
|
122
136
|
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry-doc
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: reek
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
125
167
|
- !ruby/object:Gem::Dependency
|
126
168
|
name: simplecov
|
127
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +201,7 @@ files:
|
|
159
201
|
- deribit.gemspec
|
160
202
|
- lib/deribit-api.rb
|
161
203
|
- lib/deribit.rb
|
204
|
+
- lib/deribit/authentication.rb
|
162
205
|
- lib/deribit/client.rb
|
163
206
|
- lib/deribit/version.rb
|
164
207
|
homepage: https://github.com/icostan/deribit-api-ruby
|
@@ -184,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
227
|
version: '0'
|
185
228
|
requirements: []
|
186
229
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.6
|
230
|
+
rubygems_version: 2.7.6
|
188
231
|
signing_key:
|
189
232
|
specification_version: 4
|
190
233
|
summary: Ruby library for Deribit API
|