Skip to content

Commit 9b18c5e

Browse files
authored
Merge pull request #119 from brobits/dms
DMS
2 parents 0c04412 + adea402 commit 9b18c5e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

v2/websocket/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type authState byte
5656
// AuthState provides a typed authentication state.
5757
type AuthState authState // prevent user construction of authStates
5858

59+
// DMSCancelOnDisconnect cancels session orders on disconnect.
60+
const DMSCancelOnDisconnect int = 4
61+
5962
// Asynchronous interface decouples the underlying transport from API logic.
6063
type Asynchronous interface {
6164
Connect() error
@@ -94,6 +97,7 @@ type Client struct {
9497
timeout int64 // read timeout
9598
apiKey string
9699
apiSecret string
100+
cancelOnDisconnect bool
97101
Authentication AuthState
98102
asynchronous Asynchronous
99103
nonce utils.NonceGenerator
@@ -123,6 +127,12 @@ func (c *Client) Credentials(key string, secret string) *Client {
123127
return c
124128
}
125129

130+
// CancelOnDisconnect ensures all orders will be canceled if this API session is disconnected.
131+
func (c *Client) CancelOnDisconnect(cxl bool) *Client {
132+
c.cancelOnDisconnect = cxl
133+
return c
134+
}
135+
126136
func (c *Client) sign(msg string) string {
127137
sig := hmac.New(sha512.New384, []byte(c.apiSecret))
128138
sig.Write([]byte(msg))
@@ -474,6 +484,9 @@ func (c *Client) authenticate(ctx context.Context, filter ...string) error {
474484
Filter: filter,
475485
SubID: nonce,
476486
}
487+
if c.cancelOnDisconnect {
488+
s.DMS = DMSCancelOnDisconnect
489+
}
477490
c.subscriptions.add(s)
478491

479492
if err := c.asynchronous.Send(ctx, s); err != nil {

v2/websocket/subscriptions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type SubscriptionRequest struct {
1919
AuthPayload string `json:"authPayload,omitempty"`
2020
AuthNonce string `json:"authNonce,omitempty"`
2121
Filter []string `json:"filter,omitempty"`
22+
DMS int `json:"dms,omitempty"` // dead man switch
2223

2324
// unauthenticated
2425
Channel string `json:"channel,omitempty"`

0 commit comments

Comments
 (0)