From 0a16dd66a22f378c21ca01ff9d0facf2d3623272 Mon Sep 17 00:00:00 2001 From: ku <2201441955@qq.com> Date: Sun, 30 Jan 2022 19:35:49 +0800 Subject: [PATCH] Update --- rest/api_inverse.go | 2 +- rest/api_linear.go | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/rest/api_inverse.go b/rest/api_inverse.go index 91712b1..aa6eb1a 100644 --- a/rest/api_inverse.go +++ b/rest/api_inverse.go @@ -8,7 +8,7 @@ import ( "time" ) -// GetOrderBook +// GetOrderBook Get the orderbook. Each side has a depth of 50. func (b *ByBit) GetOrderBook(symbol string) (query string, resp []byte, result OrderBook, err error) { var ret GetOrderBookResult params := map[string]interface{}{} diff --git a/rest/api_linear.go b/rest/api_linear.go index 680b0b1..f984252 100644 --- a/rest/api_linear.go +++ b/rest/api_linear.go @@ -56,11 +56,17 @@ func (b *ByBit) LinearGetOrders(symbol string, orderStatus string, limit int, pa return } -// GetActiveOrders -func (b *ByBit) LinearGetActiveOrders(symbol string) (query string, resp []byte, result OrderArrayResponse, err error) { +// LinearGetActiveOrders Query real-time active order information. If only order_id or order_link_id are passed, a single order will be returned; otherwise, returns up to 500 unfilled orders. +func (b *ByBit) LinearGetActiveOrders(symbol string, orderId string, orderLinkId string) (query string, resp []byte, result OrderArrayResponse, err error) { var cResult OrderArrayResponse params := map[string]interface{}{} params["symbol"] = symbol + if orderId != "" { + params["order_id"] = orderId + } + if orderLinkId != "" { + params["order_link_id"] = orderLinkId + } query, resp, err = b.SignedRequest(http.MethodGet, "private/linear/order/search", params, &cResult) if err != nil { return @@ -114,11 +120,17 @@ func (b *ByBit) LinearCreateOrder(side string, orderType string, price float64, return } -// ReplaceOrder -func (b *ByBit) LinearReplaceOrder(symbol string, orderID string, qty float64, price float64) (query string, resp []byte, result Order, err error) { +// LinearReplaceOrder Replace order can modify/amend your active orders. +func (b *ByBit) LinearReplaceOrder(symbol string, orderID string, orderLinkId string, qty float64, price float64, + takeProfit float64, stopLoss float64, tpTriggerBy string, slTriggerBy string) (query string, resp []byte, orderId string, err error) { var cResult OrderResponse params := map[string]interface{}{} - params["order_id"] = orderID + if orderID != "" { + params["order_id"] = orderID + } + if orderLinkId != "" { + params["order_link_id"] = orderLinkId + } params["symbol"] = symbol if qty > 0 { params["p_r_qty"] = qty @@ -126,6 +138,18 @@ func (b *ByBit) LinearReplaceOrder(symbol string, orderID string, qty float64, p if price > 0 { params["p_r_price"] = price } + if takeProfit > 0 { + params["take_profit"] = takeProfit + } + if stopLoss > 0 { + params["stop_loss"] = stopLoss + } + if tpTriggerBy != "" { + params["tp_trigger_by"] = tpTriggerBy + } + if slTriggerBy != "" { + params["sl_trigger_by"] = slTriggerBy + } query, resp, err = b.SignedRequest(http.MethodPost, "private/linear/order/replace", params, &cResult) if err != nil { return @@ -134,7 +158,7 @@ func (b *ByBit) LinearReplaceOrder(symbol string, orderID string, qty float64, p err = fmt.Errorf("%v body: [%v]", cResult.RetMsg, string(resp)) return } - result.OrderId = cResult.Result.OrderId + orderId = cResult.Result.OrderId return }