binance_client 1.3.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +4 -1
  5. data/README.md +8 -5
  6. data/lib/binance_client/client.rb +13 -2
  7. data/lib/binance_client/factories.rb +68 -0
  8. data/lib/binance_client/models/base_model.rb +7 -0
  9. data/lib/binance_client/models/coin.rb +70 -0
  10. data/lib/binance_client/models/deposit.rb +40 -0
  11. data/lib/binance_client/models/deposit_address.rb +28 -0
  12. data/lib/binance_client/models/market.rb +58 -0
  13. data/lib/binance_client/models/market_filter.rb +25 -0
  14. data/lib/binance_client/models/network.rb +70 -0
  15. data/lib/binance_client/models/rate_limit.rb +36 -0
  16. data/lib/binance_client/requests/account_request.rb +10 -0
  17. data/lib/binance_client/requests/authenticated_base_request.rb +9 -4
  18. data/lib/binance_client/requests/{get_all_request.rb → coins_info_request.rb} +1 -1
  19. data/lib/binance_client/requests/exchange_info_request.rb +10 -0
  20. data/lib/binance_client/requests/sub_account_deposit_address_request.rb +25 -0
  21. data/lib/binance_client/requests/sub_account_deposit_history_request.rb +36 -0
  22. data/lib/binance_client/responses/account_response.rb +29 -0
  23. data/lib/binance_client/responses/base_response.rb +6 -4
  24. data/lib/binance_client/responses/coins_info_response.rb +11 -0
  25. data/lib/binance_client/responses/exchange_info_response.rb +30 -0
  26. data/lib/binance_client/responses/sub_account_deposit_address_response.rb +14 -0
  27. data/lib/binance_client/responses/sub_account_deposit_history_response.rb +11 -0
  28. data/lib/binance_client/version.rb +1 -1
  29. data/lib/binance_client.rb +21 -2
  30. metadata +20 -4
  31. 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: 52c8b1596a4976bc9b6e2743fad40d6e33d050f6a614bcb550128ce29bb97d00
4
- data.tar.gz: 2cb12b4ad491d438303a745e357793f4c2d9df97d66c05fd59226f2649e7b492
3
+ metadata.gz: d0ffbedc335b6922f76dc12d791c2e362e012408ec15d89ccbc9a601277874d2
4
+ data.tar.gz: d260ca781537671f0efa3cbefad3543f681b5d8c8616d52ceaa8f411dda02d02
5
5
  SHA512:
6
- metadata.gz: cd519eeaff647220d99d6abea75054cc1eae2fd2dea9f6733d44afb4c40977957aeb74e8720bda35f5d159fff28d4092a0bb1c6fcddc3995bdc8bb84d5a4ccda
7
- data.tar.gz: 0d4570d268372084d100619469064d6ae5f364e63b99d6c0063f6bb4b68f1b6dad84a94bccd15d1308361a7bfe72371791e2a27f5f3a97465217f200f076a931
6
+ metadata.gz: ae418449f912f5acab8efea9cb2369d221ff25477254f973e4dc87e44b54d1a4eb9b4835cb2e926af9b725a3187a974a105d1c815dd704f4b03d78e2eb61871a
7
+ data.tar.gz: 81b69e1a4cbb64e0a22459a98909f605421a6fbf9286a94a448868cf951d4004cd468e2a08a2ab2d47843b2e18d774dd1284ac6acb242ded188182799a0629a1
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
+ ## [3.0.1]
8
+ ### Fixed
9
+ - `Coin#network_list` is initialized properly
10
+ - Return decimal for the following methods of `Network`:
11
+ - `#withdraw_fee`
12
+ - `#withdraw_integer_multiple`
13
+ - `#withdraw_max`
14
+ - `#withdraw_min`
15
+
16
+ ## [3.0.0]
17
+ ### Changed
18
+ - Rename `#get_all` to `#coins_info` and give access to info via the response's `#coins` method
19
+
20
+ ### Fixed
21
+ - `Deposit#insert_time` returns `Time` and not an Integer of milliseconds
22
+
23
+ ### Added
24
+ - Add Deposit, RateLimit factories
25
+
26
+ ## [2.1.0]
27
+ ### Added
28
+ - `exchange_info` endpoint
29
+ - `sub_account_deposit_history` endpoint
30
+
31
+ ## [2.0.0]
32
+ ### Changed
33
+ - Remove `used_weight` from responses
34
+
35
+ ### Added
36
+ - `recv_window` configuration to set `recvWindow`
37
+ - `#account` call to get the `/api/v3/account` info
38
+
39
+ ### Added
40
+ - `used_weights` to responses
41
+
42
+ ## [1.4.0] - 2021-12-09
43
+ ### Added
44
+ - Add factories for use in app development
45
+ - Add `#sub_account_deposit_address`
46
+
7
47
  ## [1.3.0] - 2021-11-29
