binance_client 2.1.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/Gemfile.lock +5 -3
  4. data/README.md +2 -2
  5. data/binance_client.gemspec +1 -0
  6. data/lib/binance_client/client.rb +13 -3
  7. data/lib/binance_client/factories.rb +55 -0
  8. data/lib/binance_client/loader.rb +44 -0
  9. data/lib/binance_client/models/base_model.rb +7 -0
  10. data/lib/binance_client/models/book_ticker.rb +26 -0
  11. data/lib/binance_client/models/coin.rb +70 -0
  12. data/lib/binance_client/models/deposit.rb +24 -7
  13. data/lib/binance_client/models/market.rb +9 -4
  14. data/lib/binance_client/models/network.rb +70 -0
  15. data/lib/binance_client/models/order_book.rb +4 -12
  16. data/lib/binance_client/models/order_fill.rb +21 -0
  17. data/lib/binance_client/models/rate_limit.rb +17 -5
  18. data/lib/binance_client/requests/base_create_order_request.rb +25 -0
  19. data/lib/binance_client/requests/book_ticker_request.rb +3 -1
  20. data/lib/binance_client/requests/{get_all_request.rb → coins_info_request.rb} +1 -1
  21. data/lib/binance_client/requests/create_order_request.rb +11 -0
  22. data/lib/binance_client/requests/create_sub_account_request.rb +19 -0
  23. data/lib/binance_client/requests/create_test_order_request.rb +11 -0
  24. data/lib/binance_client/requests/sub_account_bnb_burn_status_request.rb +15 -0
  25. data/lib/binance_client/requests/sub_account_create_api_keys_request.rb +27 -0
  26. data/lib/binance_client/requests/sub_account_set_spot_bnb_burn_request.rb +20 -0
  27. data/lib/binance_client/requests/sub_account_transfer_request.rb +29 -0
  28. data/lib/binance_client/requests/withdraw_request.rb +46 -0
  29. data/lib/binance_client/responses/base_create_order_response.rb +48 -0
  30. data/lib/binance_client/responses/base_response.rb +3 -2
  31. data/lib/binance_client/responses/book_ticker_response.rb +9 -0
  32. data/lib/binance_client/responses/coins_info_response.rb +11 -0
  33. data/lib/binance_client/responses/create_order_response.rb +5 -0
  34. data/lib/binance_client/responses/create_sub_account_response.rb +16 -0
  35. data/lib/binance_client/responses/create_test_order_response.rb +5 -0
  36. data/lib/binance_client/responses/sub_account_bnb_burn_status_response.rb +10 -0
  37. data/lib/binance_client/responses/sub_account_create_api_keys_response.rb +27 -0
  38. data/lib/binance_client/responses/sub_account_set_spot_bnb_burn_response.rb +11 -0
  39. data/lib/binance_client/responses/sub_account_transfer_response.rb +18 -0
  40. data/lib/binance_client/responses/withdraw_response.rb +13 -0
  41. data/lib/binance_client/version.rb +1 -1
  42. data/lib/binance_client.rb +2 -32
  43. metadata +41 -4
  44. data/lib/binance_client/responses/get_all_response.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92d03cdb49a0580cae0efce1cbcaf3f908994f2959473801eccfcabb46cd8c1d
4
- data.tar.gz: 8eadce8b6bdb99dad54e1e58724c65595f79a843006e13cc0c4618ee5d62bf88
3
+ metadata.gz: d50e294eccbbcabd5b1488a01cba18e55e78291d7027595f746e744fac3c47ba
4
+ data.tar.gz: e4476ae6a531184f71a36bad4c96a8c764d45f366539c355269ebd8abbf9f834
5
5
  SHA512:
6
- metadata.gz: f31e20576e0c83a044f2f59a3e4a5a8bddb0dfce7eab0a73494ef101dbfce4cefee7c3404b004bd3b1d1438f1accd155d151d819d4028405d9c36c2c10a4ab11
7
- data.tar.gz: 7f24cd955d6a8e2ca3ab560b0f45900c514f12001e49e5cfcbfd206b49b24ad7a105111dbc1f673b8831f4091d01486fe6a97922ca0ce12c9dd8116cf6635c7d
6
+ metadata.gz: 58e58894781ab8f2e1127b592d8df250bfe27000591aebc1dab2550a0f0d49ed5ec58d086641e9cdcabfc471cc5515e5b2c26c98d77c80e2b1649400a5e827b4
7
+ data.tar.gz: ace12fc8592ab5f794542bb340a15730647edf24d385c495a4638186c7a0b2533a6025bcb3d1404715a8317bffd92448e8355c56ad74ece8028b1eff0367d3e8
data/CHANGELOG.md CHANGED
@@ -4,6 +4,46 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [5.0.0] - 2022-04-06
8
+ ### Added
9
+ - `#sub_account_bnb_burn_status`
10
+ - `#sub_account_set_spot_bnb_burn`
11
+ - `#sub_account_transfer`
12
+ - `#sub_account_create_api_keys`
13
+ - `#create_test_order`
14
+ - `#create_order`
15
+ - `#withdraw`
16
+
17
+ ### Changed
18
+ - `Deposit#sub_account_id` is an Integer and no longer a String. Consistent with sub_account_id everywhere else
19
+ - `#book_ticker`
20
+ - accepts symbol as only arg or no args
21
+ - response has `#book_tickers` that is used to access tickers whether or not a symbol was passed in
22
+
23
+ ## [4.0.0]
24
+ ### Added
25
+ - Add optional `network` parameter when getting deposit address of a specific network
26
+ - Use keyword arguments when calling `sub_account_deposit_address`
27
+
28
+ ## [3.0.1]
29
+ ### Fixed
30
+ - `Coin#network_list` is initialized properly
31
+ - Return decimal for the following methods of `Network`:
32
+ - `#withdraw_fee`
33
+ - `#withdraw_integer_multiple`
34
+ - `#withdraw_max`
35
+ - `#withdraw_min`
36
+
37
+ ## [3.0.0]
38
+ ### Changed
39
+ - Rename `#get_all` to `#coins_info` and give access to info via the response's `#coins` method
40
+
41
+ ### Fixed
42
+ - `Deposit#insert_time` returns `Time` and not an Integer of milliseconds
43
+
44
+ ### Added
45
+ - Add Deposit, RateLimit factories
46
+
7
47
  ## [2.1.0]
