Skip to content

Commit 7e6b420

Browse files
committed
Add ComputeTotalsMicros for raw micros transaction totals
1 parent a867a26 commit 7e6b420

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

internal/ibctl/ibctltransactions/ibctltransactions.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,41 @@ func ComputeTotals(transactions []*TransactionOverview, formatBase func(int64) s
166166
}
167167
}
168168

169+
// TotalsMicros holds the raw micros totals for the transaction list, suitable for
170+
// further computation (e.g., applying tax rates).
171+
type TotalsMicros struct {
172+
// DividendBaseMicros is the total dividends (including WHT) in base currency micros.
173+
DividendBaseMicros int64
174+
// InterestBaseMicros is the total interest income in base currency micros.
175+
InterestBaseMicros int64
176+
// PnLBaseMicros is the total realized P&L in base currency micros.
177+
PnLBaseMicros int64
178+
// STCGBaseMicros is the total short-term capital gain in base currency micros.
179+
STCGBaseMicros int64
180+
// LTCGBaseMicros is the total long-term capital gain in base currency micros.
181+
LTCGBaseMicros int64
182+
}
183+
184+
// ComputeTotalsMicros sums the dividend, interest, P&L, STCG, and LTCG columns
185+
// across all transactions, returning raw micros values for further computation.
186+
func ComputeTotalsMicros(transactions []*TransactionOverview) *TotalsMicros {
187+
var dividend, interest, pnl, stcg, ltcg int64
188+
for _, t := range transactions {
189+
dividend += mathpb.ParseMicros(t.DividendBase)
190+
interest += mathpb.ParseMicros(t.InterestBase)
191+
pnl += mathpb.ParseMicros(t.PnLBase)
192+
stcg += mathpb.ParseMicros(t.STCGBase)
193+
ltcg += mathpb.ParseMicros(t.LTCGBase)
194+
}
195+
return &TotalsMicros{
196+
DividendBaseMicros: dividend,
197+
InterestBaseMicros: interest,
198+
PnLBaseMicros: pnl,
199+
STCGBaseMicros: stcg,
200+
LTCGBaseMicros: ltcg,
201+
}
202+
}
203+
169204
// GetTransactionList computes the unified transaction list from all data sources.
170205
// baseCurrency is the target currency for conversion (e.g., "USD", "CAD").
171206
// fromDate and toDate filter on the transaction date (inclusive). Zero dates mean no filter.

0 commit comments

Comments
 (0)