mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
deposit2transfer: refactor deposit check and add more logs
This commit is contained in:
parent
29727c12be
commit
073c4562fd
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user