tron.rb 1.0.0 → 1.0.2
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 +4 -4
- data/README.md +14 -0
- data/lib/tron/client.rb +55 -0
- data/lib/tron/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e2df783fb208cc34d8e404c6c93b7fd27aae0066b2f6efec8650c739b5c623
|
4
|
+
data.tar.gz: a13fae572eaebef060a24485db75d70d4d8a71a5952e62f18624b98926225258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f74287a0bd02186a0b8b2b7c4faf62a25fe4ba5e78168da5388855e21d9b3c36e6b5eaeda8d7ea2a787837729971fb033d3174d81352417f3839d043ccc5b275
|
7
|
+
data.tar.gz: 21779f5695517650257c97719bb8903e4de98d4a0c69157816d2cf71a25420385cdfd9d3c8225f6c037a00cce41fe201f4ecbe75dd1231705d4424fe05f0cd79
|
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[:token_balance]} ($#{token[:usd_value]})"
|
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
|
+
token_balance: trx_balance,
|
84
|
+
decimals: 6,
|
85
|
+
address: nil,
|
86
|
+
price_usd: trx_price,
|
87
|
+
usd_value: 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
|
+
usd_value = price_usd ? (token[:balance] * price_usd).round(2) : nil
|
98
|
+
|
99
|
+
tokens << {
|
100
|
+
symbol: token[:symbol],
|
101
|
+
name: token[:name],
|
102
|
+
token_balance: token[:balance],
|
103
|
+
decimals: token[:decimals],
|
104
|
+
address: token[:address],
|
105
|
+
price_usd: price_usd,
|
106
|
+
usd_value: usd_value
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
# Step 4: Calculate total portfolio value
|
111
|
+
total_value_usd = tokens.sum { |t| t[:usd_value] || 0 }
|
112
|
+
|
113
|
+
# Step 5: Sort by value (highest first)
|
114
|
+
tokens.sort_by! { |t| -(t[:usd_value] || 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