deposit2transfer: refactor deposit check and add more logs

This commit is contained in:
c9s 2023-08-08 12:23:17 +08:00
parent 29727c12be
commit 073c4562fd
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -87,6 +87,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
return errDepositHistoryNotSupport
}
go s.tickWatcher(ctx, s.Interval.Duration())
return nil
}
@ -94,19 +96,31 @@ func (s *Strategy) tickWatcher(ctx context.Context, interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
s.checkDeposits(ctx)
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
for _, asset := range s.Assets {
account := s.session.Account
s.checkDeposits(ctx)
}
}
}
func (s *Strategy) checkDeposits(ctx context.Context) {
for _, asset := range s.Assets {
log.Infof("checking %s deposits...", asset)
account := s.session.Account
succeededDeposits, err := s.scanDepositHistory(ctx, asset, 4*time.Hour)
if err != nil {
log.WithError(err).Errorf("unable to scan deposit history")
continue
return
}
if len(succeededDeposits) == 0 {
log.Infof("no %s deposit found", asset)
}
for _, d := range succeededDeposits {
@ -115,7 +129,7 @@ func (s *Strategy) tickWatcher(ctx context.Context, interval time.Duration) {
bal, ok := account.Balance(d.Asset)
if !ok {
log.Errorf("unexpected error: %s balance not found", d.Asset)
continue
return
}
log.Infof("%s balance: %+v", d.Asset, bal)
@ -131,8 +145,6 @@ func (s *Strategy) tickWatcher(ctx context.Context, interval time.Duration) {
}
}
}
}
}
}
func (s *Strategy) scanDepositHistory(ctx context.Context, asset string, duration time.Duration) ([]types.Deposit, error) {