mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
aggregate totalBorrowed
This commit is contained in:
parent
2933db20cd
commit
109fdd6511
|
@ -77,9 +77,16 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {}
|
||||||
func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) {
|
func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) {
|
||||||
totalAssets := types.AssetMap{}
|
totalAssets := types.AssetMap{}
|
||||||
totalBalances := types.BalanceMap{}
|
totalBalances := types.BalanceMap{}
|
||||||
|
totalBorrowed := map[string]fixedpoint.Value{}
|
||||||
lastPrices := map[string]fixedpoint.Value{}
|
lastPrices := map[string]fixedpoint.Value{}
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
balances := session.GetAccount().Balances()
|
if err := session.UpdateAccount(ctx) ; err != nil {
|
||||||
|
log.WithError(err).Errorf("can not update account")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
account := session.GetAccount()
|
||||||
|
balances := account.Balances()
|
||||||
if err := session.UpdatePrices(ctx); err != nil {
|
if err := session.UpdatePrices(ctx); err != nil {
|
||||||
log.WithError(err).Error("price update failed")
|
log.WithError(err).Error("price update failed")
|
||||||
return
|
return
|
||||||
|
@ -90,8 +97,13 @@ func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]
|
||||||
tb.Available = tb.Available.Add(b.Available)
|
tb.Available = tb.Available.Add(b.Available)
|
||||||
tb.Locked = tb.Locked.Add(b.Locked)
|
tb.Locked = tb.Locked.Add(b.Locked)
|
||||||
totalBalances[b.Currency] = tb
|
totalBalances[b.Currency] = tb
|
||||||
|
|
||||||
|
if b.Borrowed.Sign() > 0 {
|
||||||
|
totalBorrowed[b.Currency] = totalBorrowed[b.Currency].Add(b.Borrowed)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
totalBalances[b.Currency] = b
|
totalBalances[b.Currency] = b
|
||||||
|
totalBorrowed[b.Currency] = b.Borrowed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user