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

Getting "readNumberAsString: invalid number" when getting trades from WebSocket #11

Open
x34v opened this issue Sep 12, 2022 · 1 comment

Comments

@x34v
Copy link

x34v commented Sep 12, 2022

Hello,
I am getting this error when subscribing to trades via websocket:

2022/09/12 19:16:34 BybitWs subscribeHandler
2022/09/12 19:16:35 BybitWs {"topic":"trade.BTCUSDT","data":[{"symbol":"BTCUSDT","tick_direction":"ZeroMinusTick","price":"22230.50","size":0.004,"timestamp":"2022-09-12T17:16:33.000Z","trade_time_ms":"1663002993247","side":"Sell","trade_id":"d6634491-3ffd-537b-8424-e800c5b36f1b","is_block_trade":"false"}]}
2022/09/12 19:16:35 BybitWs []*ws.Trade: ws.Trade.Price: readNumberAsString: invalid number, error found in #10 byte of ...|","price":"22230.50"|..., bigger context ...|BTCUSDT","tick_direction":"ZeroMinusTick","price":"22230.50","size":0.004,"timestamp":"2022-09-12T17|...

This is the code I am using to connect and subscribe to the topic:

cfg := &ws.Configuration{
  Addr:          "wss://stream.bybit.com/realtime_public", 
  ApiKey:        "",
  SecretKey:     "",
  AutoReconnect: true,
  DebugMode:     true,
}
b := ws.New(cfg)
b.Subscribe("trade.BTCUSDT")
b.On(ws.WSTrade, handleTrade)
b.Start()

forever := make(chan struct{})
<-forever

I am not sure if I am doing anything wrong here but it looks like the library for some reason is not able to unmarshal the bybit json to the Trade struct.

@pptav0
Copy link

pptav0 commented Nov 10, 2022

Hi.... I get into same error, after following the source code, I found that websocket for Linear contract returns some fields (prices, size) in wrong data type as defined in Struct. Check them and adjust as your convinience.

["price":"22230.50"|

Regards

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

2 participants