Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when listenKey expired get error:json: cannot unmarshal string into Go struct field WsUserDataEvent.E of type int64 #524

Open
csquan opened this issue Nov 9, 2023 · 2 comments

Comments

@csquan
Copy link

csquan commented Nov 9, 2023

when listenKey expired get error:json: cannot unmarshal string into Go struct field WsUserDataEvent.E of type int64?
about an hour,which code should like this :

doneC, stopC, err := futures.WsUserDataServe(listenKey, func(event *futures.WsUserDataEvent) {
logrus.Info("****receive followed order data:")
logrus.Info(event)
switch event.Event {
case "ORDER_TRADE_UPDATE":

	case "listenKeyExpired":
		logrus.Info("receive listenKey expired signal")
		err = binanceClient.NewKeepaliveUserStreamService().ListenKey(listenKey).Do(context.Background())
		if err != nil {
			logrus.Info("receive listenKey expired signal,keep alive error,remove form followList, exit and retry new listenKey")
			//remove uid form
			delete(followList, uid)
			return
		}
	}
}, func(err error) {

//when listenKey expired,get error:json: cannot unmarshal string into Go struct field WsUserDataEvent.E of type int64
logrus.Error(err)
})
see above code ,what happned?

@csquan
Copy link
Author

csquan commented Nov 9, 2023

func WsUserDataServe(listenKey string, handler WsUserDataHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) {
endpoint := fmt.Sprintf("%s/%s", getWsEndpoint(), listenKey)
cfg := newWsConfig(endpoint)
wsHandler := func(message []byte) {
event := new(WsUserDataEvent)
err := json.Unmarshal(message, event)
if err != nil {
errHandler(err) //here error happen
return
}
handler(event)
}
return wsServe(cfg, wsHandler, errHandler)
}

when key expired,message:{"e": "listenKeyExpired","E": "1699520437418","listenKey": "eKCFWuorbdKFRW27XzMmVva76epP8F2zSpPrQTlXESDBsQAXFHennNf3A7GsyCqT"}
then json.Unmarshal(message, event) error

@csquan
Copy link
Author

csquan commented Nov 9, 2023

binance api problem:

{"e": "listenKeyExpired","E": "1699520437418","listenKey": "eKCFWuorbdKFRW27XzMmVva76epP8F2zSpPrQTlXESDBsQAXFHennNf3A7GsyCqT"}

{"e":"ORDER_TRADE_UPDATE","T":1699521504258,"E":1699521504260,"o":{"s":"DOGEUSDT","c":"ios_bdoSoCTJC3xJ5mpHM8BK","S":"SELL","o":"LIMIT","f":"GTC","q":"131","p":"0.610000","ap":"0","sp":"0","x":"NEW","X":"NEW","i":34611865748,"l":"0","z":"0","L":"0","n":"0","N":"USDT","T":1699521504258,"t":0,"b":"0","a":"229.188000","m":false,"R":false,"wt":"CONTRACT_PRICE","ot":"LIMIT","ps":"SHORT","cp":false,"rp":"0","pP":false,"si":0,"ss":0,"V":"NONE","pm":"NONE","gtd":0}}

which you would see type of E is different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant