Merge pull request #1289 from bailantaotao/edwin/fix-misc-2

FIX: [bybit] fix misc
This commit is contained in:
bailantaotao 2023-08-16 22:07:57 +08:00 committed by GitHub
commit 3eeba521f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

View File

@ -21,7 +21,7 @@ type CancelOrderRequest struct {
// User customised order ID. Either orderId or orderLinkId is required // User customised order ID. Either orderId or orderLinkId is required
orderLinkId string `param:"orderLinkId"` orderLinkId string `param:"orderLinkId"`
orderId *string `param:"orderLinkId"` orderId *string `param:"orderId"`
// orderFilter default type is Order // orderFilter default type is Order
// tpsl order type are not currently supported // tpsl order type are not currently supported
orderFilter *string `param:"timeInForce" validValues:"Order"` orderFilter *string `param:"timeInForce" validValues:"Order"`

View File

@ -77,12 +77,12 @@ func (p *CancelOrderRequest) GetParameters() (map[string]interface{}, error) {
// assign parameter of orderLinkId // assign parameter of orderLinkId
params["orderLinkId"] = orderLinkId params["orderLinkId"] = orderLinkId
// check orderId field -> json key orderLinkId // check orderId field -> json key orderId
if p.orderId != nil { if p.orderId != nil {
orderId := *p.orderId orderId := *p.orderId
// assign parameter of orderId // assign parameter of orderId
params["orderLinkId"] = orderId params["orderId"] = orderId
} else { } else {
} }
// check orderFilter field -> json key timeInForce // check orderFilter field -> json key timeInForce

View File

@ -302,7 +302,9 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
if len(order.ClientOrderID) > maxOrderIdLen { if len(order.ClientOrderID) > maxOrderIdLen {
return nil, fmt.Errorf("unexpected length of order id, got: %d", len(order.ClientOrderID)) return nil, fmt.Errorf("unexpected length of order id, got: %d", len(order.ClientOrderID))
} }
if len(order.ClientOrderID) > 0 {
req.OrderLinkId(order.ClientOrderID) req.OrderLinkId(order.ClientOrderID)
}
if err := orderRateLimiter.Wait(ctx); err != nil { if err := orderRateLimiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("place order rate limiter wait error: %w", err) return nil, fmt.Errorf("place order rate limiter wait error: %w", err)
@ -312,11 +314,11 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
return nil, fmt.Errorf("failed to place order, order: %#v, err: %w", order, err) return nil, fmt.Errorf("failed to place order, order: %#v, err: %w", order, err)
} }
if len(res.OrderId) == 0 || res.OrderLinkId != order.ClientOrderID { if len(res.OrderId) == 0 || (len(order.ClientOrderID) != 0 && res.OrderLinkId != order.ClientOrderID) {
return nil, fmt.Errorf("unexpected order id, resp: %#v, order: %#v", res, order) return nil, fmt.Errorf("unexpected order id, resp: %#v, order: %#v", res, order)
} }
ordersResp, err := e.client.NewGetOpenOrderRequest().OrderLinkId(res.OrderLinkId).Do(ctx) ordersResp, err := e.client.NewGetOpenOrderRequest().OrderId(res.OrderId).Do(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to query order by client order id: %s, err: %w", res.OrderLinkId, err) return nil, fmt.Errorf("failed to query order by client order id: %s, err: %w", res.OrderLinkId, err)
} }
@ -336,11 +338,17 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
for _, order := range orders { for _, order := range orders {
req := e.client.NewCancelOrderRequest() req := e.client.NewCancelOrderRequest()
reqId := ""
switch { switch {
// use the OrderID first, then the ClientOrderID
case order.OrderID > 0:
req.OrderId(order.UUID)
reqId = order.UUID
case len(order.ClientOrderID) != 0: case len(order.ClientOrderID) != 0:
req.OrderLinkId(order.ClientOrderID) req.OrderLinkId(order.ClientOrderID)
case len(order.UUID) != 0 && order.OrderID != 0: reqId = order.ClientOrderID
req.OrderId(order.UUID)
default: default:
errs = multierr.Append( errs = multierr.Append(
errs, errs,
@ -360,8 +368,10 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
errs = multierr.Append(errs, fmt.Errorf("failed to cancel order id: %s, err: %w", order.ClientOrderID, err)) errs = multierr.Append(errs, fmt.Errorf("failed to cancel order id: %s, err: %w", order.ClientOrderID, err))
continue continue
} }
if res.OrderId != order.UUID || res.OrderLinkId != order.ClientOrderID {
errs = multierr.Append(errs, fmt.Errorf("unexpected order id, resp: %#v, order: %#v", res, order)) // sanity check
if res.OrderId != reqId && res.OrderLinkId != reqId {
errs = multierr.Append(errs, fmt.Errorf("order id mismatch, exp: %s, respOrderId: %s, respOrderLinkId: %s", reqId, res.OrderId, res.OrderLinkId))
continue continue
} }
} }