Bybit API Cliente

· Componentes

A partir do sgcWebSockets 2022.10.0 Bybit Crypto Exchange é suportado. The following APIs suportado


The following product APIs are implemented:

Propriedades 

Você pode configure como propriedades um seguir no Bybit property.

Conexão 

When o cliente successfully connects para Bybit servers, o evento OnConnect é disparado. After o evento OnConnect é disparado, then você pode iniciar para send and receber mensagens to/from Bybit servers. Se você é connecting para o private websocket channel, você deve wait till OnBybitAuthentication event é disparado e check if o success parameter is true, before inscreva-se em any channel.

O cliente suporta several APIs, so use um propriedade BybitClient para definir which API you want para usar:


Veja abaixo um exemplo de connecting para 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 um successfull conexão para o Spot servidor WebSocket, você pode iniciar para inscreva-se em WebSocket channels, just access o SPOT property e then call any do subscribe/unsubscribe métodos available.

Veja abaixo um lista de o Bybit APIs objects:

Inscreva-se em WebSocket Channels 

Veja abaixo um exemplo de subscribing para o Private Spot Websocket Channels after um bem-sucedido autenticação.

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.SubscribeOrder;
    oClient.SubscribeStopOrder;
  end;
end; 

Colocar Ordens 

Veja abaixo um exemplo de Placing um Market Order para USDT Perpetual.


oClient := TsgcWebSocketClient.Create(nil);
oBybit := TsgcWSAPI_Bybit.Create(nil);
oBybit.Client := oClient;
oBybit.Bybit.ApiKey := 'alsdjk23kandfnasbdfdkjhsdf';
oBybit.Bybit.ApiSecret := 'aldskjfk3jkadknfajndsjfj23j';
oBybit.BybitClient := bybUSDTPerpetual;
oBybit.USDT_PERPETUAL.REST_API.PlaceMarketOrder('BTCUSDT', bbosBuy, 1); 

Compiled Windows Bybit Demo

Download um compiled Bybit Client API Demo para Windows that shows o main features do sgcWebSockets Bybit API Client. https://www.esegece.com/download/protocols/sgcBybit.zip