Class: Bybit::Configuration

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

Constant Summary collapse

SAFE_ATTRS =

Attributes safe to expose in serialized form. Anything not in this allowlist is dropped from to_json / as_json / marshal_dump — no accidental secret leakage through pino/winston-style default serializers.

%i[testnet base_url recv_window timeout].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



18
19
20
21
22
# File 'lib/bybit/configuration.rb', line 18

def initialize
  @testnet = false
  @recv_window = DEFAULT_RECV_WINDOW
  @timeout = DEFAULT_TIMEOUT
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def api_secret
  @api_secret
end

#base_urlObject

Returns the value of attribute base_url.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def base_url
  @base_url
end

#faraday_connectionObject

Returns the value of attribute faraday_connection.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def faraday_connection
  @faraday_connection
end

#recv_windowObject

Returns the value of attribute recv_window.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def recv_window
  @recv_window
end

#testnetObject

Returns the value of attribute testnet.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def testnet
  @testnet
end

#timeoutObject

Returns the value of attribute timeout.



15
16
17
# File 'lib/bybit/configuration.rb', line 15

def timeout
  @timeout
end

Instance Method Details

#as_json(*_) ⇒ Object



45
46
47
# File 'lib/bybit/configuration.rb', line 45

def as_json(*_)
  to_h_safe.transform_keys(&:to_s)
end

#inspectObject Also known as: to_s

Redact credentials from #inspect and #to_s so a stray puts/logger call doesn't leak the secret into log aggregation.



61
62
63
# File 'lib/bybit/configuration.rb', line 61

def inspect
  "#<Bybit::Configuration api_key=#{redact(@api_key)} api_secret=#{redact(@api_secret)} testnet=#{@testnet} base_url=#{resolved_base_url}>"
end

#marshal_dumpObject



49
50
51
# File 'lib/bybit/configuration.rb', line 49

def marshal_dump
  to_h_safe
end

#marshal_load(hash) ⇒ Object

Un-marshalling a redacted Configuration is intentionally lossy — callers should never round-trip credentials through Marshal.



55
56
57
# File 'lib/bybit/configuration.rb', line 55

def marshal_load(hash)
  hash.each { |k, v| instance_variable_set("@#{k}", v) }
end

#resolved_base_urlObject



24
25
26
# File 'lib/bybit/configuration.rb', line 24

def resolved_base_url
  base_url || (testnet ? BASE_URL_TESTNET : BASE_URL_MAINNET)
end

#to_h_safeObject

Serialization-safe hash used by as_json / to_json / marshal_dump.



29
30
31
32
33
34
35
36
37
38
# File 'lib/bybit/configuration.rb', line 29

def to_h_safe
  {
    api_key: redact(@api_key),
    api_secret: redact(@api_secret),
    testnet: @testnet,
    base_url: resolved_base_url,
    recv_window: @recv_window,
    timeout: @timeout
  }
end

#to_json(*args) ⇒ Object



40
41
42
43
# File 'lib/bybit/configuration.rb', line 40

def to_json(*args)
  require 'json'
  to_h_safe.to_json(*args)
end