8
8
"sync"
9
9
"time"
10
10
11
+ "github.com/pkg/errors"
11
12
"github.com/prometheus/client_golang/prometheus"
12
13
"github.com/sirupsen/logrus"
13
14
"go.uber.org/multierr"
@@ -372,7 +373,7 @@ func (s *Strategy) CleanUp(ctx context.Context) error {
372
373
return werr
373
374
}
374
375
375
- func (s * Strategy ) mustCalculateAndEmitProfit (ctx context.Context ) error {
376
+ func (s * Strategy ) CalculateAndEmitProfitUntilSuccessful (ctx context.Context ) error {
376
377
fromOrderID := s .ProfitStats .FromOrderID
377
378
378
379
historyService , ok := s .ExchangeSession .Exchange .(types.ExchangeTradeHistoryService )
@@ -385,23 +386,19 @@ func (s *Strategy) mustCalculateAndEmitProfit(ctx context.Context) error {
385
386
return fmt .Errorf ("exchange %s doesn't support ExchangeOrderQueryService" , s .ExchangeSession .Exchange .Name ())
386
387
}
387
388
388
- maxTry := 10
389
- for try := 1 ; try < maxTry ; try ++ {
389
+ var op = func () error {
390
390
if err := s .CalculateAndEmitProfit (ctx , historyService , queryService ); err != nil {
391
- s .logger .WithError (err ).Warnf ("failed to calculate and emit profit at #%d try, please check it" , try )
392
- continue
391
+ return errors .Wrapf (err , "failed to calculate and emit profit, please check it" )
393
392
}
394
393
395
- if s .ProfitStats .FromOrderID > fromOrderID {
396
- break
394
+ if s .ProfitStats .FromOrderID == fromOrderID {
395
+ return fmt . Errorf ( "FromOrderID (%d) is not updated, retry it" , s . ProfitStats . FromOrderID )
397
396
}
398
- }
399
397
400
- if s .ProfitStats .FromOrderID == fromOrderID {
401
- return fmt .Errorf ("after trying %d times, we still can't calculate and emit profit, please check it" , maxTry )
398
+ return nil
402
399
}
403
400
404
- return nil
401
+ return retry . GeneralLiteBackoff ( ctx , op )
405
402
}
406
403
407
404
func (s * Strategy ) CalculateAndEmitProfit (ctx context.Context , historyService types.ExchangeTradeHistoryService , queryService types.ExchangeOrderQueryService ) error {
0 commit comments