8
48
  ### Added
9
49
  - `exchange_info` endpoint
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- binance_client (2.1.0)
4
+ binance_client (5.0.0)
5
5
  activesupport
6
6
  api_client_base (~> 1.11)
7
7
  typhoeus
@@ -39,7 +39,7 @@ GEM
39
39
  ffi (>= 1.15.0)
40
40
  factory_bot (6.2.0)
41
41
  activesupport (>= 5.0.0)
42
- ffi (1.15.4)
42
+ ffi (1.15.5)
43
43
  gem_config (0.3.2)
44
44
  hashdiff (1.0.1)
45
45
  i18n (1.8.11)
@@ -82,6 +82,7 @@ GEM
82
82
  axiom-types (~> 0.1)
83
83
  coercible (~> 1.0)
84
84
  descendants_tracker (~> 0.0, >= 0.0.3)
85
+ wait (0.5.3)
85
86
  webmock (3.9.1)
86
87
  addressable (>= 2.3.6)
87
88
  crack (>= 0.3.2)
@@ -99,7 +100,8 @@ DEPENDENCIES
99
100
  rspec (~> 3.0)
100
101
  rspec-its
101
102
  vcr
103
+ wait
102
104
  webmock
103
105
 
104
106
  BUNDLED WITH
105
- 2.2.28
107
+ 2.2.29
data/README.md CHANGED
@@ -34,8 +34,8 @@ We provide one method per API endpoint.
34
34
  ```
35
35
  client.system_status
36
36
  client.account_snapshot
37
- client.get_all
38
- client.book_ticker(symbol: "BTCETH")
37
+ client.coins_info
38
+ client.book_ticker("BTCETH")
39
39
  client.order_book_depth(symbol: "BTCUSDT", limit: 100)
40
40
  ```
41
41
 
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "vcr"
33
33
  spec.add_development_dependency "webmock"
34
34
  spec.add_development_dependency "rspec-its"
35
+ spec.add_development_dependency "wait"
35
36
  end
@@ -5,13 +5,23 @@ module BinanceClient
5
5
  api_action :account
6
6
  api_action :system_status
7
7
  api_action :account_snapshot
8
- api_action :get_all
8
+ api_action :coins_info
9
9
  api_action :exchange_info
10
- api_action :book_ticker
10
+ api_action :book_ticker, args: [:symbol]
11
11
  api_action :order_book_depth
12
12
  api_action :sub_account_assets, args: [:email]
13
- api_action :sub_account_deposit_address, args: [:email, :coin]
13
+ api_action :sub_account_deposit_address
14
14
  api_action :sub_account_deposit_history
15
+ api_action :sub_account_bnb_burn_status, args: [:sub_account_id]
16
+ api_action(:sub_account_set_spot_bnb_burn, {
17
+ args: [:sub_account_id, :spot_bnb_burn_status],
18
+ })
19
+ api_action :create_sub_account
20
+ api_action :sub_account_transfer
21
+ api_action :sub_account_create_api_keys
22
+ api_action :create_test_order
23
+ api_action :create_order
24
+ api_action :withdraw
15
25
 
16
26
  attribute :host
17
27
  attribute :api_key
@@ -10,4 +10,59 @@ FactoryBot.define do
10
10
  end
11
11
  end
12
12
 
