batch

package
v1.64.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 12 Imported by: 5

README

Batch Query Module

Basic Assumptions for .Query() Methods

All .Query() methods in the batch module follow some fundamental assumptions that are crucial for proper usage:

Error Channel Guarantee

The error channel is always guaranteed to be closed by the Query method implementation. This means that after the data channel has been fully consumed, reading from the error channel will never block - it will either return an error or immediately signal that the channel is closed.

Common Usage Pattern

Due to this guarantee, the typical pattern for using .Query() methods is:

  1. First: Read all data from the data channel
  2. Then: Read from the error channel to handle any errors

This pattern ensures that:

  • You process all available data before checking for errors
  • Your code won't hang waiting for error channel reads
  • Error handling is performed after data consumption is complete
Example Usage
// Query returns (dataChan, errorChan)
dataChan, errChan := batchQuery.Query(ctx, symbol, options)

// Read all data first
var results []types.Trade
for trade := range dataChan {
    results = append(results, trade)
}

// Then check for errors - this will not block
if err := <-errChan; err != nil {
    log.WithError(err).Error("batch query failed")
    return err
}

// Process `results`...

or

// in a function
for {
    select {
    case <-ctx.Done():
        return nil
    case data, ok := <-dataC:
        if !ok {
            err := <-errChan
            return err
        }
        // do stuff with `data`...
    }
}

This design pattern provides a clean separation between data processing and error handling while ensuring predictable, non-blocking behavior.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncTimeRangedBatchQuery added in v1.33.0

type AsyncTimeRangedBatchQuery struct {
	// Type is the object type of the result
	Type interface{}

	// Limiter is the rate limiter for each query
	Limiter *rate.Limiter

	// Q is the remote query function
	Q func(startTime, endTime time.Time) (interface{}, error)

	// T function returns time of an object
	T func(obj interface{}) time.Time

	// ID returns the ID of the object
	ID func(obj interface{}) string

	// JumpIfEmpty jump the startTime + duration when the result is empty
	JumpIfEmpty time.Duration

	DisableBackoff bool
}

func (*AsyncTimeRangedBatchQuery) Query added in v1.33.0

func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, since, until time.Time) chan error

type BinanceFuturesIncomeBatchQuery added in v1.45.0

type BinanceFuturesIncomeBatchQuery struct {
	BinanceFuturesIncomeHistoryService
}

func (*BinanceFuturesIncomeBatchQuery) Query added in v1.45.0

func (e *BinanceFuturesIncomeBatchQuery) Query(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime time.Time) (c chan binanceapi.FuturesIncome, errC chan error)

type BinanceFuturesIncomeHistoryService added in v1.45.0

type BinanceFuturesIncomeHistoryService interface {
	QueryFuturesIncomeHistory(ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime *time.Time) ([]binanceapi.FuturesIncome, error)
}

type ClosedOrderBatchQuery added in v1.13.0

type ClosedOrderBatchQuery struct {
	types.ExchangeTradeHistoryService
}

func (*ClosedOrderBatchQuery) Query added in v1.13.0

func (q *ClosedOrderBatchQuery) Query(ctx context.Context, symbol string, startTime, endTime time.Time, lastOrderID uint64, opts ...Option) (c chan types.Order, errC chan error)

type DepositBatchQuery added in v1.33.2

type DepositBatchQuery struct {
	types.ExchangeTransferService
}

func (*DepositBatchQuery) Query added in v1.33.2

func (e *DepositBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.Deposit, errC chan error)

type KLineBatchQuery added in v1.13.0

type KLineBatchQuery struct {
	types.Exchange
}

func (*KLineBatchQuery) Query added in v1.13.0

func (e *KLineBatchQuery) Query(ctx context.Context, symbol string, interval types.Interval, startTime, endTime time.Time) (c chan types.KLine, errC chan error)

type MarginInterestBatchQuery added in v1.33.0

type MarginInterestBatchQuery struct {
	types.MarginHistoryService
}

func (*MarginInterestBatchQuery) Query added in v1.33.0

func (e *MarginInterestBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.MarginInterest, errC chan error)

type MarginLiquidationBatchQuery added in v1.33.0

type MarginLiquidationBatchQuery struct {
	types.MarginHistoryService
}

func (*MarginLiquidationBatchQuery) Query added in v1.33.0

func (e *MarginLiquidationBatchQuery) Query(ctx context.Context, startTime, endTime time.Time) (c chan types.MarginLiquidation, errC chan error)

type MarginLoanBatchQuery added in v1.33.0

type MarginLoanBatchQuery struct {
	types.MarginHistoryService
}

func (*MarginLoanBatchQuery) Query added in v1.33.0

func (e *MarginLoanBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.MarginLoan, errC chan error)

type MarginRepayBatchQuery added in v1.33.0

type MarginRepayBatchQuery struct {
	types.MarginHistoryService
}

func (*MarginRepayBatchQuery) Query added in v1.33.0

func (e *MarginRepayBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.MarginRepay, errC chan error)

type Option added in v1.53.0

type Option func(query *AsyncTimeRangedBatchQuery)

func JumpIfEmpty added in v1.53.0

func JumpIfEmpty(duration time.Duration) Option

JumpIfEmpty jump the startTime + duration when the result is empty

type RewardBatchQuery added in v1.13.0

type RewardBatchQuery struct {
	Service types.ExchangeRewardService
}

func (*RewardBatchQuery) Query added in v1.13.0

func (q *RewardBatchQuery) Query(ctx context.Context, startTime, endTime time.Time) (c chan types.Reward, errC chan error)

type TradeBatchQuery added in v1.13.0

type TradeBatchQuery struct {
	types.ExchangeTradeHistoryService

	DisableBackoff bool
}

func (TradeBatchQuery) Query added in v1.13.0

func (e TradeBatchQuery) Query(
	ctx context.Context, symbol string, options *types.TradeQueryOptions, opts ...Option,
) (c chan types.Trade, errC chan error)

type WithdrawBatchQuery added in v1.33.0

type WithdrawBatchQuery struct {
	types.ExchangeTransferService
}

func (*WithdrawBatchQuery) Query added in v1.33.0

func (e *WithdrawBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.Withdraw, errC chan error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL