qbtrade/pkg/exchange/retry/trade.go
2024-06-27 22:42:38 +08:00

43 lines
1.1 KiB
Go

package retry
import (
"context"
"fmt"
"git.qtrade.icu/lychiyu/qbtrade/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 {
return fmt.Errorf("trade fee of #%d (order #%d) is still processing", trade.ID, trade.OrderID)
}
}
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 {
return fmt.Errorf("trade fee of #%d (order #%d) is still processing", trade.ID, trade.OrderID)
}
}
return err2
}
err = GeneralLiteBackoff(ctx, op)
return trades, err
}