The ByBit Client API foi upgraded para V5 version. The following Protocols são suportados:
- 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...
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
- bybPerpetual
- bybLinear
- bybFutures
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 bem-sucedido conexão para o Spot servidor WebSocket, você pode iniciar para inscreva-se em WebSocket channels, just access o REST_API property e then call any do subscribe/unsubscribe métodos available
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.SubscribeOrderBook('BTCUSDT');
oClient.SubscribeTrade('BTCUSDT');
end;
end;
Colocar Ordens
Veja abaixo um exemplo de Placing um Market Order
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);
