Skip to content

Commit

Permalink
Merge pull request bitfinexcom#119 from brobits/dms
Browse files Browse the repository at this point in the history
DMS
  • Loading branch information
prdn authored Apr 25, 2018
2 parents 0c04412 + adea402 commit 9b18c5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions v2/websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,6 +97,7 @@ type Client struct {
timeout int64 // read timeout
apiKey string
apiSecret string
cancelOnDisconnect bool
Authentication AuthState
asynchronous Asynchronous
nonce utils.NonceGenerator
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions v2/websocket/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 9b18c5e

Please sign in to comment.