Class: OrionX::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/orionx/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, api_secret: nil, api_endpoint: nil, debug: false) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/orionx/client.rb', line 5

def initialize(api_key: nil, api_secret: nil, api_endpoint: nil, debug: false)
  # Configure the SDK if parameters are provided
  if api_key || api_secret || api_endpoint || debug
    OrionX.configure do |config|
      config.api_key = api_key if api_key
      config.api_secret = api_secret if api_secret
      config.api_endpoint = api_endpoint if api_endpoint
      config.debug = debug
    end
  end

  @api = OrionX::API.new
  @logger = @api.logger

  # Initialize endpoint modules
  @user = OrionX::Endpoints::User.new(@api)
  @orders = OrionX::Endpoints::Orders.new(@api)
  @accounts = OrionX::Endpoints::Accounts.new(@api)
  @markets = OrionX::Endpoints::Markets.new(@api)
  @transactions = OrionX::Endpoints::Transactions.new(@api)

  @logger.info("OrionX Client initialized successfully")
end

Instance Attribute Details

#accounts ⇒ Object (readonly)

Returns the value of attribute accounts.



3
4
5
# File 'lib/orionx/client.rb', line 3

def accounts
  @accounts
end

#api ⇒ Object (readonly)

Returns the value of attribute api.



3
4
5
# File 'lib/orionx/client.rb', line 3

def api
  @api
end

#logger ⇒ Object (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/orionx/client.rb', line 3

def logger
  @logger
end

#markets ⇒ Object (readonly)

Returns the value of attribute markets.



3
4
5
# File 'lib/orionx/client.rb', line 3

def markets
  @markets
end

#orders ⇒ Object (readonly)

Returns the value of attribute orders.



3
4
5
# File 'lib/orionx/client.rb', line 3

def orders
  @orders
end

#transactions ⇒ Object (readonly)

Returns the value of attribute transactions.



3
4
5
# File 'lib/orionx/client.rb', line 3

def transactions
  @transactions
end

#user ⇒ Object (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/orionx/client.rb', line 3

def user
  @user
end

Instance Method Details

#debug=(enabled) ⇒ Object

Enable/disable debug mode



45
46
47
48
49
# File 'lib/orionx/client.rb', line 45

def debug=(enabled)
  OrionX.configuration.debug = enabled
  @logger.level = enabled ? ::Logger::DEBUG : ::Logger::INFO
  @logger.info("Debug mode #{enabled ? 'enabled' : 'disabled'}")
end

#debug? ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/orionx/client.rb', line 51

def debug?
  OrionX.configuration.debug?
end

#me ⇒ Object

Convenience method to get current user information



30
31
32
# File 'lib/orionx/client.rb', line 30

def me
  @user.me
end

#ping ⇒ Object

Health check method



35
36
37
38
39
40
41
42
# File 'lib/orionx/client.rb', line 35

def ping
  begin
    me
    { status: "ok", message: "Connection successful" }
  rescue => e
    { status: "error", message: e.message }
  end
end