add Balance.Add method

This commit is contained in:
c9s 2022-05-04 21:33:22 +08:00
parent d5b203a925
commit e903bd5f69
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -23,6 +23,16 @@ type Balance struct {
NetAsset fixedpoint.Value `json:"net,omitempty"`
}
func (b Balance) Add(b2 Balance) Balance {
var newB = b
newB.Available = b.Available.Add(b2.Available)
newB.Locked = b.Locked.Add(b2.Locked)
newB.Borrowed = b.Borrowed.Add(b2.Borrowed)
newB.NetAsset = b.NetAsset.Add(b2.NetAsset)
newB.Interest = b.Interest.Add(b2.Interest)
return newB
}
func (b Balance) Total() fixedpoint.Value {
return b.Available.Add(b.Locked)
}
@ -65,11 +75,7 @@ func (m BalanceMap) Add(bm BalanceMap) BalanceMap {
for _, b := range bm {
tb, ok := total[b.Currency]
if ok {
tb.Available = tb.Available.Add(b.Available)
tb.Locked = tb.Locked.Add(b.Locked)
tb.Borrowed = tb.Borrowed.Add(b.Borrowed)
tb.NetAsset = tb.NetAsset.Add(b.NetAsset)
tb.Interest = tb.Interest.Add(b.Interest)
tb = tb.Add(b)
} else {
tb = b
}