API client Bybit

· Composants

À partir de sgcWebSockets 2022.10.0, l'exchange crypto Bybit est pris en charge. APIs prises en charge :


Les APIs produit suivantes sont implémentées :

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 ; 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é SPOT puis appelle l'une des méthodes subscribe/unsubscribe disponibles.

Tu trouveras ci-dessous la liste des objets APIs Bybit :

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

Placer des ordres 

Tu trouveras ci-dessous un exemple de placement d'un ordre market pour 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); 

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