Class: OrionX::Endpoints::Accounts
- Inherits:
-
Object
- Object
- OrionX::Endpoints::Accounts
- Defined in:
- lib/orionx/endpoints/accounts.rb
Instance Method Summary collapse
-
#get_account(currency_code) ⇒ Object
Get a specific account by currency code.
-
#get_accounts ⇒ Object
Get all accounts for the user.
-
#get_balance(currency_code) ⇒ Object
Get account balance for a specific currency.
-
#get_balances ⇒ Object
Get balances for all currencies.
-
#initialize(api_client) ⇒ Accounts
constructor
A new instance of Accounts.
Constructor Details
#initialize(api_client) ⇒ Accounts
Returns a new instance of Accounts.
4 5 6 7 |
# File 'lib/orionx/endpoints/accounts.rb', line 4 def initialize(api_client) @api = api_client @logger = api_client.logger end |
Instance Method Details
#get_account(currency_code) ⇒ Object
Get a specific account by currency code
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/orionx/endpoints/accounts.rb', line 10 def get_account(currency_code) raise OrionX::ValidationError, "Currency code cannot be nil or empty" if currency_code.nil? || currency_code.empty? query = <<~GRAPHQL query sdk_getAccount($assetId: ID!) { wallet(code: $assetId) { _id currency { code units } balance availableBalance availableNetworks { code } balanceUSD balanceCLP } } GRAPHQL @logger.debug("Fetching account for currency: #{currency_code}") response = @api.call(query, { assetId: currency_code }) result = response.dig("wallet") @logger.info("Account for #{currency_code} retrieved successfully") if result result end |
#get_accounts ⇒ Object
Get all accounts for the user
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/orionx/endpoints/accounts.rb', line 41 def get_accounts query = <<~GRAPHQL query sdk_getAccounts { me { wallets { _id currency { code units } balance availableBalance availableNetworks { code } balanceUSD balanceCLP } } } GRAPHQL @logger.debug("Fetching all accounts") response = @api.call(query) result = response.dig("me", "wallets") @logger.info("All accounts retrieved: #{result&.length || 0} accounts") if result result end |
#get_balance(currency_code) ⇒ Object
Get account balance for a specific currency
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/orionx/endpoints/accounts.rb', line 72 def get_balance(currency_code) account = get_account(currency_code) return nil unless account { currency: account.dig("currency", "code"), balance: account["balance"], available_balance: account["availableBalance"], balance_usd: account["balanceUSD"], balance_clp: account["balanceCLP"] } end |
#get_balances ⇒ Object
Get balances for all currencies
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/orionx/endpoints/accounts.rb', line 86 def get_balances accounts = get_accounts return [] unless accounts accounts.map do |account| { currency: account.dig("currency", "code"), balance: account["balance"], available_balance: account["availableBalance"], balance_usd: account["balanceUSD"], balance_clp: account["balanceCLP"], wallet_id: account["_id"] } end end |