1 Star 0 Fork 1

小栈/GoEx

forked from simonxing/GoEx 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
websocket_test.go 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
btstar 提交于 2019-06-22 13:53 . add ws for fcoin
package goex
import (
"encoding/json"
"fmt"
"testing"
"time"
)
func Test_time(t *testing.T) {
t.Log(time.Now().Unix())
}
func ProtoHandle(data []byte) error {
println(string(data))
return nil
}
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://api.fcoin.com/v2/ws").ProxyUrl("socks5://127.0.0.1:1080").
Heartbeat([]byte(ping3), 5*time.Second).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.ReceiveMessage()
time.Sleep(time.Second * 20)
ws.CloseWs()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiaozhan/GoEx.git
git@gitee.com:xiaozhan/GoEx.git
xiaozhan
GoEx
GoEx
master

搜索帮助