Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api_trading.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions models/cancel_by_label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package models

type CancelByLabelParams struct {
Label string `json:"label"`
Currency string `json:"currency,omitempty"`
}