diff --git a/v2/websocket/client.go b/v2/websocket/client.go index 194f11293..f79c7f848 100644 --- a/v2/websocket/client.go +++ b/v2/websocket/client.go @@ -56,6 +56,9 @@ type authState byte // AuthState provides a typed authentication state. type AuthState authState // prevent user construction of authStates +// DMSCancelOnDisconnect cancels session orders on disconnect. +const DMSCancelOnDisconnect int = 4 + // Asynchronous interface decouples the underlying transport from API logic. type Asynchronous interface { Connect() error @@ -94,6 +97,7 @@ type Client struct { timeout int64 // read timeout apiKey string apiSecret string + cancelOnDisconnect bool Authentication AuthState asynchronous Asynchronous nonce utils.NonceGenerator @@ -123,6 +127,12 @@ func (c *Client) Credentials(key string, secret string) *Client { return c } +// CancelOnDisconnect ensures all orders will be canceled if this API session is disconnected. +func (c *Client) CancelOnDisconnect(cxl bool) *Client { + c.cancelOnDisconnect = cxl + return c +} + func (c *Client) sign(msg string) string { sig := hmac.New(sha512.New384, []byte(c.apiSecret)) sig.Write([]byte(msg)) @@ -474,6 +484,9 @@ func (c *Client) authenticate(ctx context.Context, filter ...string) error { Filter: filter, SubID: nonce, } + if c.cancelOnDisconnect { + s.DMS = DMSCancelOnDisconnect + } c.subscriptions.add(s) if err := c.asynchronous.Send(ctx, s); err != nil { diff --git a/v2/websocket/subscriptions.go b/v2/websocket/subscriptions.go index 4026d93e9..78b9895d2 100644 --- a/v2/websocket/subscriptions.go +++ b/v2/websocket/subscriptions.go @@ -19,6 +19,7 @@ type SubscriptionRequest struct { AuthPayload string `json:"authPayload,omitempty"` AuthNonce string `json:"authNonce,omitempty"` Filter []string `json:"filter,omitempty"` + DMS int `json:"dms,omitempty"` // dead man switch // unauthenticated Channel string `json:"channel,omitempty"`