Skip to content

Commit 80be56d

Browse files
committed
Update
1 parent cafda3e commit 80be56d

File tree

3 files changed

+153
-38
lines changed

3 files changed

+153
-38
lines changed

rest/api_order.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ func (b *ByBit) getOrders(orderID string, orderLinkID string, sort string, order
221221
// stopOrderStatus 条件单状态: Untriggered: 等待市价触发条件单; Triggered: 市价已触发条件单; Cancelled: 取消; Active: 条件单触发成功且下单成功; Rejected: 条件触发成功但下单失败
222222
// limit: 一页数量,默认一页展示20条数据;最大支持50条每页
223223
func (b *ByBit) GetStopOrders(orderID string, orderLinkID string, stopOrderStatus string, order string,
224-
page int, limit int, symbol string) (result []Order, err error) {
225-
var cResult OrderListResult
224+
page int, limit int, symbol string) (result GetStopOrdersResult, err error) {
226225

227226
if limit == 0 {
228227
limit = 20
@@ -245,16 +244,15 @@ func (b *ByBit) GetStopOrders(orderID string, orderLinkID string, stopOrderStatu
245244
params["page"] = page
246245
params["limit"] = limit
247246
var resp []byte
248-
resp, err = b.SignedRequest(http.MethodGet, "open-api/stop-order/list", params, &cResult)
247+
resp, err = b.SignedRequest(http.MethodGet, "open-api/stop-order/list", params, &result)
249248
if err != nil {
250249
return
251250
}
252-
if cResult.RetCode != 0 {
253-
err = fmt.Errorf("%v body: [%v]", cResult.RetMsg, string(resp))
251+
if result.RetCode != 0 {
252+
err = fmt.Errorf("%v body: [%v]", result.RetMsg, string(resp))
254253
return
255254
}
256255

257-
result = cResult.Result.Data
258256
return
259257
}
260258

@@ -388,3 +386,23 @@ func (b *ByBit) CancelStopOrder(orderID string, symbol string) (result Order, er
388386
result = cResult.Result
389387
return
390388
}
389+
390+
// CancelAllStopOrders 撤消全部条件委托单
391+
// symbol:
392+
func (b *ByBit) CancelAllStopOrders(symbol string) (result []StopOrderV2, err error) {
393+
var cResult CancelStopOrdersV2Result
394+
params := map[string]interface{}{}
395+
params["symbol"] = symbol
396+
var resp []byte
397+
resp, err = b.SignedRequest(http.MethodPost, "v2/private/stop-order/cancelAll", params, &cResult)
398+
if err != nil {
399+
return
400+
}
401+
if cResult.RetCode != 0 {
402+
err = fmt.Errorf("%v body: [%v]", cResult.RetMsg, string(resp))
403+
return
404+
}
405+
406+
result = cResult.Result
407+
return
408+
}

rest/api_test.go

+30-7
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,31 @@ func TestByBit_GetOrder(t *testing.T) {
243243
func TestByBit_GetStopOrders(t *testing.T) {
244244
b := newByBit()
245245
symbol := "BTCUSD"
246-
orders, err := b.GetStopOrders("", "", "", "", 0, 10, symbol)
246+
// Untriggered: 等待市价触发条件单; Triggered: 市价已触发条件单; Cancelled: 取消; Active: 条件单触发成功且下单成功; Rejected: 条件触发成功但下单失败
247+
status := "Untriggered,Triggered,Active"
248+
result, err := b.GetStopOrders("", "", status, "", 0, 10, symbol)
247249
assert.Nil(t, err)
248250
//t.Logf("%#v", orders)
249-
for _, order := range orders {
250-
if order.ExtFields != nil {
251-
t.Logf("%#v %v", order, *order.ExtFields)
252-
} else {
253-
t.Logf("%#v", order)
254-
}
251+
for _, order := range result.Result.Data {
252+
//if order.ExtFields != nil {
253+
// t.Logf("%#v %v", order, *order.ExtFields)
254+
//} else {
255+
t.Logf("CreatedAt: %v %#v", order.CreatedAt.Local(), order)
256+
//}
257+
}
258+
}
259+
260+
func TestByBit_GetStopOrders2(t *testing.T) {
261+
b := newByBit()
262+
symbol := "BTCUSD"
263+
//stopOrderID := "8a84cd9b-a3d4-4354-b2d7-e3b805369b77"
264+
stopOrderID := "ccdcbdae-2eb8-4b8f-92de-32cc5ee18de4"
265+
order, err := b.GetOrderByID(stopOrderID, "", symbol)
266+
if err != nil {
267+
t.Error(err)
268+
return
255269
}
270+
t.Logf("%#v", order)
256271
}
257272

258273
func TestByBit_CancelOrder(t *testing.T) {
@@ -285,6 +300,14 @@ func TestByBit_CancelStopOrder(t *testing.T) {
285300
t.Logf("%#v", order)
286301
}
287302

303+
func TestByBit_CancelAllStopOrders(t *testing.T) {
304+
b := newByBit()
305+
symbol := "BTCUSD"
306+
orders, err := b.CancelAllStopOrders(symbol)
307+
assert.Nil(t, err)
308+
t.Logf("%#v", orders)
309+
}
310+
288311
func TestByBit_GetLeverages(t *testing.T) {
289312
b := newByBit()
290313
l, err := b.GetLeverages()

rest/result.go

+99-25
Original file line numberDiff line numberDiff line change
@@ -239,29 +239,30 @@ type OrderListResult struct {
239239

240240
// Order ...
241241
type Order struct {
242-
OrderID string `json:"order_id"`
243-
StopOrderID string `json:"stop_order_id"`
244-
UserID int `json:"user_id"`
245-
Symbol string `json:"symbol"`
246-
Side string `json:"side"`
247-
OrderType string `json:"order_type"`
248-
Price float64 `json:"price"`
249-
Qty float64 `json:"qty"`
250-
TimeInForce string `json:"time_in_force"`
251-
StopOrderType string `json:"stop_order_type,omitempty"`
252-
StopPx sjson.Number `json:"stop_px,omitempty"`
253-
OrderStatus string `json:"order_status"`
254-
LastExecTime string `json:"last_exec_time"`
255-
LastExecPrice float64 `json:"last_exec_price"`
256-
LeavesQty float64 `json:"leaves_qty"`
257-
CumExecQty float64 `json:"cum_exec_qty"`
258-
CumExecValue float64 `json:"cum_exec_value"`
259-
CumExecFee float64 `json:"cum_exec_fee"`
260-
RejectReason string `json:"reject_reason"`
261-
OrderLinkID string `json:"order_link_id"`
262-
CreatedAt time.Time `json:"created_at"`
263-
UpdatedAt time.Time `json:"updated_at"`
264-
ExtFields *ExtFields `json:"ext_fields,omitempty"`
242+
OrderID string `json:"order_id"`
243+
//StopOrderID string `json:"stop_order_id"`
244+
UserID int `json:"user_id"`
245+
Symbol string `json:"symbol"`
246+
Side string `json:"side"`
247+
OrderType string `json:"order_type"`
248+
Price float64 `json:"price"`
249+
Qty float64 `json:"qty"`
250+
TimeInForce string `json:"time_in_force"`
251+
//StopOrderType string `json:"stop_order_type,omitempty"`
252+
//StopPx sjson.Number `json:"stop_px,omitempty"`
253+
OrderStatus string `json:"order_status"`
254+
//StopOrderStatus string `json:"stop_order_status"`
255+
LastExecTime string `json:"last_exec_time"`
256+
LastExecPrice float64 `json:"last_exec_price"`
257+
LeavesQty float64 `json:"leaves_qty"`
258+
CumExecQty float64 `json:"cum_exec_qty"`
259+
CumExecValue float64 `json:"cum_exec_value"`
260+
CumExecFee float64 `json:"cum_exec_fee"`
261+
RejectReason string `json:"reject_reason"`
262+
OrderLinkID string `json:"order_link_id"`
263+
CreatedAt time.Time `json:"created_at"`
264+
UpdatedAt time.Time `json:"updated_at"`
265+
ExtFields *ExtFields `json:"ext_fields,omitempty"`
265266
}
266267

267268
type ExtFields struct {
@@ -416,8 +417,8 @@ type OrderV2 struct {
416417
OrderStatus string `json:"order_status"`
417418
LastExecTime sjson.Number `json:"last_exec_time"`
418419
LastExecPrice sjson.Number `json:"last_exec_price"`
419-
LeavesQty int `json:"leaves_qty"`
420-
CumExecQty int `json:"cum_exec_qty"`
420+
LeavesQty float64 `json:"leaves_qty"`
421+
CumExecQty float64 `json:"cum_exec_qty"`
421422
CumExecValue sjson.Number `json:"cum_exec_value"`
422423
CumExecFee sjson.Number `json:"cum_exec_fee"`
423424
RejectReason string `json:"reject_reason"`
@@ -473,3 +474,76 @@ type QueryOrderResult struct {
473474
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
474475
RateLimit int `json:"rate_limit"`
475476
}
477+
478+
type StopOrderV2 struct {
479+
ClOrdID string `json:"clOrdID"`
480+
UserID int64 `json:"user_id"`
481+
Symbol string `json:"symbol"`
482+
Side string `json:"side"`
483+
OrderType string `json:"order_type"`
484+
Price sjson.Number `json:"price"`
485+
Qty float64 `json:"qty"`
486+
TimeInForce string `json:"time_in_force"`
487+
CreateType string `json:"create_type"`
488+
CancelType string `json:"cancel_type"`
489+
OrderStatus string `json:"order_status"`
490+
LeavesQty float64 `json:"leaves_qty"`
491+
LeavesValue string `json:"leaves_value"`
492+
CreatedAt time.Time `json:"created_at"`
493+
UpdatedAt time.Time `json:"updated_at"`
494+
CrossStatus string `json:"cross_status"`
495+
CrossSeq float64 `json:"cross_seq"`
496+
StopOrderType string `json:"stop_order_type"`
497+
TriggerBy string `json:"trigger_by"`
498+
BasePrice sjson.Number `json:"base_price"`
499+
ExpectedDirection string `json:"expected_direction"`
500+
}
501+
502+
type CancelStopOrdersV2Result struct {
503+
RetCode int `json:"ret_code"`
504+
RetMsg string `json:"ret_msg"`
505+
ExtCode string `json:"ext_code"`
506+
ExtInfo string `json:"ext_info"`
507+
Result []StopOrderV2 `json:"result"`
508+
TimeNow string `json:"time_now"`
509+
RateLimitStatus int `json:"rate_limit_status"`
510+
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
511+
RateLimit int `json:"rate_limit"`
512+
}
513+
514+
type StopOrder struct {
515+
UserID int64 `json:"user_id"`
516+
StopOrderStatus string `json:"stop_order_status"`
517+
Symbol string `json:"symbol"`
518+
Side string `json:"side"`
519+
OrderType string `json:"order_type"`
520+
Price float64 `json:"price"`
521+
Qty float64 `json:"qty"`
522+
TimeInForce string `json:"time_in_force"`
523+
StopOrderType string `json:"stop_order_type"`
524+
TriggerBy string `json:"trigger_by"`
525+
BasePrice float64 `json:"base_price"`
526+
OrderLinkID string `json:"order_link_id"`
527+
CreatedAt time.Time `json:"created_at"`
528+
UpdatedAt time.Time `json:"updated_at"`
529+
StopPx float64 `json:"stop_px"`
530+
StopOrderID string `json:"stop_order_id"`
531+
}
532+
533+
type GetStopOrdersResultData struct {
534+
CurrentPage int `json:"current_page"`
535+
LastPage int `json:"last_page"`
536+
Data []StopOrder `json:"data"`
537+
}
538+
539+
type GetStopOrdersResult struct {
540+
RetCode int `json:"ret_code"`
541+
RetMsg string `json:"ret_msg"`
542+
ExtCode string `json:"ext_code"`
543+
Result GetStopOrdersResultData `json:"result"`
544+
ExtInfo interface{} `json:"ext_info"`
545+
TimeNow string `json:"time_now"`
546+
RateLimitStatus int `json:"rate_limit_status"`
547+
RateLimitResetMs int64 `json:"rate_limit_reset_ms"`
548+
RateLimit int `json:"rate_limit"`
549+
}

0 commit comments

Comments
 (0)