8
48
  ### Added
9
49
  - Add proxy support
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in binance_client.gemspec
4
4
  gemspec
5
5
 
6
+ gem "factory_bot"
6
7
  gem "rake", "~> 12.0"
7
8
  gem "rspec", "~> 3.0"
8
9
  gem "pry-byebug"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- binance_client (1.3.0)
4
+ binance_client (3.0.1)
5
5
  activesupport
6
6
  api_client_base (~> 1.11)
7
7
  typhoeus
@@ -37,6 +37,8 @@ GEM
37
37
  diff-lcs (1.4.4)
38
38
  ethon (0.15.0)
39
39
  ffi (>= 1.15.0)
40
+ factory_bot (6.2.0)
41
+ activesupport (>= 5.0.0)
40
42
  ffi (1.15.4)
41
43
  gem_config (0.3.2)
42
44
  hashdiff (1.0.1)
@@ -91,6 +93,7 @@ PLATFORMS
91
93
 
92
94
  DEPENDENCIES
93
95
  binance_client!
96
+ factory_bot
94
97
  pry-byebug
95
98
  rake (~> 12.0)
96
99
  rspec (~> 3.0)
data/README.md CHANGED
@@ -34,11 +34,13 @@ We provide one method per API endpoint.
34
34
  ```
35
35
  client.system_status
36
36
  client.account_snapshot
37
- client.get_all
37
+ client.coins_info
38
38
  client.book_ticker(symbol: "BTCETH")
39
39
  client.order_book_depth(symbol: "BTCUSDT", limit: 100)
40
40
  ```
41
41
 
42
+ See `spec/acceptance` for all calls.
43
+
42
44
  ## Responses
43
45
  The default representation of response data is a JSON hash
44
46
 
@@ -55,10 +57,7 @@ What you assign can be a proc -- it just needs to respond to `call` and accept t
55
57
  class DoSomethingAfterBinanceResponse
56
58
 
57
59
  def self.call(request, response)
58
- one_minute_weight = response.used_weight("1m")
59
- if one_minute_weight > 1200
60
- Rails.logger.info "Looks like we've hit the request limit!"
61
- end
60
+ response.used_weights # Ruby hash of the headers of all the possible used weights
62
61
  end
63
62
 
64
63
  end
@@ -67,6 +66,10 @@ end
67
66
  ## Development
68
67
  Edit the `config.yml.sample` with your own credentials for testing
69
68
 
69
+ ## Factories
70
+
71
+ To make testing easier in your app, `require "binance_client/factories"` to get access to factories of the models.
72
+
70
73
  ## Contributing
71
74
 
72
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/bloom-solutions/binance_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bloom-solutions/binance_client/blob/master/CODE_OF_CONDUCT.md).
@@ -2,22 +2,33 @@ module BinanceClient
2
2
  class Client
3
3
  include APIClientBase::Client.module(default_opts: :default_opts)
4
4
 
5
+ api_action :account
5
6
  api_action :system_status
6
7
  api_action :account_snapshot
7
- api_action :get_all
8
+ api_action :coins_info
9
+ api_action :exchange_info
8
10
  api_action :book_ticker
9
11
  api_action :order_book_depth
10
12
  api_action :sub_account_assets, args: [:email]
13
+ api_action :sub_account_deposit_address, args: [:email, :coin]
14
+ api_action :sub_account_deposit_history
11
15
 
12
16
  attribute :host
13
17
  attribute :api_key
14
18
  attribute :api_secret
15
19
  attribute :proxy
20
+ attribute :recv_window
16
21
 
17
22
  private
18
23
 
19
24
  def default_opts
20
- {host: host, api_key: api_key, api_secret: api_secret, proxy: proxy}
25
+ {
26
+ host: host,
27
+ api_key: api_key,
28
+ api_secret: api_secret,
29
+ proxy: proxy,
30
+ recv_window: recv_window,
31
+ }
21
32
  end
