deposit2transfer: fix deposit time checking

This commit is contained in:
c9s 2024-11-14 22:38:57 +08:00
parent 37c97fd966
commit e9e3dbacec
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

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),
@ -339,7 +345,13 @@ func (s *Strategy) scanDepositHistory(ctx context.Context, asset string, duratio
logger.Infof("ignored expired succeedded deposit: %s %+v", deposit.TransactionID, deposit) logger.Infof("ignored expired succeedded deposit: %s %+v", deposit.TransactionID, deposit)
} }
} else { } else {
s.addWatchingDeposit(deposit) // 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 {
s.addWatchingDeposit(deposit)
}
} }
case types.DepositCredited, types.DepositPending: case types.DepositCredited, types.DepositPending:
@ -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