tron.rb 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb06efba2988905e0c66fa13f78960c58b91b08646a1822ad1878182ad359f90
4
- data.tar.gz: f3f3b0b7b88280f7fcbc5733b57d752abef9a8623ea7a05a360e91c790131f33
3
+ metadata.gz: 966fad6a23cb5e25e03942b1c957e50686b57aba89cffca0567618648015dcad
4
+ data.tar.gz: '09b08d02c41b826b15cfb283acac79f4c9bd1272465013ec7961e64076b03b7e'
5
5
  SHA512:
6
- metadata.gz: 6fcef166d0c652dcb4deaf3040eb71f9647009e315d53486adbfd505bc322848d9516f6d60d72f3623bc4fc11b11fe6d58798544df7b566f9782828add54d501
7
- data.tar.gz: deb26afaafb9c7dc395dabcb17ac31a4ff01c1458f61d6e3db394659d1c1ad2daf6e2a7a82ed4f2e59d6efb61776d178e1e38254aa2e5b978da6b77064f400fe
6
+ metadata.gz: b532f28c101c294eab8b13d1439f41a6ec71d14911a0b4c351c009a0f711dedf27c67c8041bbddb84a785d766cd2655a0d3920498748b0823bb6629593c337f8
7
+ data.tar.gz: a474fa28f378f2c0c28dbfb247db873f6080a66a94976b26d1a59578e8786687ef598d55ffaa8c2550a281a4a7fd32a4653615e08451cf5391e540edaf5bb1fd
data/README.md CHANGED
@@ -90,6 +90,20 @@ wallet_info = client.get_wallet_balance('TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb')
90
90
  full_info = client.get_full_account_info('TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb')
91
91
  ```
92
92
 
93
+ #### Get Wallet Portfolio with USD Values:
94
+ ```ruby
95
+ # Get wallet portfolio with balances, USD prices, and total value
96
+ portfolio = client.get_wallet_portfolio('TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb')
97
+
98
+ # Include tokens with zero balance
99
+ portfolio = client.get_wallet_portfolio('TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb', include_zero_balances: true)
100
+
101
+ puts "Total Portfolio Value: $#{portfolio[:total_value_usd]}"
102
+ portfolio[:tokens].each do |token|
103
+ puts "#{token[:symbol]}: #{token[:balance]} ($#{token[:value_usd]})"
104
+ end
105
+ ```
106
+
93
107
  ## Features
94
108
 
95
109
  - ✓ TRX balance
data/lib/tron/client.rb CHANGED
@@ -65,6 +65,61 @@ module Tron
65
65
  }
66
66
  end
67
67
 
68
+ def get_wallet_portfolio(address, include_zero_balances: false)
69
+ validate_address!(address)
70
+
71
+ # Step 1: Get all balances (TRX + TRC20)
72
+ wallet_data = get_wallet_balance(address)
73
+
74
+ tokens = []
75
+
76
+ # Step 2: Process TRX (native token)
77
+ trx_balance = wallet_data[:trx_balance].to_f
78
+ if trx_balance > 0 || include_zero_balances
79
+ trx_price = price_service.get_token_price_usd('trx')
80
+ tokens << {
81
+ symbol: 'TRX',
82
+ name: 'Tronix',
83
+ balance: trx_balance,
84
+ decimals: 6,
85
+ address: nil,
86
+ price_usd: trx_price,
87
+ value_usd: trx_price ? (trx_balance * trx_price).round(2) : nil
88
+ }
89
+ end
90
+
91
+ # Step 3: Process TRC20 tokens
92
+ wallet_data[:trc20_tokens].each do |token|
93
+ next if token[:balance] <= 0 && !include_zero_balances
94
+
95
+ # Get USD price for this token
96
+ price_usd = price_service.get_token_price_usd(token[:symbol].downcase)
97
+ value_usd = price_usd ? (token[:balance] * price_usd).round(2) : nil
98
+
99
+ tokens << {
100
+ symbol: token[:symbol],
101
+ name: token[:name],
102
+ balance: token[:balance],
103
+ decimals: token[:decimals],
104
+ address: token[:address],
105
+ price_usd: price_usd,
106
+ value_usd: value_usd
107
+ }
108
+ end
109
+
110
+ # Step 4: Calculate total portfolio value
111
+ total_value_usd = tokens.sum { |t| t[:value_usd] || 0 }
112
+
113
+ # Step 5: Sort by value (highest first)
114
+ tokens.sort_by! { |t| -(t[:value_usd] || 0) }
115
+
116
+ {
117
+ address: address,
118
+ total_value_usd: total_value_usd.round(2),
119
+ tokens: tokens
120
+ }
121
+ end
122
+
68
123
  private
69
124
 
70
125
  def validate_address!(address)
data/lib/tron/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # lib/tron/version.rb
4
4
  module Tron
5
- VERSION = "1.0.0".freeze
5
+ VERSION = "1.0.1".freeze
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tron.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name