ByBit class
That class opens a WebSocket to communicate with the bybit API You can subscribes to several topics over that WebSocket To see a complete list of all endpoints, see https://bybit-exchange.github.io/docs/inverse/#t-websocket
Constructors
- ByBit({String key = '', String password = '', String restUrl = 'https://api.bybit.com', String websocketUrl = 'wss://stream.bybit.com/realtime', int timeout = -1, int pingPeriod = 30, int receiveWindow = 1000, String logLevel = 'WARNING'})
-
The constructor use default parameters without api-key.
If you want to use all endpoints, you must provite a valid
key and password. Go to https://www.bybit.com/app/user/api-management
To generate your key. If you're using the websockets, a ping will be
sent every pingPeriod seconds to the server to maintain connection.
If no message is received from the Server within
timeout
seconds, an exception will be thrown. The receiveWindow must be given in milliseconds and prevents replay attacks. See https://bybit-exchange.github.io/docs/inverse/?console#t-authentication
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- key ↔ String
-
API-key
getter/setter pair
- log ↔ LoggerSingleton
-
For easy debugging
getter/setter pair
- password ↔ String
-
API-key password
getter/setter pair
- pingPeriod ↔ int
-
Period between pings send to WebSocketServer to keep connection
getter/setter pair
- receiveWindow ↔ int
-
getter/setter pair
- rest ↔ ByBitRest
-
Used for the REST communication with bybit.
getter/setter pair
- restUrl ↔ String
-
REST url used
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
↔ Stream<
Map< ?String, dynamic> ?> -
Stream that remaps the websocket and periodic REST calls into
one stream output of json.
getter/setter pair
-
streamGroup
↔ StreamGroup<
Map< String, dynamic> ?> -
Groupe the REST periodic api calls and the websocket stream into one group
getter/setter pair
- timeout ↔ Duration?
-
Communication timeout value
getter/setter pair
- websocket ↔ ByBitWebSocket
-
Used for the websocket connection with bybit.
getter/setter pair
- websocketUrl ↔ String
-
WebSocket url used
getter/setter pair
Methods
-
cancelActiveOrder(
{required String symbol, String? orderId, String? orderLinkId}) → Future< Map< String, dynamic> ?> - Cancel active order. Note that either orderId or orderLinkId are required https://bybit-exchange.github.io/docs/inverse/#t-cancelactive
-
cancelActiveOrderPeriodic(
{required String symbol, String? orderId, String? orderLinkId, required Duration period}) → void - Cancel active order periodically. Note that either orderId or orderLinkId are required https://bybit-exchange.github.io/docs/inverse/#t-cancelactive
-
cancelAllActiveOrders(
{required String symbol}) → Future< Map< String, dynamic> ?> - Cancel all active orders that are unfilled or partially filled. Fully filled orders cannot be cancelled. https://bybit-exchange.github.io/docs/inverse/#t-cancelallactive
-
cancelAllActiveOrdersPeriodic(
{required String symbol, required Duration period}) → void - Cancel all active orders that are unfilled or partially filled periodically. Fully filled orders cannot be cancelled. https://bybit-exchange.github.io/docs/inverse/#t-cancelallactive
-
cancelAllConditionalOrders(
{required String symbol}) → Future< Map< String, dynamic> ?> - Cancel all untriggered conditional orders https://bybit-exchange.github.io/docs/inverse/#t-cancelallcond
-
cancelAllConditionalOrdersPeriodic(
{required String symbol, required Duration period}) → void - Cancel all untriggered conditional orders periodically. https://bybit-exchange.github.io/docs/inverse/#t-cancelallcond
-
cancelConditionalOrder(
{required String symbol, String? orderId, String? orderLinkId}) → Future< Map< String, dynamic> ?> - Cancel untriggered conditional order https://bybit-exchange.github.io/docs/inverse/#t-cancelcond
-
cancelConditionalOrderPeriodic(
{required String symbol, String? orderId, String? orderLinkId, required Duration period}) → void - Cancel untriggered conditional order periodically. https://bybit-exchange.github.io/docs/inverse/#t-cancelcond
-
connect(
{bool toWebSocket = true, bool toRestApi = true}) → void - Connect to the WebSocket server and/or the REST API server
-
crossIsolatedMarginSwitch(
{required String symbol, required bool isIsolated, required double buyLeverage, required double sellLeverage}) → Future< Map< String, dynamic> ?> - Switch Cross/Isolated; must set leverage value when switching from Cross to Isolated. https://bybit-exchange.github.io/docs/inverse/#t-marginswitch
-
disconnect(
) → void - Disconnect the websocket and http client
-
fullPartialPositionTPSLSwitch(
{required String symbol, required String tpSlMode}) → Future< Map< String, dynamic> ?> - Full/Partial Position TP/SL Switch : Switch mode between Full or Partial https://bybit-exchange.github.io/docs/inverse/#t-switchmode
-
getActiveOrder(
{required String symbol, String? orderStatus, String? direction, int? limit, String? cursor}) → Future< Map< String, dynamic> ?> - Get active order https://bybit-exchange.github.io/docs/inverse/?console#t-getactive
-
getActiveOrderPeriodic(
{required String symbol, String? orderStatus, String? direction, int? limit, String? cursor, required Duration period}) → void - Get active order periodically https://bybit-exchange.github.io/docs/inverse/?console#t-getactive
-
getAnnouncement(
) → Future< Map< String, dynamic> ?> - Get Bybit OpenAPI announcements in the last 30 days in reverse order. https://bybit-exchange.github.io/docs/inverse/?console#t-announcement
-
getAnnouncementPeriodic(
{required Duration period}) → void - Get Bybit OpenAPI announcements in the last 30 days in reverse order periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-announcement
-
getApiKeyInfo(
) → Future< Map< String, dynamic> ?> - Get user's API key information. https://bybit-exchange.github.io/docs/inverse/#t-key
-
getApiKeyInfoPeriodic(
{required Duration period}) → void - Get user's API key information periodically. https://bybit-exchange.github.io/docs/inverse/#t-key
-
getAssetExchangeRecords(
{String? direction, int? from, int? limit}) → Future< Map< String, dynamic> ?> - Get asset exchange records. https://bybit-exchange.github.io/docs/inverse/#t-assetexchangerecords
-
getAssetExchangeRecordsPeriodic(
{String? direction, int? from, int? limit, required Duration period}) → void - Get asset exchange records periodically. https://bybit-exchange.github.io/docs/inverse/#t-assetexchangerecords
-
getConditionalOrder(
{required String symbol, String? stopOrderId, String? orderLinkId}) → Future< Map< String, dynamic> ?> - Query conditional order https://bybit-exchange.github.io/docs/inverse/#t-querycond
-
getConditionalOrderPeriodic(
{required String symbol, String? stopOrderId, String? orderLinkId, required Duration period}) → void - Query conditional order periodically. https://bybit-exchange.github.io/docs/inverse/#t-querycond
-
getConditionalOrders(
{required String symbol, String? stopOrderStatus, String? direction, int? limit, String? cursor}) → Future< Map< String, dynamic> ?> - Get user conditional order list. https://bybit-exchange.github.io/docs/inverse/#t-getcond
-
getConditionalOrdersPeriodic(
{required String symbol, String? stopOrderStatus, String? direction, int? limit, String? cursor, required Duration period}) → void - Get user conditional order list periodically. https://bybit-exchange.github.io/docs/inverse/#t-getcond
-
getFundingRate(
{required String symbol}) → Future< Map< String, dynamic> ?> - Get the last funding rate https://bybit-exchange.github.io/docs/inverse/#t-fundingrate
-
getFundingRatePeriodic(
{required String symbol, required Duration period}) → void - Get the last funding rate periodically. https://bybit-exchange.github.io/docs/inverse/#t-fundingrate
-
getKLine(
{required String symbol, required String interval, required int from, int limit = -1}) → Future< Map< String, dynamic> ?> - Get kline. https://bybit-exchange.github.io/docs/inverse/?console#t-querykline
-
getKLinePeriodic(
{required String symbol, required String interval, required int from, int? limit, required Duration period}) → void - Get kline periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-querykline
-
getLatestBigDeals(
{required String symbol, int? limit}) → Future< Map< String, dynamic> ?> - Obtain filled orders worth more than 500,000 USD within the last 24h.
-
getLatestBigDealsPeriodic(
{required String symbol, int? limit, required Duration period}) → void - Obtain filled orders worth more than 500,000 USD within the last 24h, periodically.
-
getLongShortRatio(
{required String symbol, required String interval, int? limit}) → Future< Map< String, dynamic> ?> - Gets the Bybit user accounts' long-short ratio.
-
getLongShortRatioPeriodic(
{required String symbol, required String interval, int? limit, required Duration period}) → void - Gets the Bybit user accounts' long-short ratio periodically
-
getMarkPriceKLine(
{required String symbol, required String interval, required int from, int? limit}) → Future< Map< String, dynamic> ?> - Query mark price kline (like Query Kline but for mark price).
-
getMarkPriceKLinePeriodic(
{required String symbol, required String interval, required int from, int? limit, required Duration period}) → void - Query mark price kline (like Query Kline but for mark price) periodically
-
getOpenInterest(
{required String symbol, required String interval, int? limit}) → Future< Map< String, dynamic> ?> - Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions.
-
getOpenInterestPeriodic(
{required String symbol, required String interval, int? limit, required Duration period}) → void -
Gets the total amount of unsettled contracts periodically.
In other words, get the total number of contracts held in open positions
every
period
. -
getOrderBook(
{required String symbol}) → Future< Map< String, dynamic> ?> - Get the orderbook. https://bybit-exchange.github.io/docs/inverse/?console#t-orderbook
-
getOrderBookPeriodic(
{required String symbol, required Duration period}) → void - Add a periodic call to the order book REST API. https://bybit-exchange.github.io/docs/inverse/?console#t-orderbook
-
getPosition(
{String? symbol}) → Future< Map< String, dynamic> ?> - Get user position list https://bybit-exchange.github.io/docs/inverse/?console#t-myposition
-
getPositionPeriodic(
{String? symbol, required Duration period}) → void - Get user position list periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-myposition
-
getPredictedFundingRateAndFundingFee(
{required String symbol}) → Future< Map< String, dynamic> ?> - Get predicted funding rate and my funding fee. https://bybit-exchange.github.io/docs/inverse/#t-predictedfunding
-
getPredictedFundingRateAndFundingFeePeriodic(
{required String symbol, required Duration period}) → void - Get predicted funding rate and my funding fee periodically. https://bybit-exchange.github.io/docs/inverse/#t-predictedfunding
-
getPreviousFundingFee(
{required String symbol}) → Future< Map< String, dynamic> ?> - Get previous funding fee https://bybit-exchange.github.io/docs/inverse/#t-mylastfundingfee
-
getPreviousFundingFeePeriodic(
{required String symbol, required Duration period}) → void - Get previous funding fee periodically. https://bybit-exchange.github.io/docs/inverse/#t-mylastfundingfee
-
getRealTimeActiveOrder(
{required String symbol, String? orderId, String? orderLinkId}) → Future< Map< String, dynamic> ?> - Query real-time active order information. https://bybit-exchange.github.io/docs/inverse/#t-queryactive
-
getRealTimeActiveOrderPeriodic(
{required String symbol, String? orderId, String? orderLinkId, required Duration period}) → void - Query real-time active order information periodically. https://bybit-exchange.github.io/docs/inverse/#t-queryactive
-
getRiskLimit(
) → Future< Map< String, dynamic> ?> - Get risk limit https://bybit-exchange.github.io/docs/inverse/#t-risklimit
-
getRiskLimitPeriodic(
{required Duration period}) → void - Get risk limit periodically. https://bybit-exchange.github.io/docs/inverse/#t-risklimit
-
getServerTime(
) → Future< Map< String, dynamic> ?> - Get the server time (used for synchronization purposes for example) https://bybit-exchange.github.io/docs/inverse/?console#t-servertime
-
getServerTimePeriodic(
{required Duration period}) → void - Get the server time (used for synchronization purposes for example) periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-servertime
-
getSymbolsInfo(
) → Future< Map< String, dynamic> ?> - Get the information for all symbols. https://bybit-exchange.github.io/docs/inverse/?console#t-querysymbol
-
getSymbolsInfoPeriodic(
{required Duration period}) → void - Get the information for all symbols periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-querysymbol
-
getTickers(
{String? symbol}) → Future< Map< String, dynamic> ?> - Get the latest information for symbol. https://bybit-exchange.github.io/docs/inverse/?console#t-latestsymbolinfo
-
getTickersPeriodic(
{String? symbol, required Duration period}) → void - Get the latest information for symbols periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-latestsymbolinfo
-
getTradingFeeRate(
{required String symbol}) → Future< Map< String, dynamic> ?> - Get trading fee rate for a given symbol https://bybit-exchange.github.io/docs/inverse/#t-queryfeerate
-
getTradingRecords(
{required String symbol, int? limit}) → Future< Map< String, dynamic> ?> - Get recent trades.
-
getTradingRecordsPeriodic(
{required String symbol, int? from, int? limit, required Duration period}) → void - Get recent trades periodically.
-
getUserClosedProfit(
{required String symbol, int? startTime, int? endTime, String? execType, int? page, int? limit}) → Future< Map< String, dynamic> ?> - Get user's closed profit and loss records. https://bybit-exchange.github.io/docs/inverse/#t-closedprofitandloss
-
getUserClosedProfitPeriodic(
{required String symbol, int? startTime, int? endTime, String? execType, int? page, int? limit, required Duration period}) → void - Get user's closed profit and loss records periodically. https://bybit-exchange.github.io/docs/inverse/#t-closedprofitandloss
-
getUserLCP(
{required String symbol}) → Future< Map< String, dynamic> ?> - Get user's LCP (data refreshes once an hour). https://bybit-exchange.github.io/docs/inverse/#t-lcp
-
getUserLCPPeriodic(
{required String symbol, required Duration period}) → void - Get user's LCP (data refreshes once an hour) periodically. https://bybit-exchange.github.io/docs/inverse/#t-lcp
-
getUserTradingRecords(
{required String symbol, String? orderId, int? startTime, int? page, int? limit, String? order}) → Future< Map< String, dynamic> ?> - Get user's trading records. https://bybit-exchange.github.io/docs/inverse/#t-usertraderecords
-
getUserTradingRecordsPeriodic(
{required String symbol, String? orderId, int? startTime, int? page, int? limit, String? order, required Duration period}) → void - Get user's trading records periodically. https://bybit-exchange.github.io/docs/inverse/#t-usertraderecords
-
getWalletBalance(
{String? currency}) → Future< Map< String, dynamic> ?> - Get wallet balance https://bybit-exchange.github.io/docs/inverse/#t-wallet
-
getWalletBalancePeriodic(
{String? currency, required Duration period}) → void - Get wallet balance periodically. https://bybit-exchange.github.io/docs/inverse/#t-wallet
-
getWalletFundRecords(
{String? currency, int? startTimestamp, int? endTimestamp, String? walletFundType, int? page, int? limit}) → Future< Map< String, dynamic> ?> - Get wallet fund records. https://bybit-exchange.github.io/docs/inverse/#t-walletrecords
-
getWalletFundRecordsPeriodic(
{String? currency, int? startTimestamp, int? endTimestamp, String? walletFundType, int? page, int? limit, required Duration period}) → void - Get wallet fund records periodically. https://bybit-exchange.github.io/docs/inverse/#t-walletrecords
-
getWithdrawalRecords(
{String? currency, int? startTimestamp, int? endTimestamp, String? status, int? page, int? limit}) → Future< Map< String, dynamic> ?> - Get withdrawal records. https://bybit-exchange.github.io/docs/inverse/#t-withdrawrecords
-
getWithdrawalRecordsPeriodic(
{String? currency, int? startTimestamp, int? endTimestamp, String? status, int? page, int? limit, required Duration period}) → void - Get withdrawal records periodically. https://bybit-exchange.github.io/docs/inverse/#t-withdrawrecords
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ping(
) → void - Send ping to the WebSocket server
-
placeActiveOrder(
{required String symbol, required String side, required String orderType, required int quantity, required String timeInForce, double? price, double? takeProfit, double? stopLoss, bool? reduceOnly, bool? closeOnTrigger, String? orderLinkId}) → Future< Map< String, dynamic> ?> - Place active order https://bybit-exchange.github.io/docs/inverse/?console#t-placeactive
-
placeActiveOrderPeriodic(
{required String symbol, required String side, required String orderType, required int quantity, required String timeInForce, double? price, double? takeProfit, double? stopLoss, bool? reduceOnly, bool? closeOnTrigger, String? orderLinkId, required Duration period}) → void - Place active order periodically. https://bybit-exchange.github.io/docs/inverse/?console#t-placeactive
-
placeConditionalOrder(
{required String symbol, required String side, required String orderType, required int quantity, double? price, required double basePrice, required double triggerPrice, required String timeInForce, String? triggerBy, bool? closeOnTrigger, String? orderLinkId}) → Future< Map< String, dynamic> ?> - Place a market price conditional order https://bybit-exchange.github.io/docs/inverse/#t-placecond
-
placeConditionalOrderPeriodic(
{required String symbol, required String side, required String orderType, required int quantity, double? price, required double basePrice, required double triggerPrice, required String timeInForce, String? triggerBy, bool? closeOnTrigger, String? orderLinkId, required Duration period}) → void - Place a market price conditional order periodically. https://bybit-exchange.github.io/docs/inverse/#t-placecond
-
setLeverage(
{required String symbol, required double leverage}) → Future< Map< String, dynamic> ?> - Set leverage https://bybit-exchange.github.io/docs/inverse/#t-setleverage
-
setLeveragePeriodic(
{required String symbol, required double leverage, required Duration period}) → void - Set leverage periodically. https://bybit-exchange.github.io/docs/inverse/#t-setleverage
-
setMargin(
{required String symbol, required double margin}) → Future< Map< String, dynamic> ?> - Update margin https://bybit-exchange.github.io/docs/inverse/#t-changemargin
-
setMarginPeriodic(
{required String symbol, required double margin, required Duration period}) → void - Update margin periodically. https://bybit-exchange.github.io/docs/inverse/#t-changemargin
-
setRiskLimit(
{required String symbol, required int riskId}) → Future< Map< String, dynamic> ?> - Set risk limit https://bybit-exchange.github.io/docs/inverse/#t-setrisklimit
-
setRiskLimitPeriodic(
{required String symbol, required int riskId, required Duration period}) → void - Set risk limit periodically. https://bybit-exchange.github.io/docs/inverse/#t-setrisklimit
-
setTradingStop(
{required String symbol, double? takeProfit, double? stopLoss, double? trailingStop, String? tpTriggerBy, String? slTriggerBy, double? newTrailingTriggerPrice}) → Future< Map< String, dynamic> ?> - Set trading-stop https://bybit-exchange.github.io/docs/inverse/#t-tradingstop
-
setTradingStopPeriodic(
{required String symbol, double? takeProfit, double? stopLoss, double? trailingStop, String? tpTriggerBy, String? slTriggerBy, double? newTrailingTriggerPrice, required Duration period}) → void - Set trading-stop periodically. https://bybit-exchange.github.io/docs/inverse/#t-tradingstop
-
subscribeToExecution(
) → void - Private topic to subscribe to with a valid api-Key. See https://bybit-exchange.github.io/docs/inverse/#t-websocketexecution
-
subscribeToInstrumentInfo(
{required String symbol}) → void - Get latest information for symbol. https://bybit-exchange.github.io/docs/inverse/#t-websocketinstrumentinfo
-
subscribeToInsurance(
{String currency = ''}) → void - Get the daily insurance fund update. https://bybit-exchange.github.io/docs/inverse/#t-websocketinsurance
-
subscribeToKlines(
{required String symbol, required String interval}) → void -
Subscribe to the KLines channel. A list of valid
interval
values string is at: https://bybit-exchange.github.io/docs/inverse/#t-websocketklinev2 -
subscribeToOrder(
) → void - Private topic to subscribe to with a valid api-Key. See https://bybit-exchange.github.io/docs/inverse/#t-websocketorder
-
subscribeToOrderBook(
{required int depth, String symbol = ''}) → void -
Fetches the orderbook with a
depth
of '25' or '200' orders per side. is at: https://bybit-exchange.github.io/docs/inverse/#t-websocketorderbook25 -
subscribeToPosition(
) → void - Subscribe to the position channel. You need to have a valid api-key in order to receive a valid response from the server https://bybit-exchange.github.io/docs/inverse/#t-websocketposition
-
subscribeToStopOrder(
) → void - Private topic to subscribe to with a valid api-Key. See https://bybit-exchange.github.io/docs/inverse/#t-websocketstoporder
-
subscribeToTrades(
{String symbol = ''}) → void - Get real-time trading information. https://bybit-exchange.github.io/docs/inverse/#t-websockettrade
-
toString(
) → String -
A string representation of this object.
inherited
-
updateActiveOrder(
{required String symbol, String? orderId, String? orderLinkId, int? newOrderQuantity, double? newOrderPrice}) → Future< Map< String, dynamic> ?> - Replace order can modify/amend your active orders. https://bybit-exchange.github.io/docs/inverse/#t-replaceactive
-
updateActiveOrderPeriodic(
{required String symbol, String? orderId, String? orderLinkId, int? newOrderQuantity, double? newOrderPrice, required Duration period}) → void - Replace order can modify/amend your active orders periodically. https://bybit-exchange.github.io/docs/inverse/#t-replaceactive
-
updateConditionalOrder(
{required String symbol, String? stopOrderId, String? orderLinkId, int? newOrderQuantity, double? newOrderPrice, double? newTriggerPrice}) → Future< Map< String, dynamic> ?> - Update conditional order https://bybit-exchange.github.io/docs/inverse/#t-replacecond
-
updateConditionalOrderPeriodic(
{required String symbol, String? stopOrderId, String? orderLinkId, int? newOrderQuantity, double? newOrderPrice, double? newTriggerPrice, required Duration period}) → void - Update conditional order periodically. https://bybit-exchange.github.io/docs/inverse/#t-replacecond
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited