đź”— Visit Live Web App
Tip: You can switch currencies by tapping on the currency Symbols.
Tip: You can change your desired duration. i.e. 1m, 3m or 1d etc.
Tip: You can scroll up and down to zoom-in and zoom-out.
WebSocketChannel establishConnection(String symbol, String interval) {
final channel = WebSocketChannel.connect(
Uri.parse('wss://stream.binance.com:9443/ws'),
);
channel.sink.add(
jsonEncode(
{
"method": "SUBSCRIBE",
"params": ["$symbol@kline_$interval"],
"id": 1
},
),
);
return channel;
}
Future<List<Candle>> fetchCandles(
{required String symbol, required String interval, int? endTime}) async {
final uri = Uri.parse(
"https://api.binance.com/api/v3/klines?symbol=$symbol&interval=$interval${endTime != null ? "&endTime=$endTime" : ""}");
final res = await http.get(uri);
return (jsonDecode(res.body) as List<dynamic>)
.map((e) => Candle.fromJson(e))
.toList()
.reversed
.toList();
}
Future<List<String>> fetchSymbols() async {
final uri = Uri.parse("https://api.binance.com/api/v3/ticker/price");
final res = await http.get(uri);
return (jsonDecode(res.body) as List<dynamic>)
.map((e) => e["symbol"] as String)
.toList();
}
dependencies:
# Flutter SDK
flutter:
sdk: flutter
# Dependency for Icons
cupertino_icons: ^1.0.2
# Dependency for HTTP Calls
http: ^0.13.3
# Dependency for Web Socket Channels
web_socket_channel: ^2.1.0