bybit 0.3.0 copy "bybit: ^0.3.0" to clipboard
bybit: ^0.3.0 copied to clipboard

outdated

(Unofficial) Dart library to communicate with the bybit API over REST or WebSockets

pub package BSD License PRs Welcome Watch on GitHub Star on GitHub

ByBit #

ByBit is a Dart package for a communication with the bybit exchange platform API

How to use #

Import the library #

import 'package:bybit/bybit.dart';

Create a ByBit instance #

Use the getInstance function to create an instance of ByBit. Note that the first parameters that you give to the function can't be changed after the first call of getInstance

ByBit bybit = ByBit.getInstance(
        key: 'yOuRsUpErKey',
        password: 'yOuRsUpErPaSsWoRd',
        logLevel: 'INFO',
        restUrl: 'https://api.bybit.com',
        restTimeout: 3000,
        websocketUrl: 'wss://stream.bytick.com/realtime',
        websocketTimeout: 2000);
// otherBybitInstance will have the same parameters as bybit. Doesn't matter what parameters you give here.
ByBit otherBybitInstance = ByBit.getInstance(key: 'OtHeRkEyLoLoLoL', restTimeout: 1000);

Connect #

If you want to use WebSocket streams. If you just want to make REST API calls, no need to connect

bybit.connect();

Subscribe to topics and read stream if you want #

Note that some topics are public and doesn't require a valid api-key and password. If you only want to use public topics, you don't need to pass the key and password to the ByBit.getInstance(...) function.

Note also the websocket.websocket

// ...
bybit.subscribeToKlines(symbol: 'ETHUSD', interval: '1');
bybit.subscribeToKlines(symbol: 'BTCUSD', interval: 'D');
bybit.subscribeToOrderBook(depth: 25);
// ...
StreamBuilder(
    stream: bybit.websocket.websocket.stream,
    builder: (context, bybitResponse) {
          print('From WebSocket: ' + bybitResponse.data.toString());
          //...
    }
),
//...

Make some HTTP request if you want #

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

Example #

See the file example/lib/main.dart for a concrete example of WebSocket (stream) and Future (http) communication

List of functions #

See the doc for the latest avaiable function

8
likes
0
pub points
42%
popularity

Publisher

unverified uploader

(Unofficial) Dart library to communicate with the bybit API over REST or WebSockets

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, flutter, http, logger, sortedmap, web_socket_channel

More

Packages that depend on bybit