binance_client 1.4.0 → 2.0.0

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: 4b4624eac956c44c052169d1c6598f527ac24dbee062321dd23525d33cc5fea0
4
- data.tar.gz: 3cc4c5a13eedf200f51a218daf89aeb2ad4a8b49607149db8397af47b5c45c02
3
+ metadata.gz: 16763512a190393e8a071e5e0840de77416ec615e91edf8f86cc1b897ca40c4b
4
+ data.tar.gz: e30373d8442ad67cd59a43bd5e4c1c97b8bf93724d2a1d0820d02363ae7387d1
5
5
  SHA512:
6
- metadata.gz: 416797926140c8928d4db9eb322db9187d3744af4d8c0a9f5090ce1bbedc85edabd4ea2f26b9249591d329d6da01445f38a98f881d12a91d88d3f76349c3cc0f
7
- data.tar.gz: 49cec6ad29790c32623484f23ca6986f79d635d738d18da4b3fec3b8a0495696d146380fea9a77f9011930ca2c8bdb7ab2d871f4ea7e1a7efdf7ded25d6b3037
6
+ metadata.gz: a92884dc017a7a2ae3b868acd953eb7c89e95f08e537176e7298fff4112f5acb6c4582f73156fb7b4a99b9c7523b0e57a5219a423e4903ea38052f1a03ba8186
7
+ data.tar.gz: cf6a0272acc771014477ed8946a293c688a5a5679814f4f96d24cdf09fbd605843d0bfce113a2ae819f4d969f85e5331f758b72299fccbd08f32bb1c57f26672
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ 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
+ ## [1.5.0]
8
+ ### Changed
9
+ - Remove `used_weight` from responses
10
+
11
+ ### Added
12
+ - `recv_window` configuration to set `recvWindow`
13
+ - `#account` call to get the `/api/v3/account` info
14
+
15
+ ### Added
16
+ - `used_weights` to responses
17
+
7
18
  ## [1.4.0] - 2021-12-09
8
19
  ### Added
9
20
  - Add factories for use in app development
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- binance_client (1.4.0)
4
+ binance_client (2.0.0)
5
5
  activesupport
6
6
  api_client_base (~> 1.11)
7
7
  typhoeus
@@ -2,6 +2,7 @@ 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
8
  api_action :get_all
@@ -14,11 +15,18 @@ module BinanceClient
14
15
  attribute :api_key
15
16
  attribute :api_secret
16
17
  attribute :proxy
18
+ attribute :recv_window
17
19
 
18
20
  private
19
21
 
20
22
  def default_opts
21
- {host: host, api_key: api_key, api_secret: api_secret, proxy: proxy}
23
+ {
24
+ host: host,
25
+ api_key: api_key,
26
+ api_secret: api_secret,
27
+ proxy: proxy,
28
+ recv_window: recv_window,
29
+ }
22
30
  end
23
31
  end
24
32
  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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module BinanceClient
2
- VERSION = "1.4.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -2,6 +2,7 @@ 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"
5
6
  require "json"
6
7
  require "openssl"
7
8
 
@@ -23,6 +24,7 @@ require "binance_client/requests/book_ticker_request"
23
24
  require "binance_client/requests/order_book_depth_request"
24
25
  require "binance_client/requests/sub_account_assets_request"
25
26
  require "binance_client/requests/sub_account_deposit_address_request"
27
+ require "binance_client/requests/account_request"
26
28
  require "binance_client/responses/system_status_response"
27
29
  require "binance_client/responses/account_snapshot_response"
28
30
  require "binance_client/responses/get_all_response"
@@ -30,6 +32,7 @@ require "binance_client/responses/book_ticker_response"
30
32
  require "binance_client/responses/order_book_depth_response"
31
33
  require "binance_client/responses/sub_account_assets_response"
32
34
  require "binance_client/responses/sub_account_deposit_address_response"
35
+ require "binance_client/responses/account_response"
33
36
 
34
37
  module BinanceClient
35
38
  class Error < StandardError; end
@@ -42,6 +45,7 @@ module BinanceClient
42
45
  has :host, classes: String, default: DEFAULT_HOST
43
46
  has :api_key, classes: String
44
47
  has :api_secret, classes: String
48
+ has :recv_window, classes: [NilClass, Integer]
45
49
  has :proxy
46
50
  end
47
51
  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.4.0
4
+ version: 2.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-09 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_client_base
@@ -122,6 +122,7 @@ files:
122
122
  - lib/binance_client/models/deposit_address.rb
123
123
  - lib/binance_client/models/order_book.rb
124
124
  - lib/binance_client/models/order_book_entry.rb
125
+ - lib/binance_client/requests/account_request.rb
125
126
  - lib/binance_client/requests/account_snapshot_request.rb
126
127
  - lib/binance_client/requests/authenticated_base_request.rb
127
128
  - lib/binance_client/requests/base_request.rb
@@ -131,6 +132,7 @@ files:
131
132
  - lib/binance_client/requests/sub_account_assets_request.rb
132
133
  - lib/binance_client/requests/sub_account_deposit_address_request.rb
133
134
  - lib/binance_client/requests/system_status_request.rb
135
+ - lib/binance_client/responses/account_response.rb
134
136
  - lib/binance_client/responses/account_snapshot_response.rb
135
137
  - lib/binance_client/responses/base_response.rb
136
138
  - lib/binance_client/responses/book_ticker_response.rb