diff --git a/api_trading.go b/api_trading.go index d367516..478c17e 100644 --- a/api_trading.go +++ b/api_trading.go @@ -39,6 +39,11 @@ func (c *Client) CancelAllByInstrument(params *models.CancelAllByInstrumentParam return } +func (c *Client) CancelByLabel(params *models.CancelByLabelParams) (result int, err error) { + err = c.Call("private/cancel_by_label", params, &result) + return +} + func (c *Client) ClosePosition(params *models.ClosePositionParams) (result models.ClosePositionResponse, err error) { err = c.Call("private/close_position", params, &result) return diff --git a/client_test.go b/client_test.go index d33088f..68fc9d4 100644 --- a/client_test.go +++ b/client_test.go @@ -2,9 +2,10 @@ package deribit import ( "encoding/json" + "testing" + "github.com/frankrap/deribit-api/models" "github.com/stretchr/testify/assert" - "testing" ) func newClient() *Client { @@ -135,6 +136,39 @@ func TestClient_Buy(t *testing.T) { t.Logf("%#v", result) } +func TestClient_CancelByLabel(t *testing.T) { + client := newClient() + params := &models.BuyParams{ + InstrumentName: "BTC-PERPETUAL", + Amount: 10, + Price: 20000.0, + Type: "limit", + Label: "TestClient_CancelByLabel", + } + result, err := client.Buy(params) + if err != nil { + t.Fatal(err) + return + } + + t.Logf("%#v", result) + + cancelByLabelParams := &models.CancelByLabelParams{ + Label: "TestClient_CancelByLabel", + } + + cancelResult, err := client.CancelByLabel(cancelByLabelParams) + if err != nil { + t.Errorf("Cancel failed, %s", err) + } + + if cancelResult <= 0 { + t.Errorf("Cancel order count should be greater than 0, actual=%d", cancelResult) + } + + t.Logf("%#v", cancelResult) +} + func TestJsonOmitempty(t *testing.T) { params := &models.BuyParams{ InstrumentName: "BTC-PERPETUAL", diff --git a/models/cancel_by_label.go b/models/cancel_by_label.go new file mode 100644 index 0000000..09d3b44 --- /dev/null +++ b/models/cancel_by_label.go @@ -0,0 +1,6 @@ +package models + +type CancelByLabelParams struct { + Label string `json:"label"` + Currency string `json:"currency,omitempty"` +}