22
33
  end
23
34
  end
@@ -0,0 +1,68 @@
1
+ FactoryBot.define do
2
+
3
+ factory :binance_client_asset_balance, class: "BinanceClient::AssetBalance" do
4
+ sequence(:asset) { |n| "ASSET#{n}" }
5
+ free { rand(10_000) }
6
+ locked { rand(1_000) }
7
+
8
+ initialize_with do
9
+ new(asset: asset, free: free, locked: locked)
10
+ end
11
+ end
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
+
68
+ 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,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
@@ -0,0 +1,40 @@
1
+ module BinanceClient
2
+ class Deposit < BaseModel
3
+
4
+ METHODS = %i[
5
+ sub_account_id
6
+ address
7
+ address_tag
8
+ amount
9
+ coin
10
+ network
11
+ status
12
+ tx_id
13
+ source_address
14
+ confirm_times
15
+ insert_time
16
+ ].freeze
17
+
18
+ attr_accessor :raw_hash
19
+ attr_writer *METHODS
20
+
21
+ def initialize(**kwargs)
22
+ kwargs.each do |key, value|
23
+ self.send("#{key}=", value)
24
+ end
25
+ end
26
+
27
+ METHODS.each do |method_name|
28
+ define_method method_name do
29
+ memoize_results "@#{method_name}" do
30
+ raw_hash[method_name.to_s.camelcase(:lower)]
31
+ end
32
+ end
33
+ end
34
+
35
+ def insert_time
36
+ @insert_time ||= Time.at(raw_hash["insertTime"] / 1_000)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ module BinanceClient
2
+ class DepositAddress
3
+
4
+ def self.new_from_raw(raw_hash)
5
+ args = raw_hash.each_with_object({}) do |(k, v), h|
6
+ h[k.underscore] = v
7
+ end
8
+
9
+ self.new(**args)
10
+ end
11
+
12
+ ATTRS = [
13
+ :address,
14
+ :coin,
15
+ :tag,
16
+ :url,
17
+ ]
18
+
19
+ attr_accessor(*ATTRS)
20
+
21
+ def initialize(**kwargs)
22
+ kwargs.each do |attr, value|
23
+ self.send("#{attr}=", value)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ module BinanceClient
2
+ class Market < BaseModel
3
+
4
+ METHODS = %i[
5
+ symbol
6
+ status
7
+ base_asset
8
+ base_asset_precision
9
+ quote_asset
10
+ quote_precision
11
+ quote_asset_precision
12
+ base_commission_precision
13
+ quote_commission_precision
14
+ order_types
15
+ iceberg_allowed
16
+ oco_allowed
17
+ quote_order_qty_market_allowed
18
+ is_spot_trading_allowed
19
+ is_margin_trading_allowed
20
+ ].freeze
21
+
22
+ BOOL_MAP = {
23
+ iceberg_allowed: :iceberg_allowed?,
24
+ oco_allowed: :oco_allowed?,
25
+ quote_order_qty_market_allowed: :quote_order_qty_market_allowed?,
26
+ is_spot_trading_allowed: :spot_trading_allowed?,
27
+ is_margin_trading_allowed: :margin_trading_allowed?,
28
+ }.freeze
29
+
30
+ attr_accessor :raw_hash
31
+ attr_writer *METHODS
32
+
33
+ def initialize(**kwargs)
34
+ kwargs.each do |key, value|
35
+ self.send("#{key}=", value)
36
+ end
37
+ end
38
+
39
+ METHODS.each do |method_name|
40
+ define_method method_name do
41
+ memoize_results "@#{method_name}" do
42
+ raw_hash[method_name.to_s.camelcase(:lower)]
43
+ end
44
+ end
45
+ end
46
+
47
+ BOOL_MAP.each do |original_method_name, alias_method_name|
48
+ alias_method alias_method_name, original_method_name
49
+ end
50
+
51
+ def filters
52
+ @filters ||= raw_hash["filters"].map do |filter_hash|
53
+ MarketFilter.new(raw_hash: filter_hash)
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ module BinanceClient
2
+ class MarketFilter
3
+
4
+ attr_reader :raw_hash
5
+
6
+ def initialize(raw_hash:)
7
+ @raw_hash = raw_hash
8
+ end
9
+
10
+ def method_missing(method_name, *args)
11
+ key = method_name.to_s.camelcase(:lower)
12
+ super if raw_hash[key].nil?
13
+
14
+ self.class.define_method method_name do
15
+ value = raw_hash[method_name.to_s.camelcase(:lower)]
16
+
17
+ value = value.to_d if value =~ /^[\d\.]+$/
18
+
19
+ value
20
+ end
21
+ send(method_name)
22
+ end
23
+
24
+ end
25
+ end
@@ -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
@@ -0,0 +1,36 @@
1
+ module BinanceClient
2
+ class RateLimit < BaseModel
3
+
4
+ INTERVALS = %w[SECOND MINUTE DAY].freeze
5
+ METHODS = %i[
6
+ rate_limit_type
7
+ interval
8
+ interval_num
9
+ limit
10
+ ].freeze
11
+
12
+ attr_accessor :raw_hash
13
+ attr_writer *METHODS
14
+
15
+ def initialize(**kwargs)
16
+ kwargs.each do |key, value|
17
+ self.send("#{key}=", value)
18
+ end
19
+ end
20
+
21
+ METHODS.each do |method_name|
22
+ define_method method_name do
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
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ module BinanceClient
2
+ class AccountRequest < AuthenticatedBaseRequest
3
+ private
4
+
5
+ def path
6
+ "/api/v3/account"
7
+ end
8
+
9
+ end
10
+ end
@@ -2,11 +2,13 @@ module BinanceClient
2
2
  class AuthenticatedBaseRequest < BaseRequest
