Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: [xalign] detect active depoit. if found, skip align #1786

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions pkg/strategy/xalign/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,38 @@ func (s *Strategy) detectActiveWithdraw(
return nil, err2
}

func (s *Strategy) detectActiveDeposit(
ctx context.Context,
sessions map[string]*bbgo.ExchangeSession,
) (*types.Deposit, error) {
var err2 error
until := time.Now()
since := until.Add(-time.Hour * 24)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using 1 hour should be enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the same interval as detectActiveWithdraw. I think both it's ok because there will not be too many withdraws and deposits ?

for _, session := range sessions {
transferService, ok := session.Exchange.(types.ExchangeTransferHistoryService)
if !ok {
continue
}

deposits, err := transferService.QueryDepositHistory(ctx, "", since, until)
if err != nil {
log.WithError(err).Errorf("unable to query deposit history")
err2 = err
continue
}

for _, deposit := range deposits {
log.Infof("checking deposit status: %s", deposit.String())
switch deposit.Status {
case types.DepositPending:
return &deposit, nil
}
}
}

return nil, err2
}

func (s *Strategy) selectSessionForCurrency(
ctx context.Context, sessions map[string]*bbgo.ExchangeSession, currency string, changeQuantity fixedpoint.Value,
) (*bbgo.ExchangeSession, *types.SubmitOrder) {
Expand Down Expand Up @@ -439,16 +471,28 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange

pendingWithdraw, err := s.detectActiveWithdraw(ctx, sessions)
if err != nil {
log.WithError(err).Errorf("unable to check active transfers")
log.WithError(err).Errorf("unable to check active transfers (withdraw)")
} else if pendingWithdraw != nil {
log.Warnf("found active transfer, skip balance align check")
log.Warnf("found active transfer (withdraw), skip balance align check")

if activeTransferNotificationLimiter.Allow() {
bbgo.Notify("Found active withdraw, skip balance align", pendingWithdraw)
}
return
}

pendingDeposit, err := s.detectActiveDeposit(ctx, sessions)
if err != nil {
log.WithError(err).Errorf("unable to check active transfers (deposit)")
} else if pendingDeposit != nil {
log.Warnf("found active transfer (deposit), skip balance align check")

if activeTransferNotificationLimiter.Allow() {
bbgo.Notify("Found active deposit, skip balance align", pendingDeposit)
}
return
}

totalBalances, sessionBalances := s.aggregateBalances(ctx, sessions)
_ = sessionBalances

Expand Down
Loading