bybit 0.2.0 bybit: ^0.2.0 copied to clipboard
(Unofficial) Dart library to communicate with the bybit API
ByBit #
ByBit is a Dart package for a communication with the bybit exchange platform API
Table of content #
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