Module: MixinBot::API::Asset
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/asset.rb
Overview
API methods for asset management.
Provides methods to:
-
List all assets in bot’s wallet
-
Read specific asset information
-
Get asset ticker/price data
Instance Method Summary collapse
-
#asset(asset_id, access_token: nil) ⇒ Hash
Retrieves information for a specific asset.
- #asset_balance(asset_id) ⇒ Object (also: #asset_balance_with_safe_user)
- #asset_fee(asset_id, destination:, access_token: nil) ⇒ Object (also: #read_asset_fee)
-
#assets(access_token: nil) ⇒ Array<Hash>
Retrieves all assets in the bot’s wallet.
- #fetch_assets(asset_ids, access_token: nil) ⇒ Object
-
#ticker(asset_id, **kwargs) ⇒ Hash
Retrieves ticker/price data for an asset.
- #user_asset_balance(user_id, asset_id, access_token: nil) ⇒ Object
Instance Method Details
#asset(asset_id, access_token: nil) ⇒ Hash
Retrieves information for a specific asset.
Returns detailed information about a single asset including:
-
Current balance
-
Price information
-
Deposit address
-
Network details
70 71 72 73 |
# File 'lib/mixin_bot/api/asset.rb', line 70 def asset(asset_id, access_token: nil) path = format('/assets/%<asset_id>s', asset_id:) client.get path, access_token: end |
#asset_balance(asset_id) ⇒ Object Also known as: asset_balance_with_safe_user
119 120 121 122 |
# File 'lib/mixin_bot/api/asset.rb', line 119 def asset_balance(asset_id) outputs = safe_outputs(asset: asset_id, state: 'unspent') Array(outputs['data']).sum { |o| o['amount'].to_d } end |
#asset_fee(asset_id, destination:, access_token: nil) ⇒ Object Also known as: read_asset_fee
113 114 115 116 |
# File 'lib/mixin_bot/api/asset.rb', line 113 def asset_fee(asset_id, destination:, access_token: nil) path = format('/safe/assets/%<asset_id>s/fees', asset_id:) client.get path, destination:, access_token: end |
#assets(access_token: nil) ⇒ Array<Hash>
Retrieves all assets in the bot’s wallet.
Returns an array of asset objects, each containing:
-
asset_id: the asset UUID
-
symbol: the asset symbol (e.g., “BTC”, “ETH”)
-
name: the full asset name
-
icon_url: URL to the asset icon
-
balance: current balance
-
destination: deposit address
-
tag: deposit memo/tag (if applicable)
-
price_btc: price in BTC
-
price_usd: price in USD
-
chain_id: the blockchain UUID
-
change_btc: 24h price change in BTC
-
change_usd: 24h price change in USD
-
confirmations: required confirmations
-
asset_key: the asset key for deposit
44 45 46 47 |
# File 'lib/mixin_bot/api/asset.rb', line 44 def assets(access_token: nil) path = '/assets' client.get path, access_token: end |
#fetch_assets(asset_ids, access_token: nil) ⇒ Object
109 110 111 |
# File 'lib/mixin_bot/api/asset.rb', line 109 def fetch_assets(asset_ids, access_token: nil) client.fetch_post_array '/safe/assets/fetch', Array(asset_ids), access_token: end |
#ticker(asset_id, **kwargs) ⇒ Hash
Retrieves ticker/price data for an asset.
Returns historical price and volume data for an asset, useful for charts and price tracking.
100 101 102 103 104 105 106 107 |
# File 'lib/mixin_bot/api/asset.rb', line 100 def ticker(asset_id, **kwargs) offset = kwargs[:offset] offset = DateTime.rfc3339(offset) if offset.is_a? String offset = offset.rfc3339 if offset.is_a?(DateTime) || offset.is_a?(Time) path = '/ticker' client.get path, asset_id:, offset:, access_token: kwargs[:access_token] end |
#user_asset_balance(user_id, asset_id, access_token: nil) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/mixin_bot/api/asset.rb', line 125 def user_asset_balance(user_id, asset_id, access_token: nil) members_hash = MixinBot.utils.hash_members([user_id]) path = '/safe/outputs' response = client.get( path, members: members_hash, threshold: 1, asset: asset_id, state: 'unspent', access_token: ) Array(response['data']).sum { |o| o['amount'].to_d } end |