diff --git a/examples/kucoin/websocket.go b/examples/kucoin/websocket.go index aac492a76..911835e42 100644 --- a/examples/kucoin/websocket.go +++ b/examples/kucoin/websocket.go @@ -75,12 +75,31 @@ var websocketCmd = &cobra.Command{ c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) if err != nil { - logrus.Fatal("dial:", err) + return err } + defer c.Close() - done := make(chan struct{}) + wsCmd := &kucoinapi.WebSocketCommand{ + Id: time.Now().UnixMilli(), + Type: "subscribe", + Topic: "/market/ticker:ETH-USDT", + PrivateChannel: false, + Response: true, + } + msg, err := wsCmd.JSON() + if err != nil { + return err + } + + err = c.WriteMessage(websocket.TextMessage, msg) + if err != nil { + return err + } + + + done := make(chan struct{}) go func() { defer close(done) for { diff --git a/pkg/exchange/kucoin/kucoinapi/websocket.go b/pkg/exchange/kucoin/kucoinapi/websocket.go new file mode 100644 index 000000000..7c9050adb --- /dev/null +++ b/pkg/exchange/kucoin/kucoinapi/websocket.go @@ -0,0 +1,17 @@ +package kucoinapi + +import "encoding/json" + +type WebSocketCommand struct { + Id int64 `json:"id"` + Type string `json:"type"` + Topic string `json:"topic"` + PrivateChannel bool `json:"privateChannel"` + Response bool `json:"response"` +} + +func (c *WebSocketCommand) JSON() ([]byte, error) { + type tt WebSocketCommand + var a = (*tt)(c) + return json.Marshal(a) +} \ No newline at end of file