Atualmente, a versão da API suportada é a V5. A API V5 traz uniformidade e eficiência às linhas de produtos da Bybit, unificando Spot, Derivativos e Opções em um único conjunto de especificações.
| OpenAPI Version | Tipo de Conta | Linear | Inverse | Spot | Options | |||
|---|---|---|---|---|---|---|---|---|
| USDT Perpetual | USDC Perpetual | USDC Futures | Perpetual | Futures | ||||
| V5 | Unified trading account | ✓ | ✓ | ✓ | veja a nota | ✓ | ✓ | |
| Conta clássica | ✓ | ✓ | ✓ | ✓ | ||||
| V3 | Unified trading account | ✓ | ✓ | ✓ | ||||
| Conta clássica | ✓ | ✓ | ✓ | ✓ | ||||
*Nota: a conta Unified suporta negociação inversa. No entanto, a margem usada é da carteira de derivativos inversos em vez da carteira unified.
Você pode configurar as seguintes propriedades na propriedade Bybit.
Quando o cliente se conecta com sucesso aos servidores da Bybit, o evento OnConnect é disparado. Após o evento OnConnect ser disparado, você pode então começar a enviar e receber mensagens de/para os servidores da Bybit. Se você estiver se conectando ao canal websocket privado, deve aguardar até que o evento OnBybitAuthentication seja disparado e verificar se o parâmetro success é true, antes de assinar qualquer canal.
O cliente suporta várias APIs, portanto utilize a propriedade BybitClient para definir qual API você quer utilizar:
Veja abaixo um exemplo de conexão à 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;
Após uma conexão bem-sucedida com o Spot WebSocket Server, você pode começar a assinar canais WebSocket; basta acessar a propriedade SPOT e então chamar qualquer um dos métodos subscribe/unsubscribe disponíveis.
O cliente bybit implementa os seguintes eventos para controlar o fluxo da conexão e obter dados enviados pelo servidor WebSocket:
O feed do websocket fornece atualizações de dados de mercado em tempo real para ordens e negociações. O feed do websocket tem alguns canais públicos como ticker, trades...
Você pode se inscrever nos seguintes canais:
| Method | Público ou privado | Descrição |
| SubscribeOrderBook | Public | Assinar o stream do orderbook. Suporta diferentes profundidades. |
| SubscribeTrade | Public | Assine o stream de trades recentes. |
| SubscribeTicker | Public | Assinar o stream de ticker. |
| SubscribeKLine | Public | Assina o stream de klines. |
| SubscribeLiquidation | Public | Assine o stream de liquidação |
| SubscribeLT_KLine | Public |
Assine o stream de kline do leveraged token. |
| SubscribeLT_Ticker | Public | Assina o stream de ticker de leveraged token. |
| SubscribeLT_Nav | Public | Assina o stream de ticker de leveraged token. |
| SubscribePosition | Private | Assine o stream de nav do leveraged token. |
| SubscribeExecution | Private | Assinar |
| SubscribeOrder | Private | Assinar |
| SubscribeWallet | Private | Assinar |
| SubscribeGreek | Private | Assinar |
| SubscribeDcp | Private | Assinar |
| SubscribeInsurance | Public | Assina o stream do insurance fund. |
| SubscribeOrderPriceLimit | Public | Assina o stream de order price limit. |
| SubscribeADLAlert | Public | Assina o stream de alerta de auto-desalavancagem. |
| SubscribeFastExecution | Private | Assina o stream de execução rápida. |
Veja abaixo um exemplo de assinatura de canais websocket privados após uma autenticação bem-sucedida.
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;
A API REST tem uma lista de métodos públicos e privados para solicitar dados de: mercados, conta privada e carteira. Veja abaixo uma lista dos métodos disponíveis.
| Method | Público / Privado |
| 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 |
| BatchPlaceOrder | Private |
| BatchAmendOrder | Private |
| BatchCancelOrder | Private |
| SetDCP | Private |
| GetFeeRate | Private |
| GetCollateralInfo | Private |
| SetMarginMode | Private |
| GetBorrowHistory | Private |
| GetCoinGreeks | Private |
| GetCoinInfo | Private |
| GetAllCoinsBalance | Private |
| CreateInternalTransfer | Private |
| GetInternalTransferList | Private |
| GetDepositRecords | Private |
| GetDepositAddress | Private |
| CreateWithdrawal | Private |
| CancelWithdrawal | Private |
| GetWithdrawalRecords | Private |
Encontre abaixo um exemplo de como obter as ordens abertas.
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();