class Binance::SDK::Configuration
Constants
- ALLOWED_TLDS
- API_KEY_TYPES
Attributes
api_key[W]
futures[W]
locale[W]
read_info_api_key[W]
secret_key[W]
testnet[W]
trading_api_key[W]
withdrawals_api_key[W]
Public Class Methods
api_key(type: nil)
click to toggle source
# 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?()
click to toggle source
# File lib/binance/sdk/configuration.rb, line 17 def futures? (instance_variable_get("@futures") || ENV["BINANCE_FUTURES"]) == true end
secret_key()
click to toggle source
# File lib/binance/sdk/configuration.rb, line 13 def secret_key instance_variable_get("@secret_key") || ENV["BINANCE_SECRET_KEY"] end
signed_request_signature(payload:, api_secret_key: nil)
click to toggle source
# 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?()
click to toggle source
# File lib/binance/sdk/configuration.rb, line 21 def spot? !futures? end
testnet?()
click to toggle source
# File lib/binance/sdk/configuration.rb, line 25 def testnet? (instance_variable_get("@testnet") || ENV["BINANCE_TESTNET"]) == true end
timestamp()
click to toggle source
# File lib/binance/sdk/configuration.rb, line 43 def timestamp Time.now.strftime("%s%3N") end
tld()
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
instance_api_key(type: nil)
click to toggle source
# File lib/binance/sdk/configuration.rb, line 58 def instance_api_key(type: nil) var = "#{type.to_s.downcase}_api_key".sub(/^\_/, "") instance_variable_get("@#{var}") end