2024-04-29 09:16:04 +00:00
|
|
|
package retry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func QueryTradesUntilSuccessful(
|
|
|
|
ctx context.Context, ex types.ExchangeTradeHistoryService, symbol string, q *types.TradeQueryOptions,
|
|
|
|
) (trades []types.Trade, err error) {
|
|
|
|
var op = func() (err2 error) {
|
|
|
|
trades, err2 = ex.QueryTrades(ctx, symbol, q)
|
|
|
|
for _, trade := range trades {
|
|
|
|
if trade.FeeProcessing {
|
2024-04-30 05:38:35 +00:00
|
|
|
return fmt.Errorf("trade fee of #%d (order #%d) is still processing", trade.ID, trade.OrderID)
|
2024-04-29 09:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err2
|
|
|
|
}
|
|
|
|
|
|
|
|
err = GeneralBackoff(ctx, op)
|
|
|
|
return trades, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func QueryTradesUntilSuccessfulLite(
|
|
|
|
ctx context.Context, ex types.ExchangeTradeHistoryService, symbol string, q *types.TradeQueryOptions,
|
|
|
|
) (trades []types.Trade, err error) {
|
|
|
|
var op = func() (err2 error) {
|
|
|
|
trades, err2 = ex.QueryTrades(ctx, symbol, q)
|
|
|
|
for _, trade := range trades {
|
|
|
|
if trade.FeeProcessing {
|
2024-04-30 05:38:35 +00:00
|
|
|
return fmt.Errorf("trade fee of #%d (order #%d) is still processing", trade.ID, trade.OrderID)
|
2024-04-29 09:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err2
|
|
|
|
}
|
|
|
|
|
|
|
|
err = GeneralLiteBackoff(ctx, op)
|
|
|
|
return trades, err
|
|
|
|
}
|