binance-ruby 1.2 → 1.2.8

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: 8ce807af0caee4eca993399b1ae95a56a6b55af597be3d08581724d717f81d62
4
- data.tar.gz: 32668b0a998b6cad851be4ba03b0f9299721a6d8ae1a48f1eec93b674ca2d47e
3
+ metadata.gz: a7677d8d24f74b422c6060ea3950cd05ecbb92fe9740560351eb4e4bb0db89bb
4
+ data.tar.gz: 4c5cd1be93bcb44cec31ff006e720390dec12a93bf8e777f12b2a4b5bf1372fb
5
5
  SHA512:
6
- metadata.gz: 93b84cfdcf54bf21f114d6f5b11cc993dccebfa61f67b0e49c79197eefe57744d4ce448196deed94a74d025718d34f1f078c74eb0142d6ff5cf8a33179eb733f
7
- data.tar.gz: 5c0c6caf1f7d8dd8a2be8771ae8bdba8f671dc1fb425685c23dba324f4e3daa9a58269fe6b1ad17f923ab920a397e45e3b250e765ee51a4a4df4735a8cd55559
6
+ metadata.gz: 7e9eb96b126d8e16f2e443b992ef78a9b942a86b7f5b826d714458b3d5c0dec64cad208a50590929ca1b49b3907ceb8478443b85d1c6feec370c2adbff115f5f
7
+ data.tar.gz: 9fb99018e375191ca37b6a5b5c9d11034e04ca7df6c4f5f9013aa3afeb59ba3d5bad957c637910a5cc2e749eddc9131150c06d5a798ba23826855124e6099bb6
data/lib/binance-ruby.rb CHANGED
@@ -6,12 +6,13 @@ require "faye/websocket"
6
6
  require "binance/api"
7
7
  require "binance/api/account"
8
8
  require "binance/api/configuration"
9
- require "binance/api/data_stream"
10
9
  require "binance/api/error"
11
10
  require "binance/api/margin"
12
11
  require "binance/api/margin/account"
13
12
  require "binance/api/margin/order"
14
13
  require "binance/api/order"
15
14
  require "binance/api/request"
15
+ require "binance/api/trade"
16
+ require "binance/api/user_data_stream"
16
17
  require "binance/api/version"
17
18
  require "binance/websocket"
@@ -27,6 +27,23 @@ module Binance
27
27
  params: params.delete_if { |key, value| value.nil? },
28
28
  security_type: :user_data, api_key: api_key, api_secret_key: api_secret_key)
29
29
  end
30
+
31
+ # @note have not tested this for binance.us yet.
32
+ def withdraw!(coin: nil, withdrawOrderId: nil, network: nil, address: nil, addressTag: nil, amount: nil,
33
+ transactionFeeFlag: false, name: nil, recvWindow: nil, api_key: nil, api_secret_key: nil)
34
+ raise Error.new(message: "amount is required") if amount.nil?
35
+ raise Error.new(message: "coin is required") if coin.nil?
36
+ raise Error.new(message: "address is required") if address.nil?
37
+ timestamp = Configuration.timestamp
38
+ params = {
39
+ coin: coin, withdrawOrderId: withdrawOrderId, network: network, address: address, timestamp: timestamp,
40
+ addressTag: addressTag, amount: amount, transactionFeeFlag: transactionFeeFlag,
41
+ name: name, recvWindow: recvWindow,
42
+ }
43
+ Request.send!(api_key_type: :read_info, path: "/sapi/v1/capital/withdraw/apply",
44
+ params: params.delete_if { |key, value| value.nil? }, method: :post,
45
+ security_type: :user_data, api_key: api_key, api_secret_key: api_secret_key)
46
+ end
30
47
  end
31
48
  end
32
49
  end
@@ -10,8 +10,10 @@ module Binance
10
10
  raise Error.new(message: "invalid security type #{security_type}") unless security_types.include?(security_type)
11
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
- signature = signed_request_signature(params: params, api_secret_key: api_secret_key)
14
- params.merge!(signature: signature) if [:trade, :user_data].include?(security_type)
13
+ if %w(trade user_data).include?(security_type&.to_s)
14
+ signature = signed_request_signature(params: params, api_secret_key: api_secret_key)
15
+ params.merge!(signature: signature)
16
+ end
15
17
  # send() is insecure so don't use it.
16
18
  case method
17
19
  when :get
@@ -0,0 +1,27 @@
1
+ module Binance
2
+ module Api
3
+ class Trade
4
+ class << self
5
+ def get_bnb_burn_status!(recvWindow: nil, api_key: nil, api_secret_key: nil)
6
+ timestamp = Configuration.timestamp
7
+ params = { recvWindow: recvWindow, timestamp: timestamp }
8
+ Request.send!(api_key_type: :read_info, path: "/sapi/v1/bnbBurn",
9
+ params: params.delete_if { |key, value| value.nil? },
10
+ security_type: :user_data, tld: Configuration.tld, api_key: api_key,
11
+ api_secret_key: api_secret_key)
12
+ end
13
+
14
+ def toggle_bnb_burn!(spot_bnb_burn: true, interest_bnb_burn: false, recvWindow: nil, api_key: nil,
15
+ api_secret_key: nil)
16
+ timestamp = Configuration.timestamp
17
+ params = { spotBNBBurn: spot_bnb_burn, interestBNBBurn: interest_bnb_burn,
18
+ recvWindow: recvWindow, timestamp: timestamp }
19
+ Request.send!(api_key_type: :read_info, path: "/sapi/v1/bnbBurn", method: :post,
20
+ params: params.delete_if { |key, value| value.nil? },
21
+ security_type: :user_data, tld: Configuration.tld, api_key: api_key,
22
+ api_secret_key: api_secret_key)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,17 +1,18 @@
1
1
  module Binance
