mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
pkg/exchange: supprot queryOrderTrades
This commit is contained in:
parent
3207a8227c
commit
e4ebe1cffd
|
@ -46,6 +46,7 @@ var (
|
||||||
_ types.ExchangeMinimal = &Exchange{}
|
_ types.ExchangeMinimal = &Exchange{}
|
||||||
_ types.ExchangeTradeService = &Exchange{}
|
_ types.ExchangeTradeService = &Exchange{}
|
||||||
_ types.Exchange = &Exchange{}
|
_ types.Exchange = &Exchange{}
|
||||||
|
_ types.ExchangeOrderQueryService = &Exchange{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Exchange struct {
|
type Exchange struct {
|
||||||
|
@ -217,6 +218,45 @@ func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.O
|
||||||
return toGlobalOrder(res.List[0])
|
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) {
|
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) {
|
||||||
if len(order.Market.Symbol) == 0 {
|
if len(order.Market.Symbol) == 0 {
|
||||||
return nil, fmt.Errorf("order.Market.Symbol is required: %+v", order)
|
return nil, fmt.Errorf("order.Market.Symbol is required: %+v", order)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user