mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add Balance.Add method
This commit is contained in:
parent
d5b203a925
commit
e903bd5f69
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user