-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.dart
39 lines (32 loc) · 1.02 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'package:bybit/bybit.dart';
/// Read X ([count]) messages from a stream.
Future<void> readWebSocket(Stream<dynamic> stream, int count) async {
var i = 0;
await for (var value in stream) {
i++;
print(value);
if (i >= count) return;
}
}
void main() async {
var bybit = ByBit(logLevel: 'INFO');
// Connect to the Server
bybit.connect();
// Define REST API calls that we want to make periodically
bybit.getServerTimePeriodic(period: Duration(seconds: 5));
bybit.getAnnouncementPeriodic(period: Duration(seconds: 5));
bybit.getOpenInterestPeriodic(
symbol: 'ETHUSD',
interval: '15min',
period: Duration(seconds: 2),
limit: 3);
// Subscribe to WebSockets channels
bybit.subscribeToKlines(symbol: 'BTCUSD', interval: 'D');
// Show the stream output
await readWebSocket(bybit.stream, 10);
// Once the 10 first server response are shown, make a single REST API call
var symbols = await bybit.getSymbolsInfo();
print(symbols);
// Close sockets
bybit.disconnect();
}