3
3
  include APIClientBase::Request.module
4
4
 
5
+ attribute :recv_window, Integer
6
+
5
7
  def signature
6
8
  OpenSSL::HMAC.hexdigest(
7
9
  OpenSSL::Digest.new("sha256"),
8
10
  api_secret,
9
- params_without_signature_with_timestamp.to_query,
11
+ params_without_signature_with_timestamp_and_recv_window.to_query,
10
12
  )
11
13
  end
12
14
 
@@ -19,11 +21,14 @@ module BinanceClient
19
21
  end
20
22
 
21
23
  def params
22
- params_without_signature_with_timestamp.merge(signature_hash).to_query
24
+ params_without_signature_with_timestamp_and_recv_window.
25
+ merge(signature_hash).to_query
23
26
  end
24
27
 
25
- def params_without_signature_with_timestamp
26
- params_without_signature.merge(timestamp: timestamp)
28
+ def params_without_signature_with_timestamp_and_recv_window
29
+ attrs_to_merge = { timestamp: timestamp }
30
+ attrs_to_merge[:recvWindow] = recv_window if recv_window.present?
31
+ params_without_signature.merge(attrs_to_merge)
27
32
  end
28
33
 
29
34
  def params_without_signature
@@ -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,10 @@
1
+ module BinanceClient
2
+ class ExchangeInfoRequest < BaseRequest
3
+ private
4
+
5
+ def path
6
+ "api/v1/exchangeInfo"
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module BinanceClient
2
+ class SubAccountDepositAddressRequest < AuthenticatedBaseRequest
3
+
4
+ attribute :email, String
5
+ attribute :coin, String
6
+ attribute :network, String
7
+
8
+ private
9
+
10
+ def path
11
+ "/sapi/v1/capital/deposit/subAddress"
12
+ end
13
+
14
+ def params_without_signature
15
+ {
16
+ email: email,
17
+ coin: coin,
18
+ network: network,
19
+ }.reject do |key, value|
20
+ value.nil?
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ module BinanceClient
2
+ class SubAccountDepositHistoryRequest < AuthenticatedBaseRequest
3
+ attribute :sub_account_id, String
4
+ attribute :start_time, DateTime
5
+ attribute :end_time, DateTime
6
+ attribute :coin, String
7
+ attribute :status, Integer
8
+ attribute :limit, Integer
9
+ attribute :offset, Integer
10
+
11
+ PARAMS = [
12
+ :sub_account_id,
13
+ :start_time,
14
+ :end_time,
15
+ :coin,
16
+ :status,
17
+ :limit,
18
+ :offset,
19
+ ].freeze
20
+
21
+ private
22
+
23
+ def path
24
+ "/sapi/v1/broker/subAccount/depositHist"
25
+ end
26
+
27
+ def params_without_signature
28
+ PARAMS.each_with_object({}) do |param, hash|
29
+ key = param.to_s.camelcase(:lower)
30
+ value = send(param)
31
+ value = value.to_i * 1_000 if value.is_a?(DateTime)
32
+ hash[key] = value
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ module BinanceClient
2
+ class AccountResponse < BaseResponse
3
+
4
+ [
5
+ :maker_commission,
6
+ :taker_commission,
7
+ :buyer_commission,
8
+ :seller_commission,
9
+ :can_trade,
10
+ :can_withdraw,
11
+ :can_deposit,
12
+ :update_time,
13
+ :account_type,
14
+ :permissions,
15
+ ].each do |method_name|
16
+ define_method method_name do
17
+ key = method_name.to_s.camelcase(:lower)
18
+ body[key]
19
+ end
20
+ end
21
+
22
+ def balances
23
+ body["balances"].map do |balance_hash|
24
+ AssetBalance.new(**balance_hash.symbolize_keys)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -4,10 +4,12 @@ module BinanceClient
4
4
 
