Class: Binance::Api::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/binance/api/configuration.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_key(type: nil) ⇒ Object

Raises:



11
12
13
14
# File 'lib/binance/api/configuration.rb', line 11

def api_key(type: nil)
  raise Error.new(message: "invalid api_key type: #{type}.") unless type.nil? || api_key_types.include?(type)
  instance_api_key(type: type) || ENV["BINANCE_#{type.to_s.humanize.upcase}_API_KEY"] || instance_api_key || ENV["BINANCE_API_KEY"]
end

.locale=(value) ⇒ Object (writeonly)

Sets the attribute locale

Parameters:

  • value

    the value to set the attribute locale to.



8
9
10
# File 'lib/binance/api/configuration.rb', line 8

def locale=(value)
  @locale = value
end

.read_info_api_key=(value) ⇒ Object (writeonly)

Sets the attribute read_info_api_key

Parameters:

  • value

    the value to set the attribute read_info_api_key to.



8
9
10
# File 'lib/binance/api/configuration.rb', line 8

def read_info_api_key=(value)
  @read_info_api_key = value
end

.secret_keyObject



22
23
24
# File 'lib/binance/api/configuration.rb', line 22

def secret_key
  instance_variable_get("@secret_key") || ENV["BINANCE_SECRET_KEY"]
end

.trading_api_key=(value) ⇒ Object (writeonly)

Sets the attribute trading_api_key

Parameters:

  • value

    the value to set the attribute trading_api_key to.



8
9
10
# File 'lib/binance/api/configuration.rb', line 8

def trading_api_key=(value)
  @trading_api_key = value
end

.withdrawals_api_key=(value) ⇒ Object (writeonly)

Sets the attribute withdrawals_api_key

Parameters:

  • value

    the value to set the attribute withdrawals_api_key to.



8
9
10
# File 'lib/binance/api/configuration.rb', line 8

def withdrawals_api_key=(value)
  @withdrawals_api_key = value
end

Class Method Details

.signed_request_signature(payload:, api_secret_key: nil) ⇒ Object

Raises:



26
27
28
29
30
31
# File 'lib/binance/api/configuration.rb', line 26

def signed_request_signature(payload:, api_secret_key: nil)
  raise Error.new(message: "environment variable 'BINANCE_SECRET_KEY' is required " \
                  "for signed requests.") unless api_secret_key || secret_key
  digest = OpenSSL::Digest::SHA256.new
  OpenSSL::HMAC.hexdigest(digest, api_secret_key || secret_key, payload)
end

.timestampObject



33
34
35
# File 'lib/binance/api/configuration.rb', line 33

def timestamp
  Time.now.utc.strftime("%s%3N")
end

.tldObject



16
17
18
19
20
# File 'lib/binance/api/configuration.rb', line 16

def tld
  tld = ENV["BINANCE_TLD"]&.downcase&.to_sym || :com
  validate_tld!(tld)
  tld
end

.validate_tld!(tld) ⇒ Object

Raises:



37
38
39
40
# File 'lib/binance/api/configuration.rb', line 37

def validate_tld!(tld)
  error_message = "Invalid tld (top-level-domain): #{tld}. Use one of: #{allowed_tlds.join(", ")}."
  raise Error.new(message: error_message) unless allowed_tlds.include?(tld&.to_sym)
end