fix max deposits history ordering

This commit is contained in:
c9s 2021-03-11 16:03:07 +08:00
parent 75778675e3
commit b25671c864

View File

@ -513,6 +513,7 @@ func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since
func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) (allDeposits []types.Deposit, err error) {
startTime := since
limit := 1000
txIDs := map[string]struct{}{}
for startTime.Before(until) {
// startTime ~ endTime must be in 90 days
@ -522,6 +523,7 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
}
log.Infof("querying deposit history %s: %s <=> %s", asset, startTime, endTime)
req := e.client.AccountService.NewGetDepositHistoryRequest()
if len(asset) > 0 {
req.Currency(toLocalCurrency(asset))
@ -529,13 +531,16 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
deposits, err := req.
From(startTime.Unix()).
To(endTime.Unix()).Do(ctx)
To(endTime.Unix()).
Limit(limit).
Do(ctx)
if err != nil {
return nil, err
}
for _, d := range deposits {
for i := len(deposits) - 1; i >= 0; i-- {
d := deposits[i]
if _, ok := txIDs[d.TxID]; ok {
continue
}
@ -552,7 +557,11 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
})
}
if len(deposits) < limit {
startTime = endTime
} else {
startTime = time.Unix(deposits[0].UpdatedAt, 0)
}
}
return allDeposits, err