move balance printing to debug-balance env var

This commit is contained in:
c9s 2021-05-17 20:03:26 +08:00
parent f80c98b97c
commit b8fe100b5e

View File

@ -6,10 +6,17 @@ import (
"sync"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
var debugBalance = false
func init() {
debugBalance = viper.GetBool("debug-balance")
}
type Balance struct {
Currency string `json:"currency"`
Available fixedpoint.Value `json:"available"`
@ -216,13 +223,16 @@ func (a *Account) UpdateBalances(balances BalanceMap) {
}
}
func printBalanceUpdate(balances BalanceMap) {
logrus.Infof("balance update: %+v", balances)
}
func (a *Account) BindStream(stream Stream) {
stream.OnBalanceUpdate(a.UpdateBalances)
stream.OnBalanceSnapshot(a.UpdateBalances)
stream.OnBalanceUpdate(func(balances BalanceMap) {
logrus.Infof("balance update: %+v", balances)
})
if debugBalance {
stream.OnBalanceUpdate(printBalanceUpdate)
}
}
func (a *Account) Print() {