diff --git a/pkg/exchange/bybit/exchange.go b/pkg/exchange/bybit/exchange.go index 94f0ce4e4..a38246936 100644 --- a/pkg/exchange/bybit/exchange.go +++ b/pkg/exchange/bybit/exchange.go @@ -46,6 +46,7 @@ var ( _ types.ExchangeMinimal = &Exchange{} _ types.ExchangeTradeService = &Exchange{} _ types.Exchange = &Exchange{} + _ types.ExchangeOrderQueryService = &Exchange{} ) type Exchange struct { @@ -217,6 +218,45 @@ func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.O return toGlobalOrder(res.List[0]) } +func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) (trades []types.Trade, err error) { + if len(q.ClientOrderID) != 0 { + log.Warn("!!!BYBIT EXCHANGE API NOTICE!!! Bybit does not support searching for trades using OrderClientId.") + } + + if len(q.OrderID) == 0 { + return nil, errors.New("orderID is required parameter") + } + req := e.v3client.NewGetTradesRequest().OrderId(q.OrderID) + + if len(q.Symbol) != 0 { + req.Symbol(q.Symbol) + } + + if err := tradeRateLimiter.Wait(ctx); err != nil { + return nil, fmt.Errorf("trade rate limiter wait error: %w", err) + } + response, err := req.Do(ctx) + if err != nil { + return nil, fmt.Errorf("failed to query order trades, err: %w", err) + } + + var errs error + for _, trade := range response.List { + res, err := v3ToGlobalTrade(trade) + if err != nil { + errs = multierr.Append(errs, err) + continue + } + trades = append(trades, *res) + } + + if errs != nil { + return nil, errs + } + + return trades, nil +} + func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) { if len(order.Market.Symbol) == 0 { return nil, fmt.Errorf("order.Market.Symbol is required: %+v", order)