mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 02:53:50 +00:00
xbalance: add verbose flag
This commit is contained in:
parent
b6fff482a4
commit
1bc36b17ff
|
@ -154,6 +154,8 @@ type Strategy struct {
|
||||||
// Middle is the middle balance level used for re-fill asset
|
// Middle is the middle balance level used for re-fill asset
|
||||||
Middle fixedpoint.Value `json:"middle"`
|
Middle fixedpoint.Value `json:"middle"`
|
||||||
|
|
||||||
|
Verbose bool `json:"verbose"`
|
||||||
|
|
||||||
state *State
|
state *State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,23 +166,10 @@ func (s *Strategy) ID() string {
|
||||||
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {}
|
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {}
|
||||||
|
|
||||||
func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) {
|
func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) {
|
||||||
|
if s.Verbose {
|
||||||
s.Notifiability.Notify("📝 Checking %s low balance level exchange session...", s.Asset)
|
s.Notifiability.Notify("📝 Checking %s low balance level exchange session...", s.Asset)
|
||||||
|
|
||||||
lowLevelSession, lowLevelBalance, err := s.findLowBalanceLevelSession(sessions)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Errorf("can not find low balance level session")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if lowLevelSession == nil {
|
|
||||||
s.Notifiability.Notify("✅ All %s balances are looking good", s.Asset)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.Notifiability.Notify("⚠️ Found low level %s balance from session %s: %s", s.Asset, lowLevelSession.Name, lowLevelBalance.String())
|
|
||||||
|
|
||||||
middle := s.Middle
|
|
||||||
if middle == 0 {
|
|
||||||
var total fixedpoint.Value
|
var total fixedpoint.Value
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
if b, ok := session.Account.Balance(s.Asset); ok {
|
if b, ok := session.Account.Balance(s.Asset); ok {
|
||||||
|
@ -188,7 +177,26 @@ func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.E
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
middle = total.DivFloat64(float64(len(sessions)))
|
lowLevelSession, lowLevelBalance, err := s.findLowBalanceLevelSession(sessions)
|
||||||
|
if err != nil {
|
||||||
|
s.Notifiability.Notify("Can not find low balance level session: %s", err.Error())
|
||||||
|
log.WithError(err).Errorf("Can not find low balance level session")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if lowLevelSession == nil {
|
||||||
|
if s.Verbose {
|
||||||
|
s.Notifiability.Notify("✅ All %s balances are looking good, total value: %f", s.Asset, total.Float64())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Notifiability.Notify("⚠️ Found low level %s balance from session %s: %s", s.Asset, lowLevelSession.Name, lowLevelBalance.String())
|
||||||
|
|
||||||
|
middle := s.Middle
|
||||||
|
if middle == 0 {
|
||||||
|
|
||||||
|
middle = total.DivFloat64(float64(len(sessions))).MulFloat64(0.99)
|
||||||
s.Notifiability.Notify("Total value %f %s, setting middle to %f", total.Float64(), s.Asset, middle.Float64())
|
s.Notifiability.Notify("Total value %f %s, setting middle to %f", total.Float64(), s.Asset, middle.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user