connectToServer method
dynamic
connectToServer(
- dynamic tickerList
connect to binance websocket
Implementation
connectToServer(tickerList) {
WebSocketChannel channelHome = IOWebSocketChannel.connect(
Uri.parse('wss://stream.binance.com:9443/ws/stream?'),
);
var subRequestHome = {
'method': "SUBSCRIBE",
'params': tickerList,
'id': 1,
};
var jsonString = json.encode(subRequestHome);
channelHome.sink.add(jsonString);
var result = channelHome.stream.transform(
StreamTransformer<dynamic, dynamic>.fromHandlers(
handleData: (number, sink) {
sink.add(number);
},
),
);
result.listen((event) {
var snapshot = jsonDecode(event);
updateCoin(snapshot['s'].toString(), snapshot['c'].toString(),
snapshot['P'].toString());
});
}