pub package BSD License PRs Welcome Last changes CI


ByBit is a Dart library for an easy communication with the bybit exchange platform API. This package allows to make simple REST API calls or to subscribe to several WebSockets channels topics.

How to use it

Create a ByBit instance

Note that all the parameters are optional, but you need a valid key and password to access private topics from bybit. You can create your own api-key on the bybit website.

var bybit = ByBit(
    key: 'yOuRsUpErKey',
    password: 'yOuRsUpErPaSsWoRd',
    logLevel: 'INFO',
    restUrl: '',
    websocketUrl: 'wss://',
    timeout: 60);

Note also that the timeout is given in seconds. If no timeout is given as parameter, no exception will be thrown on timeout.

Connect to the servers


Add periodic REST API call if you want to

Sometimes, you want to get information from the API every x period of time. That's why this library allows one to set which REST API call has to be done periodically, and all the responses from the server are merged into one single stream. Please note the limit of API calls.

bybit.getServerTimePeriodic(period: Duration(seconds: 5));
bybit.getAnnouncementPeriodic(period: Duration(seconds: 5));
    symbol: 'ETHUSD',
    interval: '15min',
    period: Duration(seconds: 2),
    limit: 3);

Subscribe to WebSocket topics

// ...
bybit.subscribeToKlines(symbol: 'ETHUSD', interval: '1');
bybit.subscribeToKlines(symbol: 'BTCUSD', interval: 'D');
bybit.subscribeToOrderBook(depth: 25);

Read the ByBit stream and handle the server response

Note that the streams all the data from the WebSockets and periodic REST API calls.

    builder: (context, bybitResponse) {
        print('From WebSocket: ' +;

You can also make single REST API calls

// ...
    future: bybit.getKLine(symbol: 'BTCUSD', from: 1581231260, interval: 'D'),
    builder: (context, bybitResponse) {
        // Handle the bybit response here
        if (bybitResponse.hasData && != null) {
          print('From REST: ' +;


See the file main.dart in the example/lib/ directory for a simple Dart example. Also, the files main_flutter_stream.dart and main_flutter_future.dart show examples using FutureBuilder and StreamBuilder.

List of functions

See the documentation for the latest avaiable functions.