mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
xbalance: configure middle value automatically from total value
This commit is contained in:
parent
732281b55d
commit
5a0ae6773c
|
@ -164,7 +164,6 @@ 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) {
|
||||||
|
|
||||||
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)
|
lowLevelSession, lowLevelBalance, err := s.findLowBalanceLevelSession(sessions)
|
||||||
|
@ -180,7 +179,20 @@ func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.E
|
||||||
|
|
||||||
s.Notifiability.Notify("⚠️ Found low level %s balance from session %s: %s", s.Asset, lowLevelSession.Name, lowLevelBalance.String())
|
s.Notifiability.Notify("⚠️ Found low level %s balance from session %s: %s", s.Asset, lowLevelSession.Name, lowLevelBalance.String())
|
||||||
|
|
||||||
requiredAmount := s.Middle - lowLevelBalance.Available
|
middle := s.Middle
|
||||||
|
if middle == 0 {
|
||||||
|
var total fixedpoint.Value
|
||||||
|
for _, session := range sessions {
|
||||||
|
if b, ok := session.Account.Balance(s.Asset); ok {
|
||||||
|
total += b.Total()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
middle = total.DivFloat64(float64(len(sessions)))
|
||||||
|
s.Notifiability.Notify("Total value %f %s, setting middle to %f", total.Float64(), s.Asset, middle.Float64())
|
||||||
|
}
|
||||||
|
|
||||||
|
requiredAmount := middle - lowLevelBalance.Available
|
||||||
|
|
||||||
s.Notifiability.Notify("Need %f %s to satisfy the middle balance level %f", requiredAmount.Float64(), s.Asset, s.Middle.Float64())
|
s.Notifiability.Notify("Need %f %s to satisfy the middle balance level %f", requiredAmount.Float64(), s.Asset, s.Middle.Float64())
|
||||||
|
|
||||||
|
@ -205,6 +217,7 @@ func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.E
|
||||||
toAddress, ok := s.Addresses[lowLevelSession.Name]
|
toAddress, ok := s.Addresses[lowLevelSession.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Errorf("%s address of session %s not found", s.Asset, lowLevelSession.Name)
|
log.Errorf("%s address of session %s not found", s.Asset, lowLevelSession.Name)
|
||||||
|
s.Notifiability.Notify("%s address of session %s not found", s.Asset, lowLevelSession.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user