5
5
  attribute :body, Object, lazy: true, default: :default_body
6
6
 
7
- def used_weight(interval)
8
- val = header("X-MBX-USED-WEIGHT-#{interval}")
9
- return nil if val.nil?
10
- val.to_i
7
+ def used_weights
8
+ @used_weights ||= headers.each_with_object({}) do |(key, value), hash|
9
+ next if not key.include?("USED")
10
+ next if not key.include?("WEIGHT")
11
+ hash[key] = value
12
+ end
11
13
  end
12
14
 
13
15
  def message
@@ -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,30 @@
1
+ module BinanceClient
2
+ class ExchangeInfoResponse < BaseResponse
3
+
4
+ def timezone
5
+ body["timezone"]
6
+ end
7
+
8
+ def timezone
9
+ body["timezone"]
10
+ end
11
+
12
+ def server_time
13
+ body["serverTime"]
14
+ end
15
+
16
+ def markets
17
+ @markets ||= body["symbols"].map do |market_hash|
18
+ Market.new(raw_hash: market_hash)
19
+ end
20
+ end
21
+ alias_method :symbols, :markets
22
+
23
+ def rate_limits
24
+ @rate_limits ||= body["rateLimits"].map do |rate_limit_hash|
25
+ RateLimit.new(raw_hash: rate_limit_hash)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ module BinanceClient
2
+ class SubAccountDepositAddressResponse < BaseResponse
3
+
4
+ def deposit_address
5
+ DepositAddress.new(
6
+ address: body["address"],
7
+ coin: body["coin"],
8
+ tag: body["tag"],
9
+ url: body["url"],
10
+ )
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module BinanceClient
2
+ class SubAccountDepositHistoryResponse < BaseResponse
3
+
4
+ def deposits
5
+ body.map do |deposit_hash|
6
+ Deposit.new(raw_hash: deposit_hash)
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module BinanceClient
2
- VERSION = "1.3.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -2,6 +2,9 @@ require "binance_client/version"
2
2
  require "api_client_base"
3
3
  require "active_support/core_ext/hash/indifferent_access"
4
4
  require "active_support/core_ext/object/to_query"
5
+ require "active_support/core_ext/string/inflections"
6
+ require "active_support/core_ext/date_time"
7
+ require "active_support/core_ext/integer"
5
8
  require "json"
6
9
  require "openssl"
7
10
 
@@ -11,22 +14,37 @@ require "binance_client/models/base_model"
11
14
  require "binance_client/models/order_book_entry"
12
15
  require "binance_client/models/order_book"
13
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"
22
+ require "binance_client/models/network"
23
+ require "binance_client/models/coin"
14
24
 
15
25
  require "binance_client/requests/base_request"
16
26
  require "binance_client/requests/authenticated_base_request"
17
27
  require "binance_client/responses/base_response"
18
28
  require "binance_client/requests/system_status_request"
19
29
  require "binance_client/requests/account_snapshot_request"
20
- require "binance_client/requests/get_all_request"
30
+ require "binance_client/requests/exchange_info_request"
31
+ require "binance_client/requests/coins_info_request"
21
32
  require "binance_client/requests/book_ticker_request"