13
+ factory :binance_client_deposit, class: "BinanceClient::Deposit" do
14
+ sequence(:sub_account_id) { |n| n.to_s }
15
+ sequence(:address) { |n| "address#{n}" }
16
+ sequence(:address_tag) { |n| "address_tag#{n}" }
17
+ sequence(:amount) { |n| n * 10 }
18
+ sequence(:coin) { |n| "coin#{n}" }
19
+ sequence(:insert_time) { |n| Time.now }
20
+ sequence(:network) { |n| "network#{n}" }
21
+ sequence(:status) { |n| "status#{n}" }
22
+ sequence(:tx_id) { |n| "tx_id#{n}" }
23
+ sequence(:source_address) { |n| "source_address#{n}" }
24
+ sequence(:confirm_times) { |n| "#{n}/#{n}" }
25
+ end
26
+
27
+ factory :binance_client_rate_limit, class: "BinanceClient::RateLimit" do
28
+ rate_limit_type { "REQUEST_WEIGHT" }
29
+ interval { %w[SECOND MINUTE DAY].sample }
30
+ sequence(:interval_num) { |n| n }
31
+ sequence(:limit) { |n| n }
32
+ end
33
+
34
+ factory :binance_client_coin, class: "BinanceClient::Coin" do
35
+ sequence(:coin) { |n| "ASSET#{n}" }
36
+ sequence(:name) { |n| "Asset #{n}" }
37
+ free { 0.001 }
38
+ freeze { 0.001 }
39
+ ipoable { 0.002 }
40
+ ipoing { 0.003 }
41
+ locked { 0.004 }
42
+ storage { 0.005 }
43
+ withdrawing { 0.006 }
44
+ end
45
+
46
+ factory :binance_client_network, class: "BinanceClient::Network" do
47
+ address_regex { "^(bnb1)[0-9a-z]{38}$" }
48
+ coin { "BTC" }
49
+ deposit_desc { "Wallet Maintenance" }
50
+ deposit_enable { false }
51
+ is_default { false }
52
+ memo_regex { "^[0-9A-Za-z\\-_]{1,120}$" }
53
+ min_confirm { 1 }
54
+ name { "BEP2" }
55
+ network { "BNB" }
56
+ reset_address_status { false }
57
+ special_tips { "Both a MEMO is required" }
58
+ un_lock_confirm { 0 }
59
+ withdraw_desc { "Wallet Maintenance" }
60
+ withdraw_enable { false }
61
+ withdraw_fee { "0.00000220" }
62
+ withdraw_integer_multiple { "0.00000001" }
63
+ withdraw_max { "9999999999.99999999" }
64
+ withdraw_min { "0.00000440" }
65
+ same_address { true }
66
+ end
67
+
13
68
  end
@@ -0,0 +1,44 @@
1
+ module BinanceClient
2
+ class Loader
3
+
4
+ def self.call
5
+ self.new.call
6
+ end
7
+
8
+ def call
9
+ models
10
+ requests
11
+ responses
12
+ end
13
+
14
+ def models
15
+ require "binance_client/models/base_model"
16
+
17
+ Dir[File.join(binance_client_dir, "models/*.rb")].each do |f|
18
+ require f
19
+ end
20
+ end
21
+
22
+ def requests
23
+ require "binance_client/requests/base_request"
24
+ require "binance_client/requests/authenticated_base_request"
25
+ require "binance_client/requests/base_create_order_request"
26
+ Dir[File.join(binance_client_dir, "requests/*.rb")].each do |f|
27
+ require f
28
+ end
29
+ end
30
+
31
+ def responses
32
+ require "binance_client/responses/base_response"
33
+ require "binance_client/responses/base_create_order_response"
34
+ Dir[File.join(binance_client_dir, "responses/*.rb")].each do |f|
35
+ require f
36
+ end
37
+ end
38
+
39
+ def binance_client_dir
40
+ File.join(File.dirname(__FILE__))
41
+ end
42
+
43
+ end
44
+ end
@@ -3,5 +3,12 @@ module BinanceClient
3
3
 
4
4
  include Virtus.model
5
5
 
6
+ private
7
+
8
+ def memoize_results(key)
9
+ return instance_variable_get(key) if instance_variable_defined?(key)
10
+ instance_variable_set key, yield
11
+ end
12
+
6
13
  end
7
14
  end
@@ -0,0 +1,26 @@
1
+ module BinanceClient
2
+ class BookTicker < BaseModel
3
+
4
+ ATTRIBUTES = [
5
+ :symbol,
6
+ :bid_price,
7
+ :bid_qty,
8
+ :ask_price,
9
+ :ask_qty
10
+ ].freeze
11
+
12
+ attribute :symbol, String
13
+ attribute :bid_price, BigDecimal
14
+ attribute :bid_qty, BigDecimal
15
+ attribute :ask_price, BigDecimal
16
+ attribute :ask_qty, BigDecimal
17
+
18
+ def self.new_from_raw_hash(raw_hash)
19
+ attrs = ATTRIBUTES.each_with_object({}) do |local_attr, hash|
20
+ hash[local_attr] = raw_hash[local_attr.to_s.camelcase(:lower)]
21
+ end
22
+ self.new(attrs)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,70 @@
1
+ module BinanceClient
2
+ class Coin < BaseModel
3
+
4
+ STR_METHODS = %i[
5
+ coin
6
+ name
7
+ ].freeze
8
+
9
+ DECIMAL_METHODS = %i[
10
+ free
11
+ freeze
12
+ ipoable
13
+ ipoing
14
+ locked
15
+ storage
16
+ withdrawing
17
+ ].freeze
18
+
19
+ BOOL_MAP = {
20
+ deposit_all_enable: :deposit_all_enabled?,
21
+ is_legal_money: :legal_money?,
22
+ trading: :trading?,
23
+ withdraw_all_enable: :withdraw_all_enabled?,
24
+ }.freeze
25
+
26
+ METHODS = (STR_METHODS + DECIMAL_METHODS + BOOL_MAP.keys).freeze
27
+
28
+ attr_accessor :raw_hash
29
+ attr_writer *METHODS
30
+
31
+ def initialize(**kwargs)
32
+ kwargs.each do |key, value|
33
+ self.send("#{key}=", value)
34
+ end
35
+ end
36
+
37
+ STR_METHODS.each do |method_name|
38
+ define_method method_name do
39
+ memoize_results "@#{method_name}" do
40
+ raw_hash[method_name.to_s.camelcase(:lower)]
41
+ end
42
+ end
43
+ end
44
+
45
+ DECIMAL_METHODS.each do |method_name|
46
+ define_method method_name do
47
+ memoize_results "@#{method_name}" do
48
+ raw_hash[method_name.to_s.camelcase(:lower)].to_d
49
+ end
50
+ end
51
+ end
52
+
53
+ BOOL_MAP.each do |original_method_name, alias_method_name|
54
+ define_method original_method_name do
55
+ memoize_results "@#{original_method_name}" do
56
+ raw_hash[original_method_name.to_s.camelcase(:lower)]
57
+ end
58
+ end
59
+
60
+ alias_method alias_method_name, original_method_name
61
+ end
62
+
63
+ def network_list
64
+ @network_list ||= raw_hash["networkList"].map do |network_hash|
65
+ Network.new(raw_hash: network_hash)
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -1,31 +1,48 @@
1
1
  module BinanceClient
