mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
kucoin: add websocket command
This commit is contained in:
parent
a65070de66
commit
6cbccc9a3f
|
@ -75,12 +75,31 @@ var websocketCmd = &cobra.Command{
|
||||||
|
|
||||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal("dial:", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer c.Close()
|
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() {
|
go func() {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
for {
|
for {
|
||||||
|
|
17
pkg/exchange/kucoin/kucoinapi/websocket.go
Normal file
17
pkg/exchange/kucoin/kucoinapi/websocket.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user