Merge pull request #1818 from c9s/c9s/fix-deposit-time-checking

FIX: fix deposit time checking
This commit is contained in:
c9s 2024-11-14 23:00:30 +08:00 committed by GitHub
commit 1e5733636d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -271,6 +271,12 @@ func (s *Strategy) checkDeposits(ctx context.Context) {
func (s *Strategy) addWatchingDeposit(deposit types.Deposit) { func (s *Strategy) addWatchingDeposit(deposit types.Deposit) {
s.watchingDeposits[deposit.TransactionID] = deposit s.watchingDeposits[deposit.TransactionID] = deposit
if lastTime, ok := s.lastAssetDepositTimes[deposit.Asset]; ok {
s.lastAssetDepositTimes[deposit.Asset] = later(deposit.Time.Time(), lastTime)
} else {
s.lastAssetDepositTimes[deposit.Asset] = deposit.Time.Time()
}
if s.SlackAlert != nil { if s.SlackAlert != nil {
bbgo.PostLiveNote(&deposit, bbgo.PostLiveNote(&deposit,
livenote.Channel(s.SlackAlert.Channel), livenote.Channel(s.SlackAlert.Channel),
@ -338,9 +344,15 @@ func (s *Strategy) scanDepositHistory(ctx context.Context, asset string, duratio
// ignore all initial deposits that are already in success status // ignore all initial deposits that are already in success status
logger.Infof("ignored expired succeedded deposit: %s %+v", deposit.TransactionID, deposit) logger.Infof("ignored expired succeedded deposit: %s %+v", deposit.TransactionID, deposit)
} }
} else {
// if the latest deposit time is not found, check if the deposit is older than 5 minutes
expiryTime := 5 * time.Minute
if deposit.Time.Before(time.Now().Add(-expiryTime)) {
logger.Infof("ignored expired (%s) succeedded deposit: %s %+v", expiryTime, deposit.TransactionID, deposit)
} else { } else {
s.addWatchingDeposit(deposit) s.addWatchingDeposit(deposit)
} }
}
case types.DepositCredited, types.DepositPending: case types.DepositCredited, types.DepositPending:
logger.Infof("adding pending deposit: %s", deposit.TransactionID) logger.Infof("adding pending deposit: %s", deposit.TransactionID)
@ -349,15 +361,6 @@ func (s *Strategy) scanDepositHistory(ctx context.Context, asset string, duratio
} }
} }
if len(deposits) > 0 {
lastDeposit := deposits[len(deposits)-1]
if lastTime, ok := s.lastAssetDepositTimes[asset]; ok {
s.lastAssetDepositTimes[asset] = later(lastDeposit.Time.Time(), lastTime)
} else {
s.lastAssetDepositTimes[asset] = lastDeposit.Time.Time()
}
}
var succeededDeposits []types.Deposit var succeededDeposits []types.Deposit
// find and move out succeeded deposits // find and move out succeeded deposits