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
15
# File 'lib/binance/api/configuration.rb', line 11

def api_key(type: nil)
  raise Error.new(message: "invalid security_type 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



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

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:) ⇒ Object

Raises:



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

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

.timestampObject



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

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

.tldObject



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

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

.validate_tld!(tld) ⇒ Object

Raises:



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

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