@@ -56,6 +56,9 @@ type authState byte
5656// AuthState provides a typed authentication state.
5757type 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.
6063type 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+
126136func (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 {
0 commit comments