binance-ruby 0.6.4 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/binance/api.rb +24 -16
- data/lib/binance/api/account.rb +6 -6
- data/lib/binance/api/configuration.rb +3 -3
- data/lib/binance/api/data_stream.rb +6 -5
- data/lib/binance/api/margin.rb +6 -4
- data/lib/binance/api/margin/account.rb +3 -2
- data/lib/binance/api/margin/order.rb +6 -4
- data/lib/binance/api/order.rb +17 -10
- data/lib/binance/api/request.rb +8 -7
- data/lib/binance/api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e38e2e3ef1f8051d6ddda7a07dfee0e35de604ba8985861ef6041d0841e127b6
|
4
|
+
data.tar.gz: 9f147f98929be3d56108cc258c5533e9469ae153c0659faa0319358e63e0636d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c40157c4619143f0d83ab5fcfab5b63f1db7a561bbb2b5fa50dd6f2c572c7762be9bc5b81bad9824bdfb345e9ad52e9c0bad8edcb7e27474c52ff4cde473604
|
7
|
+
data.tar.gz: ef136e619f4042998197c29dc99a6072036b6169ec27843a97aeade71b7db2006ac287e9fe19d08b135bde867bd045aa788c2127683aaee8e36c039e60021067
|
data/lib/binance/api.rb
CHANGED
@@ -2,64 +2,72 @@ module Binance
|
|
2
2
|
module Api
|
3
3
|
class << self
|
4
4
|
# Valid limits:[5, 10, 20, 50, 100, 500, 1000]
|
5
|
-
def candlesticks!(endTime: nil, interval: nil, limit: 500, startTime: nil, symbol: nil)
|
5
|
+
def candlesticks!(endTime: nil, interval: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil)
|
6
6
|
raise Error.new(message: "interval is required") unless interval
|
7
7
|
raise Error.new(message: "symbol is required") unless symbol
|
8
8
|
params = { endTime: endTime, interval: interval, limit: limit, startTime: startTime, symbol: symbol }
|
9
|
-
Request.send!(api_key_type: :read_info, path: "/api/v1/klines", params: params
|
9
|
+
Request.send!(api_key_type: :read_info, path: "/api/v1/klines", params: params,
|
10
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
10
11
|
end
|
11
12
|
|
12
|
-
def compressed_aggregate_trades!(endTime: nil, fromId: nil, limit: 500, startTime: nil, symbol: nil)
|
13
|
+
def compressed_aggregate_trades!(endTime: nil, fromId: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil)
|
13
14
|
raise Error.new(message: "symbol is required") unless symbol
|
14
15
|
params = {
|
15
16
|
endTime: endTime, fromId: fromId, limit: limit, startTime: startTime, symbol: symbol,
|
16
17
|
}.delete_if { |key, value| value.nil? }
|
17
|
-
Request.send!(api_key_type: :read_info, path: "/api/v1/aggTrades", params: params
|
18
|
+
Request.send!(api_key_type: :read_info, path: "/api/v1/aggTrades", params: params,
|
19
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
18
20
|
end
|
19
21
|
|
20
|
-
def depth!(symbol: nil, limit: 100)
|
22
|
+
def depth!(symbol: nil, limit: 100, api_key: nil, api_secret_key: nil)
|
21
23
|
raise Error.new(message: "symbol is required") unless symbol
|
22
24
|
params = { limit: limit, symbol: symbol }
|
23
|
-
Request.send!(api_key_type: :read_info, path: "/api/v1/depth", params: params
|
25
|
+
Request.send!(api_key_type: :read_info, path: "/api/v1/depth", params: params,
|
26
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
24
27
|
end
|
25
28
|
|
26
|
-
def exchange_info!
|
27
|
-
Request.send!(api_key_type: :read_info, path: "/api/v1/exchangeInfo"
|
29
|
+
def exchange_info!(api_key: nil, api_secret_key: nil)
|
30
|
+
Request.send!(api_key_type: :read_info, path: "/api/v1/exchangeInfo",
|
31
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
28
32
|
end
|
29
33
|
|
30
|
-
def historical_trades!(symbol: nil, limit: 500, fromId: nil)
|
34
|
+
def historical_trades!(symbol: nil, limit: 500, fromId: nil, api_key: nil, api_secret_key: nil)
|
31
35
|
raise Error.new(message: "symbol is required") unless symbol
|
32
36
|
params = { fromId: fromId, limit: limit, symbol: symbol }
|
33
|
-
Request.send!(api_key_type: :read_info, path: "/api/v1/historicalTrades", params: params,
|
37
|
+
Request.send!(api_key_type: :read_info, path: "/api/v1/historicalTrades", params: params,
|
38
|
+
security_type: :market_data, api_key: api_key, api_secret_key: api_secret_key)
|
34
39
|
end
|
35
40
|
|
36
|
-
def info!(recvWindow: nil)
|
41
|
+
def info!(recvWindow: nil, api_key: nil, api_secret_key: nil)
|
37
42
|
timestamp = Configuration.timestamp
|
38
43
|
params = { recvWindow: recvWindow, timestamp: timestamp }.delete_if { |key, value| value.nil? }
|
39
|
-
Request.send!(api_key_type: :read_info, path: "/api/v3/account", params: params, security_type: :user_data
|
44
|
+
Request.send!(api_key_type: :read_info, path: "/api/v3/account", params: params, security_type: :user_data,
|
45
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
40
46
|
end
|
41
47
|
|
42
48
|
def ping!
|
43
49
|
Request.send!(path: "/api/v1/ping")
|
44
50
|
end
|
45
51
|
|
46
|
-
def ticker!(symbol: nil, type: nil)
|
52
|
+
def ticker!(symbol: nil, type: nil, api_key: nil, api_secret_key: nil)
|
47
53
|
ticker_type = type&.to_sym
|
48
54
|
error_message = "type must be one of: #{ticker_types.join(", ")}. #{type} was provided."
|
49
55
|
raise Error.new(message: error_message) unless ticker_types.include? ticker_type
|
50
56
|
path = ticker_path(type: ticker_type)
|
51
57
|
params = symbol ? { symbol: symbol } : {}
|
52
|
-
Request.send!(api_key_type: :read_info, path: path, params: params
|
58
|
+
Request.send!(api_key_type: :read_info, path: path, params: params,
|
59
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
53
60
|
end
|
54
61
|
|
55
62
|
def time!
|
56
63
|
Request.send!(path: "/api/v1/time")
|
57
64
|
end
|
58
65
|
|
59
|
-
def trades!(symbol: nil, limit: 500)
|
66
|
+
def trades!(symbol: nil, limit: 500, api_key: nil, api_secret_key: nil)
|
60
67
|
raise Error.new(message: "symbol is required") unless symbol
|
61
68
|
params = { limit: limit, symbol: symbol }
|
62
|
-
Request.send!(api_key_type: :read_info, path: "/api/v1/trades", params: params
|
69
|
+
Request.send!(api_key_type: :read_info, path: "/api/v1/trades", params: params,
|
70
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
63
71
|
end
|
64
72
|
|
65
73
|
private
|
data/lib/binance/api/account.rb
CHANGED
@@ -2,30 +2,30 @@ module Binance
|
|
2
2
|
module Api
|
3
3
|
class Account
|
4
4
|
class << self
|
5
|
-
def fees!(recvWindow: 5000)
|
5
|
+
def fees!(recvWindow: 5000, api_key: nil, api_secret_key: nil)
|
6
6
|
timestamp = Configuration.timestamp
|
7
7
|
params = { recvWindow: recvWindow, timestamp: timestamp }
|
8
8
|
Request.send!(api_key_type: :read_info, path: "/wapi/v3/assetDetail.html",
|
9
9
|
params: params.delete_if { |key, value| value.nil? },
|
10
|
-
|
10
|
+
security_type: :user_data, api_key: api_key, api_secret_key: api_secret_key)
|
11
11
|
end
|
12
12
|
|
13
|
-
def info!(recvWindow: 5000)
|
13
|
+
def info!(recvWindow: 5000, api_key: nil, api_secret_key: nil)
|
14
14
|
timestamp = Configuration.timestamp
|
15
15
|
params = { recvWindow: recvWindow, timestamp: timestamp }
|
16
16
|
Request.send!(api_key_type: :read_info, path: "/api/v3/account",
|
17
17
|
params: params.delete_if { |key, value| value.nil? },
|
18
|
-
security_type: :user_data)
|
18
|
+
security_type: :user_data, api_key: api_key, api_secret_key: api_secret_key)
|
19
19
|
end
|
20
20
|
|
21
|
-
def trades!(fromId: nil, limit: 500, recvWindow: 5000, symbol: nil)
|
21
|
+
def trades!(fromId: nil, limit: 500, recvWindow: 5000, symbol: nil, api_key: nil, api_secret_key: nil)
|
22
22
|
raise Error.new(message: "max limit is 500") unless limit <= 500
|
23
23
|
raise Error.new(message: "symbol is required") if symbol.nil?
|
24
24
|
timestamp = Configuration.timestamp
|
25
25
|
params = { fromId: fromId, limit: limit, recvWindow: recvWindow, symbol: symbol, timestamp: timestamp }
|
26
26
|
Request.send!(api_key_type: :read_info, path: "/api/v3/myTrades",
|
27
27
|
params: params.delete_if { |key, value| value.nil? },
|
28
|
-
security_type: :user_data)
|
28
|
+
security_type: :user_data, api_key: api_key, api_secret_key: api_secret_key)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -24,11 +24,11 @@ module Binance
|
|
24
24
|
instance_variable_get("@secret_key") || ENV["BINANCE_SECRET_KEY"]
|
25
25
|
end
|
26
26
|
|
27
|
-
def signed_request_signature(payload:)
|
27
|
+
def signed_request_signature(payload:, api_secret_key: nil)
|
28
28
|
raise Error.new(message: "environment variable 'BINANCE_SECRET_KEY' is required " \
|
29
|
-
"for signed requests.") unless secret_key
|
29
|
+
"for signed requests.") unless api_secret_key || secret_key
|
30
30
|
digest = OpenSSL::Digest::SHA256.new
|
31
|
-
OpenSSL::HMAC.hexdigest(digest, secret_key, payload)
|
31
|
+
OpenSSL::HMAC.hexdigest(digest, api_secret_key || secret_key, payload)
|
32
32
|
end
|
33
33
|
|
34
34
|
def timestamp
|
@@ -3,21 +3,22 @@ module Binance
|
|
3
3
|
class DataStream
|
4
4
|
class << self
|
5
5
|
# It's recommended to send a ping about every 30 minutes.
|
6
|
-
def keepalive!(listen_key: nil)
|
6
|
+
def keepalive!(listen_key: nil, api_key: nil, api_secret_key: nil)
|
7
7
|
raise Error.new(message: "listen_key is required") if listen_key.nil?
|
8
8
|
Request.send!(api_key_type: :none, method: :put, path: "/api/v1/userDataStream",
|
9
9
|
params: { listenKey: listen_key }, security_type: :user_stream)
|
10
10
|
end
|
11
11
|
|
12
|
-
def start!
|
12
|
+
def start!(api_key: nil, api_secret_key: nil)
|
13
13
|
Request.send!(api_key_type: :none, method: :post, path: "/api/v1/userDataStream",
|
14
|
-
security_type: :user_stream)
|
14
|
+
security_type: :user_stream, api_key: api_key, api_secret_key: api_secret_key)
|
15
15
|
end
|
16
16
|
|
17
|
-
def stop!(listen_key: nil)
|
17
|
+
def stop!(listen_key: nil, api_key: nil, api_secret_key: nil)
|
18
18
|
raise Error.new(message: "listen_key is required") if listen_key.nil?
|
19
19
|
Request.send!(api_key_type: :none, method: :delete, path: "/api/v1/userDataStream",
|
20
|
-
params: { listenKey: listen_key }, security_type: :user_stream
|
20
|
+
params: { listenKey: listen_key }, security_type: :user_stream,
|
21
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/lib/binance/api/margin.rb
CHANGED
@@ -4,7 +4,7 @@ module Binance
|
|
4
4
|
class << self
|
5
5
|
# Your Margin Wallet balance determines the amount of funds you can borrow,
|
6
6
|
# following a fixed rate of 5:1 (5x).
|
7
|
-
def borrow!(asset: nil, amount: nil, recvWindow: nil)
|
7
|
+
def borrow!(asset: nil, amount: nil, recvWindow: nil, api_key: nil, api_secret_key: nil)
|
8
8
|
timestamp = Configuration.timestamp
|
9
9
|
params = {
|
10
10
|
asset: asset, amount: amount, recvWindow: recvWindow, timestamp: timestamp,
|
@@ -12,10 +12,11 @@ module Binance
|
|
12
12
|
ensure_required_keys!(params: params)
|
13
13
|
path = "/sapi/v1/margin/loan"
|
14
14
|
Request.send!(api_key_type: :trading, method: :post, path: path,
|
15
|
-
params: params, security_type: :margin, tld: Configuration.tld
|
15
|
+
params: params, security_type: :margin, tld: Configuration.tld,
|
16
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
16
17
|
end
|
17
18
|
|
18
|
-
def repay!(asset: nil, isIsolated: nil, amount: nil, recvWindow: nil)
|
19
|
+
def repay!(asset: nil, isIsolated: nil, amount: nil, recvWindow: nil, api_key: nil, api_secret_key: nil)
|
19
20
|
timestamp = Configuration.timestamp
|
20
21
|
params = {
|
21
22
|
asset: asset, amount: amount, recvWindow: recvWindow, timestamp: timestamp,
|
@@ -23,7 +24,8 @@ module Binance
|
|
23
24
|
ensure_required_keys!(params: params)
|
24
25
|
path = "/sapi/v1/margin/repay"
|
25
26
|
Request.send!(api_key_type: :trading, method: :post, path: path,
|
26
|
-
params: params, security_type: :margin, tld: Configuration.tld
|
27
|
+
params: params, security_type: :margin, tld: Configuration.tld,
|
28
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
@@ -3,7 +3,7 @@ module Binance
|
|
3
3
|
module Margin
|
4
4
|
class Account
|
5
5
|
class << self
|
6
|
-
def transfer!(asset: nil, amount: nil, type: nil, recvWindow: nil)
|
6
|
+
def transfer!(asset: nil, amount: nil, type: nil, recvWindow: nil, api_key: nil, api_secret_key: nil)
|
7
7
|
timestamp = Configuration.timestamp
|
8
8
|
params = {
|
9
9
|
asset: asset, amount: amount, type: type, recvWindow: recvWindow, timestamp: timestamp,
|
@@ -11,7 +11,8 @@ module Binance
|
|
11
11
|
ensure_required_create_keys!(params: params)
|
12
12
|
path = "/sapi/v1/margin/transfer"
|
13
13
|
Request.send!(api_key_type: :trading, method: :post, path: path,
|
14
|
-
params: params, security_type: :margin, tld: Configuration.tld
|
14
|
+
params: params, security_type: :margin, tld: Configuration.tld,
|
15
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -4,7 +4,7 @@ module Binance
|
|
4
4
|
class Order
|
5
5
|
class << self
|
6
6
|
def cancel!(symbol: nil, isIsolated: false, orderId: nil, origClientOrderId: nil,
|
7
|
-
newClientOrderId: nil, recvWindow: nil)
|
7
|
+
newClientOrderId: nil, recvWindow: nil, api_key: nil, api_secret_key: nil)
|
8
8
|
timestamp = Configuration.timestamp
|
9
9
|
params = {
|
10
10
|
symbol: symbol, isIsolated: isIsolated, orderId: orderId, origClientOrderId: origClientOrderId,
|
@@ -13,13 +13,14 @@ module Binance
|
|
13
13
|
ensure_required_cancel_keys!(params: params)
|
14
14
|
path = "/sapi/v1/margin/order"
|
15
15
|
Request.send!(api_key_type: :trading, method: :delete, path: path,
|
16
|
-
params: params, security_type: :margin, tld: Configuration.tld
|
16
|
+
params: params, security_type: :margin, tld: Configuration.tld,
|
17
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
17
18
|
end
|
18
19
|
|
19
20
|
def create!(symbol: nil, isIsolated: false, side: nil, type: nil, quantity: nil,
|
20
21
|
quoteOrderQty: nil, price: nil, stopPrice: nil, newClientOrderId: nil,
|
21
22
|
icebergQty: nil, newOrderRespType: nil, sideEffectType: nil, timeInForce: nil,
|
22
|
-
recvWindow: nil)
|
23
|
+
recvWindow: nil, api_key: nil, api_secret_key: nil)
|
23
24
|
timestamp = Configuration.timestamp
|
24
25
|
params = {
|
25
26
|
symbol: symbol, isIsolated: isIsolated, side: side, type: type,
|
@@ -31,7 +32,8 @@ module Binance
|
|
31
32
|
ensure_required_create_keys!(params: params)
|
32
33
|
path = "/sapi/v1/margin/order"
|
33
34
|
Request.send!(api_key_type: :trading, method: :post, path: path,
|
34
|
-
params: params, security_type: :margin, tld: Configuration.tld
|
35
|
+
params: params, security_type: :margin, tld: Configuration.tld,
|
36
|
+
api_key: api_key, api_secret_key: api_secret_key)
|
35
37
|
end
|
36
38
|
|
37
39
|
private
|
data/lib/binance/api/order.rb
CHANGED
@@ -2,25 +2,28 @@ module Binance
|
|
2
2
|
module Api
|
3
3
|
class Order
|
4
4
|
class << self
|
5
|
-
def all!(limit: 500, orderId: nil, recvWindow: 5000, symbol: nil)
|
5
|
+
def all!(limit: 500, orderId: nil, recvWindow: 5000, symbol: nil, api_key: nil, api_secret_key: nil)
|
6
6
|
raise Error.new(message: "max limit is 500") unless limit <= 500
|
7
7
|
raise Error.new(message: "symbol is required") if symbol.nil?
|
8
8
|
timestamp = Configuration.timestamp
|
9
9
|
params = { limit: limit, orderId: orderId, recvWindow: recvWindow, symbol: symbol, timestamp: timestamp }
|
10
10
|
Request.send!(api_key_type: :read_info, path: "/api/v3/allOrders",
|
11
11
|
params: params.delete_if { |key, value| value.nil? },
|
12
|
-
security_type: :user_data, tld: Configuration.tld
|
12
|
+
security_type: :user_data, tld: Configuration.tld, api_key: api_key,
|
13
|
+
api_secret_key: api_secret_key)
|
13
14
|
end
|
14
15
|
|
15
16
|
# Be careful when accessing without a symbol!
|
16
|
-
def all_open!(recvWindow: 5000, symbol: nil)
|
17
|
+
def all_open!(recvWindow: 5000, symbol: nil, api_key: nil, api_secret_key: nil)
|
17
18
|
timestamp = Configuration.timestamp
|
18
19
|
params = { recvWindow: recvWindow, symbol: symbol, timestamp: timestamp }
|
19
20
|
Request.send!(api_key_type: :read_info, path: "/api/v3/openOrders",
|
20
|
-
params: params, security_type: :user_data, tld: Configuration.tld
|
21
|
+
params: params, security_type: :user_data, tld: Configuration.tld, api_key: api_key,
|
22
|
+
api_secret_key: api_secret_key)
|
21
23
|
end
|
22
24
|
|
23
|
-
def cancel!(orderId: nil, originalClientOrderId: nil, newClientOrderId: nil, recvWindow: nil, symbol: nil
|
25
|
+
def cancel!(orderId: nil, originalClientOrderId: nil, newClientOrderId: nil, recvWindow: nil, symbol: nil,
|
26
|
+
api_key: nil, api_secret_key: nil)
|
24
27
|
raise Error.new(message: "symbol is required") if symbol.nil?
|
25
28
|
raise Error.new(message: "either orderid or originalclientorderid " \
|
26
29
|
"is required") if orderId.nil? && originalClientOrderId.nil?
|
@@ -29,12 +32,13 @@ module Binance
|
|
29
32
|
newClientOrderId: newClientOrderId, recvWindow: recvWindow,
|
30
33
|
symbol: symbol, timestamp: timestamp }.delete_if { |key, value| value.nil? }
|
31
34
|
Request.send!(api_key_type: :trading, method: :delete, path: "/api/v3/order",
|
32
|
-
params: params, security_type: :trade, tld: Configuration.tld
|
35
|
+
params: params, security_type: :trade, tld: Configuration.tld, api_key: api_key,
|
36
|
+
api_secret_key: api_secret_key)
|
33
37
|
end
|
34
38
|
|
35
39
|
def create!(icebergQuantity: nil, newClientOrderId: nil, newOrderResponseType: nil,
|
36
40
|
price: nil, quantity: nil, recvWindow: nil, stopPrice: nil, symbol: nil,
|
37
|
-
side: nil, type: nil, timeInForce: nil, test: false)
|
41
|
+
side: nil, type: nil, timeInForce: nil, test: false, api_key: nil, api_secret_key: nil)
|
38
42
|
timestamp = Configuration.timestamp
|
39
43
|
params = {
|
40
44
|
icebergQty: icebergQuantity, newClientOrderId: newClientOrderId,
|
@@ -45,10 +49,12 @@ module Binance
|
|
45
49
|
ensure_required_create_keys!(params: params)
|
46
50
|
path = "/api/v3/order#{"/test" if test}"
|
47
51
|
Request.send!(api_key_type: :trading, method: :post, path: path,
|
48
|
-
params: params, security_type: :trade, tld: Configuration.tld
|
52
|
+
params: params, security_type: :trade, tld: Configuration.tld, api_key: api_key,
|
53
|
+
api_secret_key: api_secret_key)
|
49
54
|
end
|
50
55
|
|
51
|
-
def status!(orderId: nil, originalClientOrderId: nil, recvWindow: nil, symbol: nil
|
56
|
+
def status!(orderId: nil, originalClientOrderId: nil, recvWindow: nil, symbol: nil,
|
57
|
+
api_key: nil, api_secret_key: nil)
|
52
58
|
raise Error.new(message: "symbol is required") if symbol.nil?
|
53
59
|
raise Error.new(message: "either orderid or originalclientorderid " \
|
54
60
|
"is required") if orderId.nil? && originalClientOrderId.nil?
|
@@ -58,7 +64,8 @@ module Binance
|
|
58
64
|
symbol: symbol, timestamp: timestamp,
|
59
65
|
}.delete_if { |key, value| value.nil? }
|
60
66
|
Request.send!(api_key_type: :trading, path: "/api/v3/order",
|
61
|
-
params: params, security_type: :user_data, tld: Configuration.tld
|
67
|
+
params: params, security_type: :user_data, tld: Configuration.tld, api_key: api_key,
|
68
|
+
api_secret_key: api_secret_key)
|
62
69
|
end
|
63
70
|
|
64
71
|
private
|
data/lib/binance/api/request.rb
CHANGED
@@ -3,14 +3,15 @@ module Binance
|
|
3
3
|
class Request
|
4
4
|
include HTTParty
|
5
5
|
class << self
|
6
|
-
def send!(api_key_type: :none, headers: {}, method: :get, path: "/", params: {}, security_type: :none, tld: :com)
|
6
|
+
def send!(api_key_type: :none, headers: {}, method: :get, path: "/", params: {}, security_type: :none, tld: :com, api_key: nil, api_secret_key: nil)
|
7
7
|
Configuration.validate_tld!(tld)
|
8
8
|
self.base_uri "https://api.binance.#{tld}"
|
9
9
|
|
10
10
|
raise Error.new(message: "invalid security type #{security_type}") unless security_types.include?(security_type)
|
11
|
-
all_headers = default_headers(api_key_type: api_key_type, security_type: security_type)
|
11
|
+
all_headers = default_headers(api_key_type: api_key_type, security_type: security_type, api_key: api_key)
|
12
12
|
params.delete_if { |k, v| v.nil? }
|
13
|
-
|
13
|
+
signature = signed_request_signature(params: params, api_secret_key: api_secret_key)
|
14
|
+
params.merge!(signature: signature) if [:trade, :user_data].include?(security_type)
|
14
15
|
# send() is insecure so don't use it.
|
15
16
|
case method
|
16
17
|
when :get
|
@@ -29,10 +30,10 @@ module Binance
|
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
def default_headers(api_key_type:, security_type:)
|
33
|
+
def default_headers(api_key_type:, security_type:, api_key: nil)
|
33
34
|
headers = {}
|
34
35
|
headers["Content-Type"] = "application/json; charset=utf-8"
|
35
|
-
headers["X-MBX-APIKEY"] = Configuration.api_key(type: api_key_type) unless security_type == :none
|
36
|
+
headers["X-MBX-APIKEY"] = (api_key || Configuration.api_key(type: api_key_type)) unless security_type == :none
|
36
37
|
headers
|
37
38
|
end
|
38
39
|
|
@@ -51,9 +52,9 @@ module Binance
|
|
51
52
|
[:none, :trade, :user_data, :user_stream, :market_data, :margin].freeze
|
52
53
|
end
|
53
54
|
|
54
|
-
def signed_request_signature(params:)
|
55
|
+
def signed_request_signature(params:, api_secret_key: nil)
|
55
56
|
payload = params.map { |key, value| "#{key}=#{value}" }.join("&")
|
56
|
-
Configuration.signed_request_signature(payload: payload)
|
57
|
+
Configuration.signed_request_signature(payload: payload, api_secret_key: api_secret_key)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
data/lib/binance/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binance-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Peterson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -206,5 +206,5 @@ requirements: []
|
|
206
206
|
rubygems_version: 3.0.8
|
207
207
|
signing_key:
|
208
208
|
specification_version: 4
|
209
|
-
summary: binance-ruby-0.
|
209
|
+
summary: binance-ruby-0.7
|
210
210
|
test_files: []
|