-
Notifications
You must be signed in to change notification settings - Fork 4
/
UtilWebsocket_test.go
65 lines (56 loc) · 1.43 KB
/
UtilWebsocket_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package goghostex
import (
"bytes"
"compress/flate"
"io/ioutil"
"testing"
"time"
)
func Test_time(t *testing.T) {
t.Log(time.Now().Unix())
}
func ProtoHandle(data []byte) error {
println(string(data))
return nil
}
func GzipDecode(in []byte) ([]byte, error) {
reader := flate.NewReader(bytes.NewReader(in))
defer func() { _ = reader.Close() }()
return ioutil.ReadAll(reader)
}
func TestNewWsConn(t *testing.T) {
clientId := "a"
//ts := time.Now().Unix()*1000 + 42029
//args := make([]interface{}, 0)
//args = append(args, ts)
//
//ping := fmt.Sprintf("{\"cmd\":\"ping\",\"args\":[%d],\"id\":\"%s\"}", ts, clientId)
//ping2 := map[string]interface{}{
// "cmd": "ping",
// "id": clientId,
// "args": args}
//ping3, err := json.Marshal(ping2)
//
//fmt.Println(ping)
//fmt.Println(ping2)
//fmt.Println(err, string(ping3))
ws := NewWsBuilder().Dump().WsUrl(
"wss://real.okex.com:8443/ws/v3",
).ProxyUrl(
"socks5://127.0.0.1:1090",
).Heartbeat(
[]byte("ping"),
0,
5*time.Second,
).UnCompressFunc(GzipDecode).ProtoHandleFunc(ProtoHandle).Build()
t.Log(ws.Subscribe(map[string]string{
//"cmd":"sub", "args":"[\"ticker.btcusdt\"]", "id": clientId}))
"cmd": "sub", "args": "ticker.btcusdt", "id": clientId}))
//_ = ws.WriteMessage(
// websocket.TextMessage,
// []byte(`{"channel":"ok_sub_futureusd_btc_depth_quarter","event":"addChannel"}`),
//)
ws.ReceiveMessage()
time.Sleep(time.Second * 20)
ws.CloseWs()
}