Currently, the API supported version is V5. The V5 API brings uniformity and efficiency to Bybit's product lines, unifying Spot, Derivatives, and Options in one set of specifications.
OpenAPI Version | Account Type | Linear | Inverse | Spot | Options | |||
---|---|---|---|---|---|---|---|---|
USDT Perpetual | USDC Perpetual | USDC Futures | Perpetual | Futures | ||||
V5 | Unified trading account | ✓ | ✓ | ✓ | see note | ✓ | ✓ | |
Classic account | ✓ | ✓ | ✓ | ✓ | ||||
V3 | Unified trading account | ✓ | ✓ | ✓ | ||||
Classic account | ✓ | ✓ | ✓ | ✓ |
*Note: the Unified account supports inverse trading. However, the margin used is from the inverse derivatives wallet instead of the unified wallet.
You can configure the following properties in the Bybit property.
When the client successfully connects to Bybit servers, the event OnConnect is fired. After the event OnConnect is fired, then you can start to send and receive messages to/from Bybit servers. If you are connecting to the private websocket channel, you must wait till OnBybitAuthentication event is fired and check if the success parameter is true, before subscribe to any channel.
The client supports several APIs, so use the property BybitClient to set which API you want to use:
Find below an example of connecting to WebSocket Spot Private API.
oClient := TsgcWebSocketClient.Create(nil);
oBybit := TsgcWSAPI_Bybit.Create(nil);
oBybit.Client := oClient;
oBybit.Bybit.ApiKey := 'alsdjk23kandfnasbdfdkjhsdf';
oBybit.Bybit.ApiSecret := 'aldskjfk3jkadknfajndsjfj23j';
oBybit.BybitClient := bybSpot;
oClient.Active := True;
procedure OnConnect(Connection: TsgcWSConnection);
begin
DoLog('#Bybit Connected');
end;
After a successfull connection to the Spot WebSocket Server, you can start to subscribe to WebSocket channels, just access the SPOT property and then call any of the subscribe/unsubscribe methods available.
The bybit client implements the following events to control the connection flow and get data sent from the WebSocket server:
The websocket feed provides real-time market data updates for orders and trades. The websocket feed has some public channels like ticker, trades...
You can subscribe to the following channels:
Method | Public or Private | Description |
SubscribeOrderBook | Public | Subscribe to the orderbook stream. Supports different depths. |
SubscribeTrade | Public | Subscribe to the recent trades stream. |
SubscribeTicker | Public | Subscribe to the ticker stream. |
SubscribeKLine | Public | Subscribe to the klines stream. |
SubscribeLiquidation | Public | Subscribe to the liquidation stream |
SubscribeLT_KLine | Public |
Subscribe to the leveraged token kline stream. |
SubscribeLT_Ticker | Public | Subscribe to the leveraged token ticker stream. |
SubscribeLT_Nav | Public | Subscribe to the leveraged token ticker stream. |
SubscribePosition | Private | Subscribe to the leveraged token nav stream. |
SubscribeExecution | Private | Subscribe |
SubscribeOrder | Private | Subscribe |
SubscribeWallet | Private | Subscribe |
SubscribeGreek | Private | Subscribe |
SubscribeDcp | Private | Subscribe |
Find below an example of subscribing to private websocket channels after a successful authentication.
oClient := TsgcWebSocketClient.Create(nil);
oBybit := TsgcWSAPI_Bybit.Create(nil);
oBybit.Client := oClient;
oBybit.Bybit.ApiKey := 'alsdjk23kandfnasbdfdkjhsdf';
oBybit.Bybit.ApiSecret := 'aldskjfk3jkadknfajndsjfj23j';
oBybit.BybitClient := bybSpot;
oClient.Active := True;
procedure OnBybitAuthentication(Sender: TObject; aSuccess: Boolean; const aError, aRawMessage: string)
begin
if aSuccess then
begin
oClient.SubscribeOrderBook('BTCUSDT');
oClient.SubscribeTrade('BTCUSDT');
end;
end;
The REST API have a list of Public and Private methods to request data from: markets, private account and wallet. Find below a list of available methods.
Method | Public / Private |
GetServerTime | Public |
GetKLine | Public |
GetMarkPriceKLine | Public |
GetIndexPriceKLine | Public |
GetPremiumIndexPriceKLine | Public |
GetInstrumentsInfo | Public |
GetOrderBook | Public |
GetTickers | Public |
GetFundingRateHistory | Public |
GetPublicRecentTradingHistory | Public |
GetOpenInterest | Public |
GetHistoricalVolatility | Public |
GetInsurance | Public |
GetRiskLimit | Public |
GetDeliveryPrice | Public |
GetLongShortRatio | Public |
PlaceOrder | Private |
PlaceMarketOrder | Private |
PlaceLimitOrder | Private |
AmendOrder | Private |
CancelOrder | Private |
GetOpenOrders | Private |
CancelAllOrders | Private |
GetOrderHistory | Private |
GetPositionInfo | Private |
SetLeverage | Private |
SwitchCrossIsolatedMargin | Private |
SetTPSLMode | Private |
SwitchPositionMode | Private |
SetRiskLimit | Private |
SetTradingStop | Private |
SetAutoAddMargin | Private |
AddOrReduceMargin | Private |
GetExecution | Private |
GetClosedPNL | Private |
ConfirmNewRiskLimit | Private |
GetWalletBalance | Private |
GetAccountInfo | Private |
GetTransactionLog | Private |
Find below an example of getting the open orders.
oClient := TsgcWebSocketClient.Create(nil);
oBybit := TsgcWSAPI_Bybit.Create(nil);
oBybit.Client := oClient;
oBybit.Bybit.ApiKey := 'alsdjk23kandfnasbdfdkjhsdf';
oBybit.Bybit.ApiSecret := 'aldskjfk3jkadknfajndsjfj23j';
oBybit.BybitClient := bybSpot;
oBybit.REST_API.GetAccountInfo();