mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
xaling: add detectActiveTransfers
This commit is contained in:
parent
6bc8dffe16
commit
4bf558f9eb
|
@ -114,24 +114,32 @@ func (s *Strategy) aggregateBalances(
|
|||
return totalBalances, sessionBalances
|
||||
}
|
||||
|
||||
func (s *Strategy) detectActiveTransfers(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) {
|
||||
func (s *Strategy) detectActiveTransfers(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) (bool, error) {
|
||||
var err2 error
|
||||
until := time.Now()
|
||||
since := until.Add(-time.Hour * 24)
|
||||
for _, session := range sessions {
|
||||
if transferService, ok := session.Exchange.(types.ExchangeTransferHistoryService); ok {
|
||||
transferService, ok := session.Exchange.(types.ExchangeTransferHistoryService)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
withdraws, err := transferService.QueryWithdrawHistory(ctx, "", since, until)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("unable to query withdraw history")
|
||||
err2 = err
|
||||
continue
|
||||
}
|
||||
|
||||
for _, withdraw := range withdraws {
|
||||
_ = withdraw
|
||||
// withdraw.
|
||||
switch withdraw.Status {
|
||||
case types.WithdrawStatusProcessing, types.WithdrawStatusSent, types.WithdrawStatusAwaitingApproval:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false, err2
|
||||
}
|
||||
|
||||
func (s *Strategy) selectSessionForCurrency(
|
||||
|
@ -411,6 +419,14 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
|
|||
}
|
||||
}
|
||||
|
||||
foundActiveTransfer, err := s.detectActiveTransfers(ctx, sessions)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("unable to check active transfers")
|
||||
} else if foundActiveTransfer {
|
||||
log.Warnf("found active transfer, skip balance align check")
|
||||
return
|
||||
}
|
||||
|
||||
totalBalances, sessionBalances := s.aggregateBalances(ctx, sessions)
|
||||
_ = sessionBalances
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user