binance-connector-ruby 1.2.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b029d14cae7ec52f77a9f61775eba15eb33027f47983f2184e49731c5de746a
4
- data.tar.gz: 5ecb20e8b7544668b2e4306a5f70548b9e3ce92696f9111b4e4ba4f88b7e4fa4
3
+ metadata.gz: 79de67acd5f3ce04c90bd7af5a1219d351f2475da326c52dd15d31de87a5fc59
4
+ data.tar.gz: a6c937781d4becf1574fa0ae75159ef4183c5305ed71886b2a35a46d6f96726e
5
5
  SHA512:
6
- metadata.gz: 1b779f8bf2a01f165f68748c37385d3a4bf79e9e887a82f5d23c08b111b697cb2280c60c9cfe4609b5c061218f008c4b58dd81e7457e26a7f76dfbafc7f1226e
7
- data.tar.gz: 25e0a750c7db5fb5dd26889548d26aa3a3c1e96b0a13ab21898623a79c69393f1df025a4f7b0c3ea6d6ad893d197544d3e24145be6b0a1e335af28dd42a9d19b
6
+ metadata.gz: 3fe1f8765880b0fb14c08333affda07065579f272b4250b2276544a93e4e4e64cbcdcad5b818903c6ed26b8e1ae932b273c832c337ef6fd45cc26b8a6935b23f
7
+ data.tar.gz: '085799a56d01d5568f0a4cc98c709d98cba18b70d4011e512fd1e4460c52b2b408344fc5c5e54f4e11e152ff1d99ca73d80f327d5c2e25f6a236e9aacd68f37f'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0 - 2022-12-20
4
+ ### Added
5
+ - Add RSA signature
6
+ - Support Ruby 3.1
7
+
8
+ ### Changed
9
+ - Drop support of Ruby 2.5
10
+
11
+
12
+ ## 1.3.0 - 2022-07-21
13
+
14
+ ### Add
15
+ - New endpoint for Margin:
16
+ - `POST /sapi/v3/asset/getUserAsset` to get user assets.
17
+ - New endpoint for Wallet:
18
+ - `GET /sapi/v1/margin/dribblet` to query the historical information of user's margin account small-value asset conversion BNB.
19
+
20
+
3
21
  ## 1.2.0 - 2022-07-15
4
22
 
5
23
  ### Add
data/README.md CHANGED
@@ -86,6 +86,10 @@ It's recommended to pass in the `base_url` parameter, even in production as Bina
86
86
  - `https://api2.binance.com`
87
87
  - `https://api3.binance.com`
88
88
 
89
+ ### RSA Signature
90
+
91
+ Binance support both HMAC and RSA signature. Please find the example at `examples/trade/account.rb` for how to sign in both solutions.
92
+
89
93
  ### RecvWindow
90
94
 
91
95
  From Binance API, recvWindow is available for all endpoints require signature. By default, it's 5000ms.
@@ -1,13 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'openssl'
4
+ require 'base64'
5
+
3
6
  module Binance
4
7
  # Authentication response to API key and signature
5
8
  class Authentication
6
- attr_accessor :key, :secret
9
+ attr_accessor :key, :secret, :private_key, :private_key_pass_phrase
7
10
 
8
- def initialize(key, secret)
11
+ def initialize(key, secret, private_key = nil, private_key_pass_phrase = nil)
9
12
  @key = key
10
13
  @secret = secret
14
+ @private_key = private_key
15
+ @private_key_pass_phrase = private_key_pass_phrase
16
+ end
17
+
18
+ def provide_private_key?
19
+ private_key
20
+ end
21
+
22
+ def hmac_sign(data)
23
+ OpenSSL::HMAC.hexdigest(
24
+ OpenSSL::Digest.new('sha256'), secret, data
25
+ )
26
+ end
27
+
28
+ def rsa_sign(data)
29
+ pkey = OpenSSL::PKey::RSA.new(private_key, private_key_pass_phrase)
30
+ Base64.encode64(pkey.sign('SHA256', data))
11
31
  end
12
32
  end
13
33
  end
@@ -11,7 +11,7 @@ module Binance
11
11
 
12
12
  def initialize(options = {})
13
13
  @base_url = options[:base_url] || 'https://api.binance.com'
14
- @auth = Authentication.new(options[:key], options[:secret])
14
+ @auth = Authentication.new(options[:key], options[:secret], options[:private_key], options[:private_key_pass_phrase])
15
15
  @logger = options[:logger]
16
16
  @show_weight_usage = options[:show_weight_usage] || false
17
17
  @show_header = options[:show_header] || false
@@ -78,7 +78,8 @@ module Binance
78
78
  build_connection do |conn|
79
79
  conn.headers['X-MBX-APIKEY'] = @auth.key
80
80
  conn.use Timestamp
