mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1284 from c9s/c9s/strategy-deposit2transfer
FIX: [deposit2transfer] apply rate limiter on checkDeposits
This commit is contained in:
commit
bc9f7b7a1e
|
@ -9,6 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/bbgo"
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
@ -115,10 +116,11 @@ func (s *Strategy) tickWatcher(ctx context.Context, interval time.Duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) checkDeposits(ctx context.Context) {
|
func (s *Strategy) checkDeposits(ctx context.Context) {
|
||||||
|
accountLimiter := rate.NewLimiter(rate.Every(3*time.Second), 1)
|
||||||
|
|
||||||
for _, asset := range s.Assets {
|
for _, asset := range s.Assets {
|
||||||
log.Infof("checking %s deposits...", asset)
|
log.Infof("checking %s deposits...", asset)
|
||||||
|
|
||||||
account := s.session.Account
|
|
||||||
succeededDeposits, err := s.scanDepositHistory(ctx, asset, 4*time.Hour)
|
succeededDeposits, err := s.scanDepositHistory(ctx, asset, 4*time.Hour)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("unable to scan deposit history")
|
log.WithError(err).Errorf("unable to scan deposit history")
|
||||||
|
@ -133,6 +135,17 @@ func (s *Strategy) checkDeposits(ctx context.Context) {
|
||||||
for _, d := range succeededDeposits {
|
for _, d := range succeededDeposits {
|
||||||
log.Infof("found succeeded deposit: %+v", d)
|
log.Infof("found succeeded deposit: %+v", d)
|
||||||
|
|
||||||
|
if err2 := accountLimiter.Wait(ctx); err2 != nil {
|
||||||
|
log.WithError(err2).Errorf("rate limiter error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
account, err2 := s.session.UpdateAccount(ctx)
|
||||||
|
if err2 != nil {
|
||||||
|
log.WithError(err2).Errorf("unable to update account")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
bal, ok := account.Balance(d.Asset)
|
bal, ok := account.Balance(d.Asset)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Errorf("unexpected error: %s balance not found", d.Asset)
|
log.Errorf("unexpected error: %s balance not found", d.Asset)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user