binance-connector-ruby 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +4 -0
- data/lib/binance/authentication.rb +22 -2
- data/lib/binance/session.rb +3 -2
- data/lib/binance/utils/faraday/middleware/{signature.rb → hmac_signature.rb} +3 -5
- data/lib/binance/utils/faraday/middleware/rsa_signature.rb +19 -0
- data/lib/binance/utils/faraday/middleware.rb +2 -1
- data/lib/binance/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79de67acd5f3ce04c90bd7af5a1219d351f2475da326c52dd15d31de87a5fc59
|
4
|
+
data.tar.gz: a6c937781d4becf1574fa0ae75159ef4183c5305ed71886b2a35a46d6f96726e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fe1f8765880b0fb14c08333affda07065579f272b4250b2276544a93e4e4e64cbcdcad5b818903c6ed26b8e1ae932b273c832c337ef6fd45cc26b8a6935b23f
|
7
|
+
data.tar.gz: '085799a56d01d5568f0a4cc98c709d98cba18b70d4011e512fd1e4460c52b2b408344fc5c5e54f4e11e152ff1d99ca73d80f327d5c2e25f6a236e9aacd68f37f'
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/binance/session.rb
CHANGED
@@ -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
|
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
|
|
@@ -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
|
-
|
10
|
+
HMACSignature = Struct.new(:app, :auth) do
|
10
11
|
def call(env)
|
11
|
-
|
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
|
data/lib/binance/version.rb
CHANGED
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Binance
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -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/
|
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
|