binance: refactor and update QueryOrderTrades implementation

This commit is contained in:
c9s 2024-05-24 17:35:14 +08:00
parent bc71c95608
commit 901272f153
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -745,6 +745,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
return nil, errors.New("binance: symbol parameter is a mandatory parameter for querying order trades") return nil, errors.New("binance: symbol parameter is a mandatory parameter for querying order trades")
} }
var remoteTrades []binance.TradeV3
var trades []types.Trade var trades []types.Trade
if e.IsMargin { if e.IsMargin {
@ -755,10 +756,20 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
req.IsIsolated(true) req.IsIsolated(true)
} }
remoteTrades, err := req.Do(ctx) remoteTrades, err = req.Do(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else {
req := e.client2.NewGetMyTradesRequest()
req.Symbol(q.Symbol).
OrderID(uint64(orderID))
remoteTrades, err = req.Do(ctx)
if err != nil {
return nil, err
}
}
for _, t := range remoteTrades { for _, t := range remoteTrades {
localTrade, err := toGlobalTrade(t, e.IsMargin) localTrade, err := toGlobalTrade(t, e.IsMargin)
@ -770,25 +781,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]
trades = append(trades, *localTrade) trades = append(trades, *localTrade)
} }
} else { return types.SortTradesAscending(trades), nil
remoteTrades, err := e.client.NewListTradesService().Symbol(q.Symbol).OrderId(orderID).Do(ctx)
if err != nil {
return nil, err
}
for _, t := range remoteTrades {
localTrade, err := toGlobalTrade(*t, e.IsMargin)
if err != nil {
log.WithError(err).Errorf("binance: unable to convert 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) { func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) {