Class: Binance::SDK::Configuration

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_key(type: nil) ⇒ Object

Raises:



7
8
9
10
11
# File 'lib/binance/sdk/configuration.rb', line 7

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)
end

.futures=(value) ⇒ Object (writeonly)

Sets the attribute futures

Parameters:

  • value

    the value to set the attribute futures to.



5
6
7
# File 'lib/binance/sdk/configuration.rb', line 5

def futures=(value)
  @futures = value
end

.locale=(value) ⇒ Object (writeonly)

Sets the attribute locale

Parameters:

  • value

    the value to set the attribute locale to.



5
6
7
# File 'lib/binance/sdk/configuration.rb', line 5

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.



5
6
7
# File 'lib/binance/sdk/configuration.rb', line 5

def read_info_api_key=(value)
  @read_info_api_key = value
end

.secret_keyObject



13
14
15
# File 'lib/binance/sdk/configuration.rb', line 13

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

.testnet=(value) ⇒ Object (writeonly)

Sets the attribute testnet

Parameters:

  • value

    the value to set the attribute testnet to.



5
6
7
# File 'lib/binance/sdk/configuration.rb', line 5

def testnet=(value)
  @testnet = value
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.



5
6
7
# File 'lib/binance/sdk/configuration.rb', line 5

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.



5
6
7
# File 'lib/binance/sdk/configuration.rb', line 5

def withdrawals_api_key=(value)
  @withdrawals_api_key = value
end

Class Method Details

.futures?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/binance/sdk/configuration.rb', line 17

def futures?
  (instance_variable_get("@futures") || ENV["BINANCE_FUTURES"]) == true
end

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

Raises:



29
30
31
32
33
34
# File 'lib/binance/sdk/configuration.rb', line 29

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

.spot?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/binance/sdk/configuration.rb', line 21

def spot?
  !futures?
end

.testnet?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/binance/sdk/configuration.rb', line 25

def testnet?
  (instance_variable_get("@testnet") || ENV["BINANCE_TESTNET"]) == true
end

.timestampObject



43
44
45
# File 'lib/binance/sdk/configuration.rb', line 43

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

.tldObject



36
37
38
39
40
41
# File 'lib/binance/sdk/configuration.rb', line 36

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

  tld
end

.validate_tld!(tld) ⇒ Object

Raises:



47
48
49
50
51
# File 'lib/binance/sdk/configuration.rb', line 47

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