mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
Merge pull request #1786 from c9s/chiahung/xalign/detect-pending-deposit
FEATURE: [xalign] detect active depoit. if found, skip align
This commit is contained in:
commit
859be58113
|
@ -156,6 +156,38 @@ func (s *Strategy) detectActiveWithdraw(
|
||||||
return nil, err2
|
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)
|
||||||
|
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(
|
func (s *Strategy) selectSessionForCurrency(
|
||||||
ctx context.Context, sessions map[string]*bbgo.ExchangeSession, currency string, changeQuantity fixedpoint.Value,
|
ctx context.Context, sessions map[string]*bbgo.ExchangeSession, currency string, changeQuantity fixedpoint.Value,
|
||||||
) (*bbgo.ExchangeSession, *types.SubmitOrder) {
|
) (*bbgo.ExchangeSession, *types.SubmitOrder) {
|
||||||
|
@ -439,9 +471,9 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
|
||||||
|
|
||||||
pendingWithdraw, err := s.detectActiveWithdraw(ctx, sessions)
|
pendingWithdraw, err := s.detectActiveWithdraw(ctx, sessions)
|
||||||
if err != nil {
|
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 {
|
} 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() {
|
if activeTransferNotificationLimiter.Allow() {
|
||||||
bbgo.Notify("Found active withdraw, skip balance align", pendingWithdraw)
|
bbgo.Notify("Found active withdraw, skip balance align", pendingWithdraw)
|
||||||
|
@ -449,6 +481,18 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
|
||||||
return
|
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)
|
totalBalances, sessionBalances := s.aggregateBalances(ctx, sessions)
|
||||||
_ = sessionBalances
|
_ = sessionBalances
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user