2
- class Deposit
2
+ class Deposit < BaseModel
3
+
4
+ attribute(:sub_account_id, Integer, {
5
+ lazy: true,
6
+ default: :default_sub_acccount_id,
7
+ })
3
8
 
4
9
  METHODS = %i[
5
- sub_account_id
6
10
  address
7
11
  address_tag
8
12
  amount
9
13
  coin
10
- insert_time
11
14
  network
12
15
  status
13
16
  tx_id
14
17
  source_address
15
18
  confirm_times
19
+ insert_time
16
20
  ].freeze
17
21
 
18
- attr_reader :raw_hash
22
+ attr_accessor :raw_hash
23
+ attr_writer *METHODS
24
+
25
+ def initialize(**kwargs)
26
+ kwargs.each do |key, value|
27
+ self.send("#{key}=", value)
28
+ end
29
+ end
19
30
 
20
- def initialize(raw_hash:)
21
- @raw_hash = raw_hash
31
+ def default_sub_acccount_id
32
+ raw_hash["subAccountId"]
22
33
  end
23
34
 
24
35
  METHODS.each do |method_name|
25
36
  define_method method_name do
26
- raw_hash[method_name.to_s.camelcase(:lower)]
37
+ memoize_results "@#{method_name}" do
38
+ raw_hash[method_name.to_s.camelcase(:lower)]
39
+ end
27
40
  end
28
41
  end
29
42
 
43
+ def insert_time
44
+ @insert_time ||= Time.at(raw_hash["insertTime"] / 1_000)
45
+ end
46
+
30
47
  end
31
48
  end
@@ -27,15 +27,20 @@ module BinanceClient
27
27
  is_margin_trading_allowed: :margin_trading_allowed?,
28
28
  }.freeze
29
29
 
30
- attr_reader :raw_hash
30
+ attr_accessor :raw_hash
31
+ attr_writer *METHODS
31
32
 
32
- def initialize(raw_hash:)
33
- @raw_hash = raw_hash
33
+ def initialize(**kwargs)
34
+ kwargs.each do |key, value|
35
+ self.send("#{key}=", value)
36
+ end
34
37
  end
35
38
 
36
39
  METHODS.each do |method_name|
37
40
  define_method method_name do
38
- raw_hash[method_name.to_s.camelcase(:lower)]
41
+ memoize_results "@#{method_name}" do
42
+ raw_hash[method_name.to_s.camelcase(:lower)]
43
+ end
39
44
  end
40
45
  end
41
46
 
@@ -0,0 +1,70 @@
1
+ module BinanceClient
2
+ class Network < BaseModel
3
+
4
+ PLAIN_METHODS = %i[
5
+ address_regex
6
+ coin
7
+ deposit_desc
8
+ memo_regex
9
+ min_confirm
10
+ name
11
+ network
12
+ special_tips
13
+ un_lock_confirm
14
+ withdraw_desc
15
+ ].freeze
16
+
17
+ DECIMAL_METHODS = %i[
18
+ withdraw_fee
19
+ withdraw_integer_multiple
20
+ withdraw_max
21
+ withdraw_min
22
+ ].freeze
23
+
24
+ BOOL_MAP = {
25
+ deposit_enable: :deposit_enabled?,
26
+ is_default: :default?,
27
+ reset_address_status: :reset_address_status?,
28
+ withdraw_enable: :withdraw_enabled?,
29
+ same_address: :same_address?
30
+ }.freeze
31
+
32
+ METHODS = (PLAIN_METHODS + DECIMAL_METHODS + BOOL_MAP.keys).freeze
33
+
34
+ attr_accessor :raw_hash
35
+ attr_writer *METHODS
36
+
37
+ def initialize(**kwargs)
38
+ kwargs.each do |key, value|
39
+ self.send("#{key}=", value)
40
+ end
41
+ end
42
+
43
+ PLAIN_METHODS.each do |method_name|
44
+ define_method method_name do
45
+ memoize_results "@#{method_name}" do
46
+ raw_hash[method_name.to_s.camelcase(:lower)]
47
+ end
48
+ end
49
+ end
50
+
51
+ DECIMAL_METHODS.each do |method_name|
52
+ define_method method_name do
53
+ memoize_results "@#{method_name}" do
54
+ raw_hash[method_name.to_s.camelcase(:lower)].to_d
55
+ end
56
+ end
57
+ end
58
+
59
+ BOOL_MAP.each do |original_method_name, alias_method_name|
60
+ define_method original_method_name do
61
+ memoize_results "@#{original_method_name}" do
62
+ raw_hash[original_method_name.to_s.camelcase(:lower)]
63
+ end
64
+ end
65
+
66
+ alias_method alias_method_name, original_method_name
67
+ end
68
+
69
+ end
70
+ end
@@ -6,25 +6,17 @@ module BinanceClient
6
6
  lazy: true,
