gateio / gatews

Gate Websocket V4 SDK
89 stars 35 forks source link

[feature] Ping/Pong #17

Closed lucaswxp closed 2 years ago

lucaswxp commented 2 years ago

I was hoping this would work:


    ws, err := gate.NewWsService(nil, nil, gate.NewConnConfFromOption(&gate.ConfOptions{
        Key: exchanges.GATEIO_KEY, Secret: exchanges.GATEIO_SECRET, MaxRetryConn: 10, SkipTlsVerify: false,
    }))

    if err != nil {
        log.Fatal(err)
    }

    pingCb := gate.NewCallBack(func(msg *gate.UpdateMsg) {
        // parse the message to struct we need
        log.Printf("%+v\n", msg)
    })

    ws.SetCallBack("server.ping", pingCb)
    err = ws.Subscribe("server.ping", []string{})

    if err != nil {
        log.Fatal(err)
    }

Response

2021/12/11 00:21:44 &{Time:1639192904 Id:<nil> Channel:ping Event:subscribe Error:Unknown channel ping Result:[110 117 108 108]}

Link: https://www.gate.io/docs/websocket/#ping

revilwang commented 2 years ago

gatews works for WebSocket v4 only. https://www.gate.io/docs/developers/apiv4/ws/en/#system-api