A partir do sgcWebSockets 2022.10.0 Bybit Crypto Exchange é suportado. The following APIs suportado
- WebSocket API: conectar um um WebSocket server e provides em tempo real dados de mercado updates, account changes e more.
- REST API: send HTTP requests para obter dados de mercado, place orders, account data...
The following product APIs are implemented:
- Spot (V3)
- USDT Perpetual (Futures V2)
- Inverse Perpetual (Futures V2)
- Inverse Futures (Futures V2)
Propriedades
Você pode configure como propriedades um seguir no Bybit property.
- ApiKey: você pode request um novo api key em your Bybit account, just copy o valor para this property. If o APIKey is set, o cliente will conectar um o WebSocket private server. If it's empty, will conectar um o WebSocket public server.
- ApiSecret: it's o secret value do api.
- SignatureExpires: number de seconds after o signature expires (por padrão 10 seconds).
- TestNet: if enabled, will conectar um o Bybit TestNet Demo account (disabled por padrão).
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:
- bybSpot
- bybInversePerpetual
- bybUSDTPerpetual
- bybInverseFutures
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:
- SPOT
- INVERSE_PERPETUAL
- USDT_PERPETUAL
- INVERSE_FUTURES
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);