81
- conn.use Signature, @auth.secret
81
+ conn.use RSASignature, @auth if @auth.provide_private_key?
82
+ conn.use HMACSignature, @auth unless @auth.provide_private_key?
82
83
  end
83
84
  end
84
85
 
@@ -725,6 +725,19 @@ module Binance
725
725
  def get_margin_order_usage(**kwargs)
726
726
  @session.sign_request(:get, '/sapi/v1/margin/rateLimit/order', params: kwargs)
727
727
  end
728
+
729
+ # Margin Dustlog (USER_DATA)
730
+ #
731
+ # GET /sapi/v1/margin/dribblet
732
+ #
733
+ # @param kwargs [Hash]
734
+ # @option kwargs [String] :startTime
735
+ # @option kwargs [String] :endTime
736
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
737
+ # @see https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user_data
738
+ def get_margin_dust_log(**kwargs)
739
+ @session.sign_request(:get, '/sapi/v1/margin/dribblet', params: kwargs)
740
+ end
728
741
  end
729
742
  end
730
743
  end
@@ -311,6 +311,19 @@ module Binance
311
311
  def api_key_permission(**kwargs)
312
312
  @session.sign_request(:get, '/sapi/v1/account/apiRestrictions', params: kwargs)
313
313
  end
314
+
315
+ # User Asset (USER_DATA)
316
+ #
317
+ # POST /sapi/v3/asset/getUserAsset
318
+ #
319
+ # @param kwargs [Hash]
320
+ # @option kwargs [String] :asset If asset is blank, then query all positive assets user have.
321
+ # @option kwargs [Boolean] :needBtcValuation
322
+ # @option kwargs [Integer] :recvWindow The value cannot be greater than 60000
323
+ # @see https://binance-docs.github.io/apidocs/spot/en/#user-asset-user_data
324
+ def get_user_asset(**kwargs)
325
+ @session.sign_request(:post, '/sapi/v3/asset/getUserAsset', params: kwargs)
326
+ end
314
327
  end
315
328
  end
316
329
  end
@@ -1,17 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'openssl'
4
+ require 'base64'
4
5
 
5
6
  module Binance
6
7
  module Utils
7
8
  module Faraday
8
9
  module Middleware
9
- Signature = Struct.new(:app, :secret) do
10
+ HMACSignature = Struct.new(:app, :auth) do
10
11
  def call(env)
11
- hash = OpenSSL::HMAC.hexdigest(
12
- OpenSSL::Digest.new('sha256'), secret, env.url.query
13
- )
14
- env.url.query = Url.add_param(env.url.query, 'signature', hash)
12
+ env.url.query = Url.add_param(env.url.query, 'signature', auth.hmac_sign(env.url.query))
15
13
  app.call env
16
14
  end
17
15
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module Binance
7
+ module Utils
8
+ module Faraday
9
+ module Middleware
10
+ RSASignature = Struct.new(:app, :auth) do
11
+ def call(env)
12
+ env.url.query = Url.add_param(env.url.query, 'signature', auth.rsa_sign(env.url.query))
13
+ app.call env
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './middleware/timestamp'
4
- require_relative './middleware/signature'
4
+ require_relative './middleware/rsa_signature'
5
+ require_relative './middleware/hmac_signature'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binance
4
- VERSION = '1.2.0'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binance-connector-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Binance
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-15 00:00:00.000000000 Z
11
+ date: 2022-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.3'
97
97
  description: ''
98
- email:
98
+ email:
99
99
  executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
@@ -127,7 +127,8 @@ files:
127
127
  - lib/binance/spot/websocket.rb
128
128
  - lib/binance/utils/faraday/custom_params_encoder.rb
129
129
  - lib/binance/utils/faraday/middleware.rb
130
- - lib/binance/utils/faraday/middleware/signature.rb
130
+ - lib/binance/utils/faraday/middleware/hmac_signature.rb
131
+ - lib/binance/utils/faraday/middleware/rsa_signature.rb
131
132
  - lib/binance/utils/faraday/middleware/timestamp.rb
132
133
  - lib/binance/utils/url.rb
133
134
  - lib/binance/utils/validation.rb
@@ -138,7 +139,7 @@ licenses:
138
139
  - MIT
139
140
  metadata:
140
141
  rubygems_mfa_required: 'true'
141
- post_install_message:
142
+ post_install_message:
142
143
  rdoc_options: []
143
144
  require_paths:
144
145
  - lib
@@ -153,8 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  - !ruby/object:Gem::Version
154
155
  version: '0'
155
156
  requirements: []
156
- rubygems_version: 3.1.2
157
- signing_key:
157
+ rubygems_version: 3.3.3
158
+ signing_key:
158
159
  specification_version: 4
159
160
  summary: This is a lightweight library that works as a connector to the Binance public
160
161
  API.