bybit 0.1.0 bybit: ^0.1.0 copied to clipboard
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 #
- Initialization:
- Market data endpoints:
- Account data endpoints:
- Active orders:
- Conditional orders:
- Position:
- Risk limit:
- Funding:
- API key information:
- LCP information:
- Wallet
- API data endpoints:
- WebSocket data:
getInstance #
connect #
Connect to the WebSocket server and/or the REST API server
disconnect #
Disconnect the websocket and http client
getOrderBook #
Get the orderbook.
getKLine #
Get kline. official doc
getTickers #
Get the latest information for symbol.
getTradingRecords #
Get recent trades.
getSymbolsInfo #
Get symbol info.
getLiquidatedOrders #
Retrieve the liquidated orders, The query range is the last seven days of data.
placeActiveOrder #
Place active order
getActiveOrder #
Get active order
cancelActiveOrder #
Cancel active order. Note that either orderId or orderLinkId are required
cancelAllActiveOrders #
Cancel all active orders that are unfilled or partially filled. Fully filled orders cannot
be cancelled.
updateActiveOrder #
Replace order can modify/amend your active orders.
getRealTimeActiveOrder #
Query real-time active order information.
placeConditionalOrder #
Place a market price conditional order
getConditionalOrders #
Get user conditional order list.
cancelConditionalOrder #
Cancel untriggered conditional order
cancelAllConditionalOrders #
Cancel all untriggered conditional orders
updateConditionalOrder #
Replace conditional order
getConditionalOrder #
Query conditional order
getPosition #
Get user position list
setMargin #
Update margin
setTradingStop #
Set trading-stop
setLeverage #
Set leverage
getUserTradingRecords #
Get user's trading records.
getUserClosedProfit #
Get user's closed profit and loss records.
getRiskLimit #
Get risk limit
setRiskLimit #
Set risk limit
getFundingRate #
Get the last funding rate
getPreviousFundingFee #
Get previous funding fee
getPredictedFundingRateAndFundingFee #
Get predicted funding rate and my funding fee.
getApiKeyInfo #
Get user's API key information.
getUserLCP #
Get user's LCP (data refreshes once an hour).
getWalletBalance #
Get wallet balance
getWalletFundRecords #
Get wallet fund records.
getWithdrawalRecords #
Get withdrawal records.
getAssetExchangeRecords #
Get asset exchange records.
getServerTime #
Get the server time (used for synchronization purposes for example)
getAnnouncement #
Get Bybit OpenAPI announcements in the last 30 days in reverse order.
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.
subscribeToInsurance #
Get the daily insurance fund update.
subscribeToInstrumentInfo #
Get latest information for symbol.
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
subscribeToOrder #
Private topic to subscribe to with a valid api-Key. See
subscribeToStopOrder #
Private topic to subscribe to with a valid api-Key. See