22
33
  require "binance_client/requests/order_book_depth_request"
23
34
  require "binance_client/requests/sub_account_assets_request"
35
+ require "binance_client/requests/sub_account_deposit_address_request"
36
+ require "binance_client/requests/sub_account_deposit_history_request"
37
+ require "binance_client/requests/account_request"
24
38
  require "binance_client/responses/system_status_response"
25
39
  require "binance_client/responses/account_snapshot_response"
26
- require "binance_client/responses/get_all_response"
40
+ require "binance_client/responses/coins_info_response"
41
+ require "binance_client/responses/exchange_info_response"
27
42
  require "binance_client/responses/book_ticker_response"
28
43
  require "binance_client/responses/order_book_depth_response"
29
44
  require "binance_client/responses/sub_account_assets_response"
45
+ require "binance_client/responses/sub_account_deposit_address_response"
46
+ require "binance_client/responses/sub_account_deposit_history_response"
47
+ require "binance_client/responses/account_response"
30
48
 
31
49
  module BinanceClient
32
50
  class Error < StandardError; end
@@ -39,6 +57,7 @@ module BinanceClient
39
57
  has :host, classes: String, default: DEFAULT_HOST
40
58
  has :api_key, classes: String
41
59
  has :api_secret, classes: String
60
+ has :recv_window, classes: [NilClass, Integer]
42
61
  has :proxy
43
62
  end
44
63
  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: 1.3.0
4
+ version: 3.0.1
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-11-29 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_client_base
@@ -116,24 +116,40 @@ files:
116
116
  - binance_client.gemspec
117
117
  - lib/binance_client.rb
118
118
  - lib/binance_client/client.rb
119
+ - lib/binance_client/factories.rb
119
120
  - lib/binance_client/models/asset_balance.rb
120
121
  - lib/binance_client/models/base_model.rb
122
+ - lib/binance_client/models/coin.rb
123
+ - lib/binance_client/models/deposit.rb
124
+ - lib/binance_client/models/deposit_address.rb
125
+ - lib/binance_client/models/market.rb
126
+ - lib/binance_client/models/market_filter.rb
127
+ - lib/binance_client/models/network.rb
121
128
  - lib/binance_client/models/order_book.rb
122
129
  - lib/binance_client/models/order_book_entry.rb
130
+ - lib/binance_client/models/rate_limit.rb
131
+ - lib/binance_client/requests/account_request.rb
123
132
  - lib/binance_client/requests/account_snapshot_request.rb
124
133
  - lib/binance_client/requests/authenticated_base_request.rb
125
134
  - lib/binance_client/requests/base_request.rb
126
135
  - lib/binance_client/requests/book_ticker_request.rb
127
- - lib/binance_client/requests/get_all_request.rb
136
+ - lib/binance_client/requests/coins_info_request.rb
137
+ - lib/binance_client/requests/exchange_info_request.rb
128
138
  - lib/binance_client/requests/order_book_depth_request.rb
129
139
  - lib/binance_client/requests/sub_account_assets_request.rb
140
+ - lib/binance_client/requests/sub_account_deposit_address_request.rb
141
+ - lib/binance_client/requests/sub_account_deposit_history_request.rb
130
142
  - lib/binance_client/requests/system_status_request.rb
143
+ - lib/binance_client/responses/account_response.rb
131
144
  - lib/binance_client/responses/account_snapshot_response.rb
132
145
  - lib/binance_client/responses/base_response.rb
133
146
  - lib/binance_client/responses/book_ticker_response.rb
134
- - lib/binance_client/responses/get_all_response.rb
147
+ - lib/binance_client/responses/coins_info_response.rb
148
+ - lib/binance_client/responses/exchange_info_response.rb
135
149
  - lib/binance_client/responses/order_book_depth_response.rb
136
150
  - lib/binance_client/responses/sub_account_assets_response.rb
151
+ - lib/binance_client/responses/sub_account_deposit_address_response.rb
152
+ - lib/binance_client/responses/sub_account_deposit_history_response.rb
137
153
  - lib/binance_client/responses/system_status_response.rb
138
154
  - lib/binance_client/version.rb
139
155
  homepage: https://github.com/bloom-solutions/binance_client-ruby
@@ -1,4 +0,0 @@
1
- module BinanceClient
2
- class GetAllResponse < BaseResponse
3
- end
4
- end