7
7
  default: :default_last_update_id,
8
8
  })
9
- attribute(:bids, Array[BinanceClient::OrderBookEntry], {
10
- lazy: true,
11
- default: :default_bids,
12
- })
13
- attribute(:asks, Array[BinanceClient::OrderBookEntry], {
14
- lazy: true,
15
- default: :default_asks,
16
- })
17
9
 
18
10
  def default_last_update_id
19
11
  body["lastUpdateId"]
20
12
  end
21
13
 
22
- def default_bids
23
- _entries_from body["bids"]
14
+ def bids
15
+ @bids ||= _entries_from(body["bids"])
24
16
  end
25
17
 
26
- def default_asks
27
- _entries_from body["asks"]
18
+ def asks
19
+ @asks ||= _entries_from(body["asks"])
28
20
  end
29
21
 
30
22
  private
@@ -0,0 +1,21 @@
1
+ module BinanceClient
2
+ class OrderFill < BaseModel
3
+
4
+ attribute :price, BigDecimal
5
+ attribute :qty, BigDecimal
6
+ attribute :commission, BigDecimal
7
+ attribute :commission_asset, String
8
+ attribute :trade_id, Integer
9
+
10
+ def self.new_from_raw_hash(raw_hash)
11
+ self.new(
12
+ price: raw_hash["price"],
13
+ qty: raw_hash["qty"],
14
+ commission: raw_hash["commission"],
15
+ commission_asset: raw_hash["commissionAsset"],
16
+ trade_id: raw_hash["tradeId"],
17
+ )
18
+ end
19
+
20
+ end
21
+ end
@@ -1,6 +1,7 @@
1
1
  module BinanceClient
2
- class RateLimit
2
+ class RateLimit < BaseModel
3
3
 
4
+ INTERVALS = %w[SECOND MINUTE DAY].freeze
4
5
  METHODS = %i[
5
6
  rate_limit_type
6
7
  interval
@@ -8,15 +9,26 @@ module BinanceClient
8
9
  limit
9
10
  ].freeze
10
11
 
11
- attr_reader :raw_hash
12
+ attr_accessor :raw_hash
13
+ attr_writer *METHODS
12
14
 
13
- def initialize(raw_hash:)
14
- @raw_hash = raw_hash
15
+ def initialize(**kwargs)
16
+ kwargs.each do |key, value|
17
+ self.send("#{key}=", value)
18
+ end
15
19
  end
16
20
 
17
21
  METHODS.each do |method_name|
18
22
  define_method method_name do
19
- raw_hash[method_name.to_s.camelcase(:lower)]
23
+ memoize_results("@#{method_name}") do
24
+ raw_hash[method_name.to_s.camelcase(:lower)]
25
+ end
26
+ end
27
+ end
28
+
29
+ INTERVALS.each do |interval|
30
+ define_method "#{interval.downcase}?" do
31
+ interval == self.interval
20
32
  end
21
33
  end
22
34
 
@@ -0,0 +1,25 @@
1
+ module BinanceClient
2
+ class BaseCreateOrderRequest < AuthenticatedBaseRequest
3
+
4
+ attribute :symbol, String
5
+ attribute :side, String
6
+ attribute :type, String
7
+ attribute :quantity, String
8
+
9
+ private
10
+
11
+ def default_action
12
+ :post
13
+ end
14
+
15
+ def params_without_signature
16
+ {
17
+ symbol: symbol,
18
+ side: side,
19
+ type: type,
20
+ quantity: quantity,
21
+ }
22
+ end
23
+
24
+ end
25
+ end
@@ -7,7 +7,9 @@ module BinanceClient
7
7
  end
8
8
 
9
9
  def params
10
- {symbol: symbol}.to_query
10
+ {}.tap do |hash|
11
+ hash[:symbol] = symbol if symbol
12
+ end.to_query
11
13
  end
12
14
  end
13
15
  end
@@ -1,5 +1,5 @@
1
1
  module BinanceClient
2
- class GetAllRequest < AuthenticatedBaseRequest
2
+ class CoinsInfoRequest < AuthenticatedBaseRequest
3
3
  private
4
4
 
5
5
  def path
