wisespace-io / binance-rs

Rust Library for the Binance API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Websocket, DayTickerEvent is no longer a vector in Single Symbol Tickers.

McYoloSwagHam opened this issue · comments

Line 103 in websockets.rs

                        } else if msg.find(DAYTICKER) != None {
                            let trades: Vec<DayTickerEvent> = from_str(msg.as_str())?;
                            (self.handler)(WebsocketEvent::DayTicker(trades))?;

according to my debugging, msg.as_str() returns a json structure that isn't an array

(gdb) p msg.as_str()
$4 = "{\"e\":\"24hrTicker\",\"E\":1600800387836,\"s\":\"BCHUSDT\",\"p\":\"1.36000000\",\"P\":\"0.639\",\"w\":\"213.85752497\",\"x\":\"212.96000000\",\"c\":\"214.34000000\",\"Q\":\"0.23330000\",\"b\":\"214.23000000\",\"B\":\"30.39787000\",\"a\":\"214.28000000\",\"A\":\"1.71200000\",\"o\":\"212.98000000\",\"h\":\"215.99000000\",\"l\":\"210.48000000\",\"v\":\"72448.37057000\",\"q\":\"15493629.21838270\",\"O\":1600713979263,\"C\":1600800379263,\"F\":31831182,\"L\":31867465,\"n\":36284}"

The way to fix this would be

To change the type to not be a Vec in that code, and in the Enum WebsocketEvents, for individual tickers this is the case

@McYoloSwagHam I released a new version with a possible fix. Now, we have DayTicker and DayTickerAll

If you want an individual symbol, you should use DayTicker, see example.

https://github.com/wisespace-io/binance-rs/blob/master/examples/binance_websockets.rs#L168

In case of all Symbols, you should use DayTickerAll

https://github.com/wisespace-io/binance-rs/blob/master/examples/binance_websockets.rs#L120

It is because the request to the stream !ticker@arr still returns an array as stated in the docs:

https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-tickers-stream