API client Bybit V5

· Composants

L'API client ByBit a été mise à niveau vers la version V5. Les protocoles suivants sont pris en charge :



Propriétés 

Tu peux configurer les propriétés suivantes dans la propriété Bybit.

Connexion 

Quand le client se connecte avec succès aux serveurs Bybit, l'événement OnConnect est déclenché. Après le déclenchement de l'événement OnConnect, tu peux commencer à envoyer et recevoir des messages vers/depuis les serveurs Bybit. Si tu te connectes au canal WebSocket privé, tu dois attendre que l'événement OnBybitAuthentication soit déclenché et vérifier si le paramètre success est true, avant de t'abonner à un canal.

Le client prend en charge plusieurs APIs, donc utilise la propriété BybitClient pour définir quelle API tu veux utiliser :


Tu trouveras ci-dessous un exemple de connexion à l'API WebSocket Spot privée.

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; 

Après une connexion réussie au serveur WebSocket Spot, tu peux commencer à t'abonner aux canaux WebSocket : accède simplement à la propriété REST_API puis appelle l'une des méthodes subscribe/unsubscribe disponibles. 

S'abonner aux canaux WebSocket 

Tu trouveras ci-dessous un exemple d'abonnement aux canaux WebSocket Spot privés après une authentification réussie.

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; 

Placer des ordres 

Tu trouveras ci-dessous un exemple de placement d'un ordre market.

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.PlaceMarketOrder('BTCUSDT', bbosBuy, 1); 

Démo Bybit compilée pour Windows

Télécharge une démo compilée de l'API client Bybit pour Windows qui montre les fonctionnalités principales du client API Bybit sgcWebSockets. https://www.esegece.com/download/protocols/sgcBybit.zip