deribit-v2 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a7790b08596da902bd3883104647578882ff70a36746c99b516bf58642a76f4a
4
+ data.tar.gz: e541aea336c6bccb2d5f13eb6653a54c93207540b8cc9d3eb9b2dc693b3c0e6b
5
+ SHA512:
6
+ metadata.gz: 8344c771d25d65eb00d380f9e05f8cb426068e9bfcbd6e8c8108e4b8f98f3078953826e0cfc24dbade80c6db5a0e60ade85dba837af6ff1a3b73410ff2746e9f
7
+ data.tar.gz: 5718d6307184f5816922d8a4ae259ab2aa4179d02f39f99316460639d8bd5e6e10ce496f131539023c1094a8a1608a7f9140061effdbb9a0f16c7d1cc4a31477
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /dev
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format progress
2
+ --order random
3
+ --color
4
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ group :test do
6
+ gem 'webmock'
7
+ gem 'vcr'
8
+ end
9
+
10
+ group :development do
11
+ gem 'pry'
12
+ end
13
+
14
+ gemspec
15
+
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deribit-v2 (2.0.0.beta)
5
+ websocket-client-simple (~> 0.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.6.0)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ coderay (1.1.2)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ event_emitter (0.2.6)
17
+ hashdiff (1.0.0)
18
+ method_source (0.9.2)
19
+ pry (0.12.2)
20
+ coderay (~> 1.1.0)
21
+ method_source (~> 0.9.0)
22
+ public_suffix (3.1.1)
23
+ rake (10.5.0)
24
+ rspec (3.8.0)
25
+ rspec-core (~> 3.8.0)
26
+ rspec-expectations (~> 3.8.0)
27
+ rspec-mocks (~> 3.8.0)
28
+ rspec-core (3.8.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-expectations (3.8.2)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-mocks (3.8.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-support (3.8.0)
37
+ safe_yaml (1.0.4)
38
+ vcr (5.0.0)
39
+ webmock (3.7.2)
40
+ addressable (>= 2.3.6)
41
+ crack (>= 0.3.2)
42
+ hashdiff (>= 0.4.0, < 2.0.0)
43
+ websocket (1.2.8)
44
+ websocket-client-simple (0.3.0)
45
+ event_emitter
46
+ websocket
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 1.16)
53
+ deribit-v2!
54
+ pry
55
+ rake (~> 10.0)
56
+ rspec (~> 3.0)
57
+ vcr
58
+ webmock
59
+
60
+ BUNDLED WITH
61
+ 1.17.2
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Deribit
2
+
3
+ # API Client for v2 [Deribit API](https://docs.deribit.com/v2/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'deribit-v2'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install deribit-v2
20
+
21
+ ## Usage
22
+
23
+
24
+ ### Example
25
+
26
+ ```
27
+ require 'deribit'
28
+
29
+ # main server
30
+ api = Deribit::API.new("KEY", "SECRET")
31
+ # test server
32
+ api = Deribit::API.new("KEY", "SECRET", test_server: true)
33
+
34
+ api.get_index currency: "BTC"
35
+ api.get_account_summary currency: "BTC"
36
+ ```
37
+
38
+ ### Methods
39
+
40
+ A full list of availiable methods are here:
41
+ https://docs.deribit.com/v2/
42
+
43
+ ## Websocket API
44
+
45
+ ```
46
+ require 'deribit-v2'
47
+
48
+ ws = Deribit::WS.new("KEY", "SECRET")
49
+ ws.connect
50
+
51
+ # set heartbeat to prevent disconnection
52
+ ws.set_heartbeat interval: 120
53
+
54
+ # example of request:
55
+ ws.get_account_summary currency: "BTC"
56
+
57
+ # example of subscription
58
+ ws.subscribe channels: ["deribit_price_index.btc_usd"]
59
+ ```
60
+
61
+ ### Example: custom handler for subscription events
62
+
63
+ Create inheritance class for handling WS notifications
64
+
65
+ ```
66
+ class MyHandler < Deribit::WS::Handler
67
+ # event handler
68
+ def subscription(json)
69
+ # your actions here
70
+ end
71
+ end
72
+
73
+ api = Deribit::API.new("KEY", "SECRET", handlers: [MyHandler.new])
74
+ ```
75
+
76
+
77
+ Available events you can check in the guide https://docs.deribit.com/v2/ WebSockets API section.
78
+
79
+
80
+ ## Development
81
+
82
+ 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.
83
+
84
+ 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](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/v1z4/deribit-ruby-v2. This project is intended to be a safe, welcoming space for collaboration.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "deribit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/deribit.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "deribit/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "deribit-v2"
7
+ spec.version = Deribit::VERSION
8
+ spec.authors = ["Alexander Dmitriev", "Ivan Tumanov"]
9
+ spec.email = ["alexanderdmv@gmail.com"]
10
+
11
+ spec.summary = %q{Deribit.com API v2 ruby adapter}
12
+ spec.description = %q{Deribit.com API v2 ruby adapter}
13
+ spec.homepage = "https://github.com/v1z4/deribit-ruby-v2"
14
+
15
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.16"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+
24
+ spec.add_dependency 'websocket-client-simple', '~> 0.3.0'
25
+ end
@@ -0,0 +1,116 @@
1
+ require "base64"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Deribit
6
+ class API
7
+ attr_accessor :key, :secret
8
+
9
+ def initialize(key, secret, test_server: false)
10
+ @key = key
11
+ @secret = secret
12
+ @server = set_server_uri(test_server)
13
+ end
14
+
15
+ # For direct calls like `deribit.get_account_summary`
16
+ # Trying to find API method in Deribit::REST_METHODS
17
+ def method_missing(name, **params, &block)
18
+ method = Deribit.find_method(name, params)
19
+ send(method[:path], params)
20
+ end
21
+
22
+ def get_token
23
+ return @token if @token
24
+
25
+ params = { grant_type: "client_credentials", client_id: key, client_secret: secret, scope: "session:default" }
26
+ result = send "public/auth", params
27
+ puts "Auth result: #{result.inspect}"
28
+
29
+ @refresh_token = result[:refresh_token]
30
+ @expires = result[:expires_in]
31
+ @token = result[:access_token]
32
+ end
33
+
34
+ def send(route, params = {})
35
+ uri = URI(@server + route.to_s)
36
+ response = get(uri, params)
37
+
38
+ if is_error_response?(response)
39
+ json = JSON.parse(response.body) rescue nil
40
+ message = "Failed for #{key}. "
41
+ message << json["error"].to_s if json
42
+
43
+ raise Error.new(code: response.code, message: message)
44
+ else
45
+ process(response)
46
+ end
47
+ end
48
+
49
+ def process(response)
50
+ json = JSON.parse(response.body, symbolize_names: true)
51
+
52
+ if json.include?(:error)
53
+ raise Error.new(message: "Failed for #{key}. " + json[:error])
54
+ elsif json.include?(:result)
55
+ json[:result]
56
+ elsif json.include?(:message)
57
+ json[:message]
58
+ else
59
+ "ok"
60
+ end
61
+ end
62
+
63
+ def generate_signature(uri, params = {})
64
+ timestamp = (Time.now.utc.to_f * 1000).to_i
65
+ nonce = rand(100000000)
66
+ http_method = "GET"
67
+ path = uri.path
68
+ path << "?" << uri.query if uri.query
69
+ body = ""
70
+ data = [timestamp, nonce, http_method, path, body, ""].join("\n")
71
+ sig = OpenSSL::HMAC.hexdigest("SHA256", secret, data)
72
+
73
+ {
74
+ signature: sig,
75
+ header: "deri-hmac-sha256 id=#{key},ts=#{timestamp},sig=#{sig},nonce=#{nonce}",
76
+ }
77
+ end
78
+
79
+ def is_error_response?(response)
80
+ response.code.to_i.yield_self { |code| code == 0 || code >= 400 }
81
+ end
82
+
83
+ private
84
+
85
+ def http(uri)
86
+ Net::HTTP.new(uri.host, uri.port).tap { |h| h.use_ssl = true }
87
+ end
88
+
89
+ def get(uri, params = {})
90
+ uri.query = URI.encode_www_form(params) if params.any?
91
+ http(uri).tap { |h| h.set_debug_output($stdout) if ENV["DEBUG"] }.
92
+ get(uri.request_uri, set_headers(uri))
93
+ end
94
+
95
+ def post(uri, params = {})
96
+ http(uri).tap { |h| h.set_debug_output($stdout) if ENV["DEBUG"] }.
97
+ post(uri.request_uri, URI.encode_www_form(params), set_headers(uri, params))
98
+ end
99
+
100
+ # def set_headers(uri)
101
+ # headers = { "Content-Type" => "application/json" }
102
+ # headers.merge!("Authorization" => "Bearer #{get_token}") if uri.to_s.index "private"
103
+ # end
104
+
105
+ def set_headers(uri, params = {})
106
+ headers = { "Content-Type" => "application/json" }
107
+ headers.tap do |h|
108
+ h["Authorization"] = generate_signature(uri, params)[:header] if uri.to_s.index "private"
109
+ end
110
+ end
111
+
112
+ def set_server_uri(test_server)
113
+ (test_server || ENV["DERIBIT_SERVER"] == "test") ? TEST_URL : SERVER_URL
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,24 @@
1
+ module Deribit
2
+ class Error < StandardError
3
+ attr_reader :code, :msg
4
+
5
+ def initialize(code: nil, json: {}, message: nil)
6
+ @code = code || json[:code]
7
+ @msg = message || json[:msg]
8
+ end
9
+
10
+ def inspect
11
+ message = ""
12
+ message += "(#{code}) " unless code.nil?
13
+ message += "#{msg}" unless msg.nil?
14
+ end
15
+
16
+ def message
17
+ inspect
18
+ end
19
+
20
+ def to_s
21
+ inspect
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Deribit
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ module Deribit
2
+ class WS
3
+ class BaseHandler
4
+ attr_accessor :timestamp, :ws
5
+
6
+ def initialize
7
+ update_timestamp
8
+ end
9
+
10
+ def process(json, method: nil, ws: nil)
11
+ @ws = ws
12
+
13
+ if method && self.respond_to?(method)
14
+ self.send(method, json)
15
+ else
16
+ puts "Received method #{method}: #{json}"
17
+ end
18
+
19
+ update_timestamp
20
+ end
21
+
22
+ private
23
+
24
+ def update_timestamp
25
+ @timestamp = Time.now.to_i
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ module Deribit
2
+ class WS
3
+ class Handler < BaseHandler
4
+ attr_accessor :subscriptions, :access_token
5
+
6
+ def initialize
7
+ @subscriptions = []
8
+ super
9
+ end
10
+
11
+ # test request response
12
+ def heartbeat(json)
13
+ # debug
14
+ # puts "GOT HEARTBEAT, json: #{json}"
15
+ if json.dig(:params, :type) == "test_request"
16
+ ws.send(path: "public/test")
17
+ end
18
+ end
19
+
20
+ def subscribe(json)
21
+ @subscriptions += json[:result]
22
+ end
23
+
24
+ def unsubscribe(json)
25
+ channels = json[:result]
26
+ channels.each { |ch| @subscriptions.delete(ch) }
27
+ end
28
+
29
+ def auth(json)
30
+ @access_token = json.dig(:result, :access_token)
31
+ end
32
+
33
+ def subscription(json)
34
+ channel = json.dig(:params, :channel)
35
+ data = json.dig(:params, :data)
36
+
37
+ puts "GOT subscription EVENT: #{json}"
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/deribit/ws.rb ADDED
@@ -0,0 +1,114 @@
1
+ require "websocket-client-simple"
2
+
3
+ module Deribit
4
+ class WS
5
+ attr_reader :key, :secret, :url, :socket, :ids_stack, :handlers, :subscriptions
6
+
7
+ def initialize(key = nil, secret = nil, handlers: [Handler.new], test_server: false)
8
+ @key = key
9
+ @secret = secret
10
+ @ids_stack = {}
11
+
12
+ @url = set_server_url(test_server)
13
+ @handlers = handlers
14
+ end
15
+
16
+ def connect
17
+ start_handle
18
+ sleep 0.1
19
+ auth if key && secret
20
+ handlers.each { |h| subscribe(channels: h.subscriptions.to_a) if h.subscriptions.any? }
21
+ end
22
+
23
+ def handler
24
+ handlers.find { |handler| handler.is_a?(Handler) }
25
+ end
26
+
27
+ # methods like ws.get_account_history
28
+ def method_missing(name, **params, &block)
29
+ method = Deribit.find_method(name, params)
30
+ # puts "Found method: #{method}, params = #{params}"
31
+ send(path: method[:path], params: params)
32
+ end
33
+
34
+ def close
35
+ socket.close
36
+ end
37
+
38
+ def auth
39
+ timestamp = (Time.now.utc.to_f * 1000).to_i
40
+ nonce = rand(100000000)
41
+
42
+ params = {
43
+ grant_type: "client_signature",
44
+ client_id: key,
45
+ timestamp: timestamp.to_s,
46
+ signature: generate_signature(timestamp, nonce),
47
+ data: "",
48
+ nonce: nonce.to_s,
49
+ }
50
+
51
+ send(path: "public/auth", params: params)
52
+
53
+ # todo: refactor
54
+ 30.times do |i|
55
+ handler.access_token == nil ? sleep(0.1) : return
56
+ end
57
+ end
58
+
59
+ def process_data(json)
60
+ stack_id = ids_stack[json[:id]]
61
+ method = json.fetch(:method) { stack_id&.fetch(:method, nil) }
62
+ handlers.each { |hander| hander.process(json, method: method, ws: self) }
63
+ ids_stack.delete(stack_id) if stack_id
64
+ end
65
+
66
+ private
67
+
68
+ def start_handle
69
+ @socket = WebSocket::Client::Simple.connect(url)
70
+
71
+ instance = self
72
+ @socket.on :message do |msg|
73
+ # debug:
74
+ puts "msg = #{msg}"
75
+ begin
76
+ if msg.type == :text
77
+ json = JSON.parse(msg.data, symbolize_names: true)
78
+ instance.process_data(json)
79
+ elsif msg.type == :close
80
+ # debug:
81
+ # puts "trying to connect= got close event, msg: #{msg.inspect}"
82
+ instance.connect
83
+ end
84
+ rescue StandardError => error
85
+ puts "Error #{error.class}: #{error.full_message}\nGot message: #{json.inspect}"
86
+ end
87
+ end
88
+
89
+ @socket.on(:error) { |e| puts e }
90
+ end
91
+
92
+ def send(path:, params: {})
93
+ raise Error.new(message: "Socket is not initialized") unless socket
94
+ params = {} if params == []
95
+
96
+ args = { id: Time.now.to_i, jsonrps: "2.0", method: path, params: params }
97
+ method = path.split("/").last
98
+ @ids_stack[args[:id]] = { method: method, path: path, params: params }
99
+
100
+ # puts debug:
101
+ puts "Sending: #{args}"
102
+ socket.send(args.to_json)
103
+ end
104
+
105
+ def generate_signature(timestamp, nonce, data = "")
106
+ payload = [timestamp, nonce, data].join("\n")
107
+ OpenSSL::HMAC.hexdigest("SHA256", secret, payload)
108
+ end
109
+
110
+ def set_server_url(test_server)
111
+ (ENV["DERIBIT_SERVER"].downcase == "test" || test_server) ? WS_TEST_URL : WS_SERVER_URL
112
+ end
113
+ end
114
+ end
data/lib/deribit.rb ADDED
@@ -0,0 +1,125 @@
1
+ require "deribit/version"
2
+ require "deribit/error"
3
+ require "deribit/api"
4
+ require "deribit/ws"
5
+ require "deribit/ws/base_handler"
6
+ require "deribit/ws/handler"
7
+
8
+ module Deribit
9
+ API_VERSION = "v2"
10
+ SERVER_URL = "https://www.deribit.com/api/#{API_VERSION}/"
11
+ TEST_URL = "https://test.deribit.com/api/#{API_VERSION}/"
12
+ WS_SERVER_URL = "wss://www.deribit.com/ws/api/#{API_VERSION}/"
13
+ WS_TEST_URL = "wss://test.deribit.com/ws/api/#{API_VERSION}/"
14
+
15
+ API_METHODS = {
16
+ "private/add_to_address_book" => %i(currency type address name tfa),
17
+ "private/buy" => %i(instrument_name amount type label price time_in_force max_show post_only reduce_only stop_price trigger advanced),
18
+ "private/cancel" => %i(order_id),
19
+ "private/cancel_all" => [],
20
+ "private/cancel_all_by_currency" => %i(currency kind type),
21
+ "private/cancel_all_by_instrument" => %i(instrument_name type),
22
+ "private/cancel_transfer_by_id" => %i(currency id tfa),
23
+ "private/cancel_withdrawal" => %i(currency id),
24
+ "private/change_subaccount_name" => %i(sid name),
25
+ "private/close_position" => %i(instrument_name type price),
26
+ "private/create_deposit_address" => %i(currency),
27
+ "private/create_subaccount" => [],
28
+ "private/disable_tfa_for_subaccount" => %i(sid),
29
+ "private/edit" => %i(order_id amount price post_only advanced stop_price),
30
+ "private/get_account_summary" => %i(currency extended),
31
+ "private/get_address_book" => %i(currency type),
32
+ "private/get_current_deposit_address" => %i(currency),
33
+ "private/get_deposits" => %i(currency count offset),
34
+ "private/get_email_language" => [],
35
+ "private/get_margins" => %i(instrument_name amount price),
36
+ "private/get_new_announcements" => [],
37
+ "private/get_open_orders_by_currency" => %i(currency kind type),
38
+ "private/get_open_orders_by_instrument" => %i(instrument_name type),
39
+ "private/get_order_history_by_currency" => %i(currency kind count offset include_old include_unfilled),
40
+ "private/get_order_history_by_instrument" => %i(instrument_name count offset include_old include_unfilled),
41
+ "private/get_order_margin_by_ids" => %i(ids),
42
+ "private/get_order_state" => %i(order_id),
43
+ "private/get_position" => %i(instrument_name),
44
+ "private/get_positions" => %i(currency kind),
45
+ "private/get_settlement_history_by_currency" => %i(currency type count),
46
+ "private/get_settlement_history_by_instrument" => %i(instrument_name type count),
47
+ "private/get_subaccounts" => %i(with_portfolio),
48
+ "private/get_transfers" => %i(currency count offset),
49
+ "private/get_user_trades_by_currency" => %i(currency kind start_id end_id count include_old sorting),
50
+ "private/get_user_trades_by_currency_and_time" => %i(currency kind start_timestamp end_timestamp count include_old sorting),
51
+ "private/get_user_trades_by_instrument" => %i(instrument_name start_seq end_seq count include_old sorting),
52
+ "private/get_user_trades_by_instrument_and_time" => %i(instrument_name start_timestamp end_timestamp count include_old sorting),
53
+ "private/get_user_trades_by_order" => %i(order_id sorting),
54
+ "private/get_withdrawals" => %i(currency count offset),
55
+ "private/getopenorders" => %i(instrument orderId type),
56
+ "private/orderhistory" => %i(count instrument offset),
57
+ "private/orderstate" => %i(orderId),
58
+ "private/positions" => %i(currency),
59
+ "private/remove_from_address_book" => %i(currency type address tfa),
60
+ "private/sell" => %i(instrument_name amount type label price time_in_force max_show post_only reduce_only stop_price trigger advanced),
61
+ "private/set_announcement_as_read" => %i(announcement_id),
62
+ "private/set_email_for_subaccount" => %i(sid email),
63
+ "private/set_email_language" => %i(language),
64
+ "private/set_password_for_subaccount" => %i(sid password),
65
+ "private/submit_transfer_to_subaccount" => %i(currency amount destination),
66
+ "private/submit_transfer_to_user" => %i(currency amount destination tfa),
67
+ "private/toggle_deposit_address_creation" => %i(currency state),
68
+ "private/toggle_notifications_from_subaccount" => %i(sid state),
69
+ "private/toggle_subaccount_login" => %i(sid state),
70
+ "private/tradehistory" => %i(sort instrument count startId endId startSeq endSeq startTimestamp endTimestamp since direction),
71
+ "private/withdraw" => %i(currency address amount priority tfa),
72
+ "public/auth" => %i(grant_type username password client_id client_secret refresh_token timestamp signature nonce state scope),
73
+ "public/get_announcements" => [],
74
+ "public/get_book_summary_by_currency" => %i(currency kind),
75
+ "public/get_book_summary_by_instrument" => %i(instrument_name),
76
+ "public/get_contract_size" => %i(instrument_name),
77
+ "public/get_currencies" => [],
78
+ "public/get_footer" => [],
79
+ "public/get_funding_chart_data" => %i(instrument_name length),
80
+ "public/get_historical_volatility" => %i(currency),
81
+ "public/get_index" => %i(currency),
82
+ "public/get_instruments" => %i(currency kind expired),
83
+ "public/get_last_settlements_by_currency" => %i(currency type count continuation search_start_timestamp),
84
+ "public/get_last_settlements_by_instrument" => %i(instrument_name type count continuation search_start_timestamp),
85
+ "public/get_last_trades_by_currency" => %i(currency kind start_seq end_seq count include_old sorting),
86
+ "public/get_last_trades_by_currency_and_time" => %i(currency kind start_timestamp end_timestamp count include_old sorting),
87
+ "public/get_last_trades_by_instrument" => %i(instrument_name start_seq end_seq count include_old sorting),
88
+ "public/get_last_trades_by_instrument_and_time" => %i(instrument_name start_timestamp end_timestamp count include_old sorting),
89
+ "public/get_option_mark_prices" => %i(currency),
90
+ "public/get_order_book" => %i(instrument_name depth),
91
+ "public/get_time" => [],
92
+ "public/get_trade_volumes" => [],
93
+ "public/getlasttrades" => %i(sort instrument count startId endId startSeq endSeq startTimestamp endTimestamp since direction),
94
+ "public/getorderbook" => %i(instrument depth),
95
+ "public/ping" => [],
96
+ "public/test" => %i(expected_result),
97
+ "public/ticker" => %i(instrument_name),
98
+ "public/validate_field" => %i(field value value2),
99
+ # === WEBSOCKETS === #
100
+ "private/enable_cancel_on_disconnect" => [],
101
+ "private/disable_cancel_on_disconnect" => [],
102
+ "private/logout" => [],
103
+ "public/hello" => %i(client_name client_version),
104
+ "public/set_heartbeat" => %i(interval),
105
+ "public/disable_heartbeat" => [],
106
+ "public/subscribe" => %i(channels),
107
+ "public/unsubscribe" => %i(channels),
108
+ }
109
+
110
+ def self.find_method(method_name, params = {})
111
+ if found = API_METHODS.find { |e| e[0].end_with?(method_name.to_s) }
112
+ { method: method_name, path: found[0], params: found[1] }.tap { |data| check_params(data, params) }
113
+ else
114
+ raise Error.new(message: "Deribit API: invalid method #{method_name}")
115
+ end
116
+ end
117
+
118
+ def self.check_params(data, params)
119
+ return true unless params.any?
120
+
121
+ params.keys.each do |key|
122
+ puts "DERIBIT-RUBY WARNING: param `#{key}` is not allowed " if key && !data[:params].include?(key)
123
+ end
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deribit-v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Dmitriev
8
+ - Ivan Tumanov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.16'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.16'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: websocket-client-simple
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.3.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.3.0
70
+ description: Deribit.com API v2 ruby adapter
71
+ email:
72
+ - alexanderdmv@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - deribit.gemspec
86
+ - lib/deribit.rb
87
+ - lib/deribit/api.rb
88
+ - lib/deribit/error.rb
89
+ - lib/deribit/version.rb
90
+ - lib/deribit/ws.rb
91
+ - lib/deribit/ws/base_handler.rb
92
+ - lib/deribit/ws/handler.rb
93
+ homepage: https://github.com/v1z4/deribit-ruby-v2
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Deribit.com API v2 ruby adapter
115
+ test_files: []