mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-16 12:03:51 +00:00
30 lines
660 B
Go
30 lines
660 B
Go
|
package binance
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/c9s/bbgo/pkg/types"
|
||
|
)
|
||
|
|
||
|
func (e *Exchange) QueryHistoricalTrades(ctx context.Context, symbol string, limit uint64) ([]types.Trade, error) {
|
||
|
req := e.client2.NewGetHistoricalTradesRequest()
|
||
|
req.Symbol(symbol)
|
||
|
req.Limit(limit)
|
||
|
trades, err := req.Do(ctx)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var result []types.Trade
|
||
|
for _, t := range trades {
|
||
|
localTrade, err := toGlobalTrade(t, e.IsMargin)
|
||
|
if err != nil {
|
||
|
log.WithError(err).Errorf("cannot convert binance trade: %+v", t)
|
||
|
continue
|
||
|
}
|
||
|
result = append(result, *localTrade)
|
||
|
}
|
||
|
result = types.SortTradesAscending(result)
|
||
|
return result, nil
|
||
|
}
|