kucoin: add websocket command

This commit is contained in:
c9s 2021-12-23 00:30:17 +08:00
parent a65070de66
commit 6cbccc9a3f
2 changed files with 38 additions and 2 deletions

View File

@ -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 {

View File

@ -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)
}