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

outdated

A Dart library for WebSocket communication 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 #


getInstance #

connect #

Connect to the WebSocket server and/or the REST API server

disconnect #

Disconnect the websocket and http client

getOrderBook #

Get the orderbook.

official doc

getKLine #

Get kline. official doc

getTickers #

Get the latest information for symbol.

official doc

getTradingRecords #

Get recent trades.

official doc

getSymbolsInfo #

Get symbol info.

official doc

getLiquidatedOrders #

Retrieve the liquidated orders, The query range is the last seven days of data.

official doc

placeActiveOrder #

Place active order

official doc

getActiveOrder #

Get active order

official doc

cancelActiveOrder #

Cancel active order. Note that either orderId or orderLinkId are required

official doc

cancelAllActiveOrders #

Cancel all active orders that are unfilled or partially filled. Fully filled orders cannot

be cancelled.

official doc

updateActiveOrder #

Replace order can modify/amend your active orders.

official doc

getRealTimeActiveOrder #

Query real-time active order information.

official doc

placeConditionalOrder #

Place a market price conditional order

official doc

getConditionalOrders #

Get user conditional order list.

official doc

cancelConditionalOrder #

Cancel untriggered conditional order

official doc

cancelAllConditionalOrders #

Cancel all untriggered conditional orders

official doc

updateConditionalOrder #

Replace conditional order

official doc

getConditionalOrder #

Query conditional order

official doc

getPosition #

Get user position list

official doc

setMargin #

Update margin

official doc

setTradingStop #

Set trading-stop

official doc

setLeverage #

Set leverage

official doc

getUserTradingRecords #

Get user's trading records.

official doc

getUserClosedProfit #

Get user's closed profit and loss records.

official doc

getRiskLimit #

Get risk limit

official doc

setRiskLimit #

Set risk limit

official doc

getFundingRate #

Get the last funding rate

official doc

getPreviousFundingFee #

Get previous funding fee

official doc

getPredictedFundingRateAndFundingFee #

Get predicted funding rate and my funding fee.

official doc

getApiKeyInfo #

Get user's API key information.

official doc

getUserLCP #

Get user's LCP (data refreshes once an hour).

official doc

getWalletBalance #

Get wallet balance

official doc

getWalletFundRecords #

Get wallet fund records.

official doc

getWithdrawalRecords #

Get withdrawal records.

official doc

getAssetExchangeRecords #

Get asset exchange records.

official doc

getServerTime #

Get the server time (used for synchronization purposes for example)

official doc

getAnnouncement #

Get Bybit OpenAPI announcements in the last 30 days in reverse order.

official doc

ping #

Send ping to the WebSocket server

subscribeToKlines #

Subscribe to the KLines channel. A list of valid [interval] values string

is at: official doc

subscribeToOrderBook #

Fetches the orderbook with a [depth] of '25' or '200' orders per side.

is at: official doc

subscribeToTrades #

Get real-time trading information.

official doc

subscribeToInsurance #

Get the daily insurance fund update.

official doc

subscribeToInstrumentInfo #

Get latest information for symbol.

official doc

subscribeToPosition #

Subscribe to the position channel. You need to have a valid api-key in order to receive a valid response from the server

subscribeToExecution #

Private topic to subscribe to with a valid api-Key. See

official doc

subscribeToOrder #

Private topic to subscribe to with a valid api-Key. See

official doc

subscribeToStopOrder #

Private topic to subscribe to with a valid api-Key. See

official doc

8
likes
0
pub points
42%
popularity

Publisher

unverified uploader

A Dart library for WebSocket communication with the bybit API

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, flutter, http, logger, sortedmap, web_socket_channel

More

Packages that depend on bybit