@@ -0,0 +1,11 @@
1
+ module BinanceClient
2
+ class CreateOrderRequest < BaseCreateOrderRequest
3
+
4
+ private
5
+
6
+ def path
7
+ "/api/v3/order"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module BinanceClient
2
+ class CreateSubAccountRequest < AuthenticatedBaseRequest
3
+ attribute :tag
4
+
5
+ private
6
+
7
+ def path
8
+ "/sapi/v1/broker/subAccount"
9
+ end
10
+
11
+ def default_action
12
+ :post
13
+ end
14
+
15
+ def params_without_signature
16
+ {}
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module BinanceClient
2
+ class CreateTestOrderRequest < BaseCreateOrderRequest
3
+
4
+ private
5
+
6
+ def path
7
+ "/api/v3/order/test"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module BinanceClient
2
+ class SubAccountBnbBurnStatusRequest < AuthenticatedBaseRequest
3
+ attribute :sub_account_id
4
+
5
+ private
6
+
7
+ def path
8
+ "/sapi/v1/broker/subAccount/bnbBurn/status"
9
+ end
10
+
11
+ def params_without_signature
12
+ {subAccountId: sub_account_id}
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module BinanceClient
2
+ class SubAccountCreateApiKeysRequest < AuthenticatedBaseRequest
3
+ attribute :sub_account_id
4
+ attribute :can_trade, Boolean, default: true
5
+ attribute :margin_trade, Boolean, default: false
6
+ attribute :futures_trade, Boolean, default: false
7
+
8
+ private
9
+
10
+ def path
11
+ "/sapi/v1/broker/subAccountApi"
12
+ end
13
+
14
+ def default_action
15
+ :post
16
+ end
17
+
18
+ def params_without_signature
19
+ {
20
+ subAccountId: sub_account_id,
21
+ canTrade: can_trade,
22
+ marginTrade: margin_trade,
23
+ futuresTrade: futures_trade,
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module BinanceClient
2
+ class SubAccountSetSpotBnbBurnRequest < AuthenticatedBaseRequest
3
+ attribute :sub_account_id
4
+ attribute :spot_bnb_burn_status
5
+
6
+ private
7
+
8
+ def path
9
+ "/sapi/v1/broker/subAccount/bnbBurn/spot"
10
+ end
11
+
12
+ def default_action
13
+ :post
14
+ end
15
+
16
+ def params_without_signature
17
+ {subAccountId: sub_account_id, spotBNBBurn: spot_bnb_burn_status}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module BinanceClient
2
+ class SubAccountTransferRequest < AuthenticatedBaseRequest
3
+ attribute :from_id
4
+ attribute :to_id
5
+ attribute :client_tran_id
6
+ attribute :asset
7
+ attribute :amount
8
+
9
+ private
10
+
11
+ def path
12
+ "/sapi/v1/broker/transfer"
13
+ end
14
+
15
+ def default_action
16
+ :post
17
+ end
18
+
19
+ def params_without_signature
20
+ {
21
+ fromId: from_id,
22
+ toId: to_id,
23
+ clientTranId: client_tran_id,
24
+ asset: asset,
25
+ amount: amount,
26
+ }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ module BinanceClient
2
+ class WithdrawRequest < AuthenticatedBaseRequest
3
+
4
+ attribute :coin, String
5
+ attribute :address, String
6
+ attribute :amount, Float
7
+ attribute :withdraw_order_id, String
8
+ attribute :network, String
9
+ attribute :address_tag, String
10
+ attribute :transaction_fee_flag, Boolean
11
+ attribute :name, String
12
+ attribute :wallet_type, Integer
13
+
14
+ private
15
+
16
+ def escaped_name
17
+ return nil if name.blank?
18
+ name.gsub("\s", "%20")
19
+ end
20
+
21
+ def path
22
+ "/sapi/v1/capital/withdraw/apply"
23
+ end
24
+
25
+ def default_action
26
+ :post
27
+ end
28
+
29
+ def params_without_signature
30
+ {
31
+ coin: coin,
32
+ address: address,
33
+ amount: amount,
34
+ withdrawOrderId: withdraw_order_id,
35
+ network: network,
36
+ addressTag: address_tag,
37
+ transactionFeeFlag: transaction_fee_flag,
38
+ name: escaped_name,
39
+ walletType: wallet_type,
40
+ }.reject do |key, value|
41
+ value.blank?
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ module BinanceClient
2
+ class BaseCreateOrderResponse < BaseResponse
3
+
4
+ attribute :symbol, String, lazy: true, default: :default_symbol
5
+ attribute :order_id, Integer, lazy: true, default: :default_order_id
6
+ attribute :client_order_id, String, lazy: true, default: :default_client_order_id
7
+ attribute :transact_time, Integer, lazy: true, default: :default_transact_time
8
+ attribute :price, BigDecimal, lazy: true, default: :default_price
9
+ attribute :orig_qty, BigDecimal, lazy: true, default: :default_orig_qty
10
+ attribute :executed_qty, BigDecimal, lazy: true, default: :default_executed_qty
11
+ attribute :cummulative_quote_qty, BigDecimal, lazy: true, default: :default_cummulative_quote_qty
12
+ attribute :status, String, lazy: true, default: :default_status
13
+ attribute :time_in_force, String, lazy: true, default: :default_time_in_force
14
+ attribute :type, String, lazy: true, default: :default_type
15
+ attribute :side, String, lazy: true, default: :default_side
16
+ attribute :time_in_force, String, lazy: true, default: :default_time_in_force
17
+ attribute :type, String, lazy: true, default: :default_type
18
+ attribute :side, String, lazy: true, default: :default_side
19
+
20
+ def fills
21
+ @fills ||= body["fills"].map do |fill_entry|
22
+ OrderFill.new_from_raw_hash(fill_entry)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ {
29
+ symbol: :symbol,
30
+ order_id: :orderId,
31
+ client_order_id: :clientOrderId,
32
+ transact_time: :transactTime,
33
+ price: :price,
34
+ orig_qty: :origQty,
35
+ executed_qty: :executedQty,
36
+ cummulative_quote_qty: :cummulativeQuoteQty,
37
+ status: :status,
38
+ time_in_force: :timeInForce,
39
+ type: :type,
40
+ side: :side,
41
+ }.each do |attr, remote_attr|
42
+ define_method :"default_#{attr}" do
43
+ body[remote_attr.to_s]
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -3,6 +3,7 @@ module BinanceClient
3
3
  include APIClientBase::Response.module
4
4
 
5
5
  attribute :body, Object, lazy: true, default: :default_body
6
+ attribute :message, String, lazy: true, default: :default_message
6
7
 
7
8
  def used_weights
8
9
  @used_weights ||= headers.each_with_object({}) do |(key, value), hash|
@@ -12,8 +13,8 @@ module BinanceClient
12
13
  end
13
14
  end
14
15
 
15
- def message
16
- body["message"]
16
+ def default_message
17
+ body["message"].presence || body["msg"]
17
18
  end
18
19
 
19
20
  def body_code
@@ -1,4 +1,13 @@
1
1
  module BinanceClient
2
2
  class BookTickerResponse < BaseResponse
3
+
4
+ def book_tickers
5
+ book_ticker_hashes = [body].flatten
6
+
7
+ @book_tickers ||= book_ticker_hashes.map do |book_ticker_hash|
8
+ BookTicker.new_from_raw_hash(book_ticker_hash)
9
+ end
10
+ end
11
+
3
12
  end
4
13
  end
@@ -0,0 +1,11 @@
1
+ module BinanceClient
2
+ class CoinsInfoResponse < BaseResponse
3
+
4
+ def coins
5
+ @coins ||= body.map do |coin_hash|
6
+ Coin.new(raw_hash: coin_hash)
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module BinanceClient
2
+ class CreateOrderResponse < BaseCreateOrderResponse
3
+
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module BinanceClient
2
+ class CreateSubAccountResponse < BaseResponse
3
+
4
+ attribute :sub_account_id, Integer, lazy: true, default: :default_sub_acccount_id
5
+ attribute :email, String, lazy: true, default: :default_email
6
+
7
+ def default_sub_acccount_id
8
+ body["subaccountId"]
9
+ end
10
+
11
+ def default_email
12
+ body["email"]
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module BinanceClient
2
+ class CreateTestOrderResponse < BaseCreateOrderResponse
3
+
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module BinanceClient
2
+ class SubAccountBnbBurnStatusResponse < BaseResponse
3
+
4
+ def spot_bnb_burn
5
+ !!body["spotBNBBurn"]
6
+ end
7
+ alias_method :spot_bnb_burn?, :spot_bnb_burn
8
+
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module BinanceClient
2
+ class SubAccountCreateApiKeysResponse < BaseResponse
3
+
4
+ attribute :sub_account_id, Integer, lazy: true, default: :default_sub_account_id
5
+ attribute :api_key, String, lazy: true, default: :default_api_key
6
+ attribute :secret_key, String, lazy: true, default: :default_secret_key
7
+ attribute :can_trade, Boolean, lazy: true, default: :default_can_trade
8
+ attribute :margin_trade, Boolean, lazy: true, default: :default_margin_trade
9
+ attribute :futures_trade, Boolean, lazy: true, default: :default_futures_trade
10
+
11
+ private
12
+
13
+ {
14
+ sub_account_id: :subaccountId,
15
+ api_key: :apiKey,
16
+ secret_key: :secretKey,
17
+ can_trade: :canTrade,
18
+ margin_trade: :marginTrade,
19
+ futures_trade: :futuresTrade,
20
+ }.each do |attr, remote_attr|
21
+ define_method :"default_#{attr}" do
22
+ body[remote_attr.to_s]
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module BinanceClient
2
+ class SubAccountSetSpotBnbBurnResponse < BaseResponse
3
+
4
+ def spot_bnb_burn
5
+ !!body["spotBNBBurn"]
6
+ end
7
+ alias_method :spot_bnb_burn?, :spot_bnb_burn
8
+
9
+
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module BinanceClient
2
+ class SubAccountTransferResponse < BaseResponse
3
+
4
+ attribute :txn_id, Integer, lazy: true, default: :default_txn_id
5
+ attribute :client_tran_id, String, lazy: true, default: :default_client_tran_id
6
+
7
+ private
8
+
9
+ def default_txn_id
10
+ body["txnId"]
11
+ end
12
+
13
+ def default_client_tran_id
14
+ body["clientTranId"]
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module BinanceClient
2
+ class WithdrawResponse < BaseResponse
3
+
4
+ attribute :withdrawal_id, String, lazy: true, default: :default_withdrawal_id
5
+
6
+ private
7
+
8
+ def default_withdrawal_id
9
+ body["id"]
10
+ end
11
+
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module BinanceClient
2
- VERSION = "2.1.0"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -10,39 +10,9 @@ require "openssl"
10
10
 
11
11
  require "binance_client/client"
12
12
 
13
- require "binance_client/models/base_model"
14
- require "binance_client/models/order_book_entry"
15
- require "binance_client/models/order_book"
16
- require "binance_client/models/asset_balance"
17
- require "binance_client/models/deposit_address"
18
- require "binance_client/models/market"
19
- require "binance_client/models/market_filter"
20
- require "binance_client/models/rate_limit"
21
- require "binance_client/models/deposit"
13
+ require "binance_client/loader"
22
14
 
23
- require "binance_client/requests/base_request"
24
- require "binance_client/requests/authenticated_base_request"
25
- require "binance_client/responses/base_response"
26
- require "binance_client/requests/system_status_request"
27
- require "binance_client/requests/account_snapshot_request"
28
- require "binance_client/requests/exchange_info_request"
29
- require "binance_client/requests/get_all_request"
30
- require "binance_client/requests/book_ticker_request"
31
- require "binance_client/requests/order_book_depth_request"
32
- require "binance_client/requests/sub_account_assets_request"
33
- require "binance_client/requests/sub_account_deposit_address_request"
34
- require "binance_client/requests/sub_account_deposit_history_request"
35
- require "binance_client/requests/account_request"
36
- require "binance_client/responses/system_status_response"
37
- require "binance_client/responses/account_snapshot_response"
38
- require "binance_client/responses/get_all_response"
39
- require "binance_client/responses/exchange_info_response"
40
- require "binance_client/responses/book_ticker_response"
41
- require "binance_client/responses/order_book_depth_response"
42
- require "binance_client/responses/sub_account_assets_response"
43
- require "binance_client/responses/sub_account_deposit_address_response"
44
- require "binance_client/responses/sub_account_deposit_history_response"
45
- require "binance_client/responses/account_response"
15
+ BinanceClient::Loader.()
46
16
 
47
17
  module BinanceClient
48
18
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binance_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AJ Villalobos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-22 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_client_base
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: wait
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Ruby wrapper for Binance API
98
112
  email:
99
113
  - hi@ajvillalobos.com
@@ -117,38 +131,61 @@ files:
117
131
  - lib/binance_client.rb
118
132
  - lib/binance_client/client.rb
119
133
  - lib/binance_client/factories.rb
134
+ - lib/binance_client/loader.rb
120
135
  - lib/binance_client/models/asset_balance.rb
121
136
  - lib/binance_client/models/base_model.rb
137
+ - lib/binance_client/models/book_ticker.rb
138
+ - lib/binance_client/models/coin.rb
122
139
  - lib/binance_client/models/deposit.rb
123
140
  - lib/binance_client/models/deposit_address.rb
124
141
  - lib/binance_client/models/market.rb
125
142
  - lib/binance_client/models/market_filter.rb
143
+ - lib/binance_client/models/network.rb
126
144
  - lib/binance_client/models/order_book.rb
127
145
  - lib/binance_client/models/order_book_entry.rb
146
+ - lib/binance_client/models/order_fill.rb
128
147
  - lib/binance_client/models/rate_limit.rb
129
148
  - lib/binance_client/requests/account_request.rb
130
149
  - lib/binance_client/requests/account_snapshot_request.rb
131
150
  - lib/binance_client/requests/authenticated_base_request.rb
151
+ - lib/binance_client/requests/base_create_order_request.rb
132
152
  - lib/binance_client/requests/base_request.rb
133
153
  - lib/binance_client/requests/book_ticker_request.rb
154
+ - lib/binance_client/requests/coins_info_request.rb
155
+ - lib/binance_client/requests/create_order_request.rb
156
+ - lib/binance_client/requests/create_sub_account_request.rb
157
+ - lib/binance_client/requests/create_test_order_request.rb
134
158
  - lib/binance_client/requests/exchange_info_request.rb
135
- - lib/binance_client/requests/get_all_request.rb
136
159
  - lib/binance_client/requests/order_book_depth_request.rb
137
160
  - lib/binance_client/requests/sub_account_assets_request.rb
161
+ - lib/binance_client/requests/sub_account_bnb_burn_status_request.rb
162
+ - lib/binance_client/requests/sub_account_create_api_keys_request.rb
138
163
  - lib/binance_client/requests/sub_account_deposit_address_request.rb
139
164
  - lib/binance_client/requests/sub_account_deposit_history_request.rb
165
+ - lib/binance_client/requests/sub_account_set_spot_bnb_burn_request.rb
166
+ - lib/binance_client/requests/sub_account_transfer_request.rb
140
167
  - lib/binance_client/requests/system_status_request.rb
168
+ - lib/binance_client/requests/withdraw_request.rb
141
169
  - lib/binance_client/responses/account_response.rb
142
170
  - lib/binance_client/responses/account_snapshot_response.rb
171
+ - lib/binance_client/responses/base_create_order_response.rb
143
172
  - lib/binance_client/responses/base_response.rb
144
173
  - lib/binance_client/responses/book_ticker_response.rb
174
+ - lib/binance_client/responses/coins_info_response.rb
175
+ - lib/binance_client/responses/create_order_response.rb
176
+ - lib/binance_client/responses/create_sub_account_response.rb
177
+ - lib/binance_client/responses/create_test_order_response.rb
145
178
  - lib/binance_client/responses/exchange_info_response.rb
146
- - lib/binance_client/responses/get_all_response.rb
147
179
  - lib/binance_client/responses/order_book_depth_response.rb
148
180
  - lib/binance_client/responses/sub_account_assets_response.rb
181
+ - lib/binance_client/responses/sub_account_bnb_burn_status_response.rb
182
+ - lib/binance_client/responses/sub_account_create_api_keys_response.rb
149
183
  - lib/binance_client/responses/sub_account_deposit_address_response.rb
150
184
  - lib/binance_client/responses/sub_account_deposit_history_response.rb
185
+ - lib/binance_client/responses/sub_account_set_spot_bnb_burn_response.rb
186
+ - lib/binance_client/responses/sub_account_transfer_response.rb
151
187
  - lib/binance_client/responses/system_status_response.rb
188
+ - lib/binance_client/responses/withdraw_response.rb
152
189
  - lib/binance_client/version.rb
153
190
  homepage: https://github.com/bloom-solutions/binance_client-ruby
154
191
  licenses:
@@ -1,4 +0,0 @@
1
- module BinanceClient
2
- class GetAllResponse < BaseResponse
3
- end
4
- end