connectToBinanceServer method
dynamic
connectToBinanceServer(
- Coin coinData,
- String interval
)
Implementation
connectToBinanceServer(Coin coinData, String interval) {
channelHome.sink.close();
channelHome = IOWebSocketChannel.connect(
Uri.parse('wss://stream.binance.com:9443/ws/stream?'),
);
var subRequestHome = {
'method': "SUBSCRIBE",
'params': ['${coinData.shortName.toLowerCase()}usdt@kline_$interval'],
'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);
updateCoinGraph(snapshot, coinData);
});
}