From b4e71dd5bbd6106a606b5833f79e1c411676ca17 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 12 Aug 2022 02:06:43 +0800 Subject: [PATCH] binance: implement QueryOrderTrades method --- pkg/exchange/binance/exchange.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/exchange/binance/exchange.go b/pkg/exchange/binance/exchange.go index 76535c9bd..c943eb466 100644 --- a/pkg/exchange/binance/exchange.go +++ b/pkg/exchange/binance/exchange.go @@ -77,6 +77,7 @@ type Exchange struct { client2 *binanceapi.RestClient } + var timeSetterOnce sync.Once func New(key, secret string) *Exchange { @@ -718,6 +719,32 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [ return toGlobalOrders(binanceOrders) } +func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]types.Trade, error) { + orderID, err := strconv.ParseInt(q.OrderID, 10, 64) + if err != nil { + return nil, err + } + + remoteTrades, err := e.client.NewListTradesService().OrderId(orderID).Do(ctx) + if err != nil { + return nil, err + } + + var trades []types.Trade + for _, t := range remoteTrades { + localTrade, err := toGlobalTrade(*t, e.IsMargin) + if err != nil { + log.WithError(err).Errorf("can not convert binance trade: %+v", t) + continue + } + + trades = append(trades, *localTrade) + } + + trades = types.SortTradesAscending(trades) + return trades, nil +} + func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) { orderID, err := strconv.ParseInt(q.OrderID, 10, 64) if err != nil {