class Binance::Api::Configuration
Attributes
api_key[W]
locale[W]
read_info_api_key[W]
secret_key[W]
trading_api_key[W]
withdrawals_api_key[W]
Public Class Methods
api_key(type: nil)
click to toggle source
# 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"] || ENV["BINANCE_API_KEY"] end
secret_key()
click to toggle source
# File lib/binance/api/configuration.rb, line 22 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/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
timestamp()
click to toggle source
# File lib/binance/api/configuration.rb, line 33 def timestamp Time.now.utc.strftime("%s%3N") end
tld()
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
allowed_tlds()
click to toggle source
# File lib/binance/api/configuration.rb, line 44 def allowed_tlds [:com, :us] end
api_key_types()
click to toggle source
# File lib/binance/api/configuration.rb, line 48 def api_key_types [:none, :read_info, :trading, :withdrawals].freeze end
instance_api_key(type: nil)
click to toggle source
# File lib/binance/api/configuration.rb, line 52 def instance_api_key(type: nil) var = "#{type.to_s.downcase}_api_key".sub(/^\_/, "") instance_variable_get("@" + var) end