2
2
  module Api
3
- class DataStream
3
+ class UserDataStream
4
4
  class << self
5
5
  # It's recommended to send a ping about every 30 minutes.
6
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
- params: { listenKey: listen_key }, security_type: :user_stream)
9
+ params: { listenKey: listen_key }, security_type: :user_stream,
10
+ api_key: api_key, api_secret_key: api_secret_key)
10
11
  end
11
12
 
12
13
  def start!(api_key: nil, api_secret_key: nil)
13
14
  Request.send!(api_key_type: :none, method: :post, path: "/api/v1/userDataStream",
14
- security_type: :user_stream, api_key: api_key, api_secret_key: api_secret_key)
15
+ security_type: :user_stream, api_key: api_key, api_secret_key: api_secret_key)[:listenKey]
15
16
  end
16
17
 
17
18
  def stop!(listen_key: nil, api_key: nil, api_secret_key: nil)
@@ -1,5 +1,5 @@
1
1
  module Binance
2
2
  module Api
3
- VERSION = "1.2"
3
+ VERSION = "1.2.8"
4
4
  end
5
5
  end
@@ -1,12 +1,15 @@
1
1
  module Binance
2
2
  class WebSocket < Faye::WebSocket::Client
3
- def initialize
3
+ class Error < StandardError; end
4
+
5
+ def initialize(on_open: nil, on_close: nil)
4
6
  super "wss://stream.binance.com:9443/stream", nil, ping: 180
5
7
 
6
8
  @request_id_inc = 0
9
+ @user_stream_handlers = {}
7
10
 
8
11
  on :open do |event|
9
- p [:open]
12
+ on_open&.call(event)
10
13
  end
11
14
 
12
15
  on :message do |event|
@@ -14,7 +17,7 @@ module Binance
14
17
  end
15
18
 
16
19
  on :close do |event|
17
- p [:close, event.code, event.reason]
20
+ on_close&.call(event)
18
21
  end
19
22
  end
20
23
 
@@ -50,6 +53,11 @@ module Binance
50
53
  subscribe(symbols_fmt.map { |s| "#{s.downcase}@kline_#{interval}" })
51
54
  end
52
55
 
56
+ def user_data_stream!(listen_key, &on_receive)
57
+ @user_stream_handlers[listen_key] = on_receive
58
+ subscribe([listen_key])
59
+ end
60
+
53
61
  private
54
62
 
55
63
  def process_data(data)
@@ -62,6 +70,11 @@ module Binance
62
70
  case json[:data][:e]&.to_sym
63
71
  when :kline
64
72
  @candlesticks_handler&.call(json[:stream], json[:data])
73
+ when :outboundAccountPosition
74
+ when :balanceUpdate
75
+ when :executionReport # order update
76
+ listen_key = json[:stream]
77
+ @user_stream_handlers[listen_key]&.call(listen_key, json[:data])
65
78
  end
66
79
  end
67
80
  end
@@ -78,12 +91,15 @@ module Binance
78
91
  }.to_json)
79
92
  end
80
93
 
81
- def unsubscribe(streams)
82
- send({
83
- method: "UNSUBSCRIBE",
84
- params: streams,
85
- id: request_id,
86
- }.to_json)
87
- end
94
+ # Terminating socket connection achieves the same result.
95
+ # If you have a use-case for this, please create a GitHub issue.
96
+ #
97
+ # def unsubscribe(streams)
98
+ # send({
99
+ # method: "UNSUBSCRIBE",
100
+ # params: streams,
101
+ # id: request_id,
102
+ # }.to_json)
103
+ # end
88
104
  end
89
105
  end
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: '1.2'
4
+ version: 1.2.8
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-04-29 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -95,19 +95,19 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '12.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.11.3
103
+ version: 11.1.3
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.11.3
110
+ version: 11.1.3
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.20.0
125
- - !ruby/object:Gem::Dependency
126
- name: activesupport
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: 5.1.0
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: 5.1.0
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: awrence
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +178,20 @@ dependencies:
192
178
  - - "~>"
193
179
  - !ruby/object:Gem::Version
194
180
  version: '1.2'
181
+ - !ruby/object:Gem::Dependency
182
+ name: activesupport
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 5.1.0
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 5.1.0
195
195
  description: Ruby wrapper for the Binance API.
196
196
  email:
197
197
  - hello@jakenberg.io
@@ -203,7 +203,6 @@ files:
203
203
  - lib/binance/api.rb
204
204
  - lib/binance/api/account.rb
205
205
  - lib/binance/api/configuration.rb
206
- - lib/binance/api/data_stream.rb
207
206
  - lib/binance/api/error.rb
208
207
  - lib/binance/api/margin.rb
209
208
  - lib/binance/api/margin/account.rb
@@ -211,6 +210,8 @@ files:
211
210
  - lib/binance/api/market_stream.rb
212
211
  - lib/binance/api/order.rb
213
212
  - lib/binance/api/request.rb
213
+ - lib/binance/api/trade.rb
214
+ - lib/binance/api/user_data_stream.rb
214
215
  - lib/binance/api/version.rb
215
216
  - lib/binance/websocket.rb
216
217
  homepage: https://github.com/jakenberg/binance-ruby
@@ -236,5 +237,5 @@ requirements: []
236
237
  rubygems_version: 3.1.6
237
238
  signing_key:
238
239
  specification_version: 4
239
- summary: binance-ruby-1.2
240
+ summary: binance-ruby-1.2.8
240
241
  test_files: []