API Bitget

Bitget

APIs supported

Properties

Use the BitgetChannel property to select the channel type:

You can configure the following properties in the Bitget property.

Connection

When the client successfully connects to Bitget servers, the event OnConnect is fired. After the event OnConnect is fired, then you can start to send and receive messages to/from Bitget servers. If you are connecting to the private websocket channel, you must wait till OnBitgetAuthentication event is fired and check if the success parameter is true, before subscribing to any channel.


oClient := TsgcWebSocketClient.Create(nil);
oBitget := TsgcWS_API_Bitget.Create(nil);
oBitget.Client := oClient;
oBitget.Bitget.ApiKey := 'your_api_key';
oBitget.Bitget.ApiSecret := 'your_api_secret';
oBitget.Bitget.Passphrase := 'your_passphrase';
oBitget.BitgetChannel := bgcSpot;
oClient.Active := True;
procedure OnConnect(Connection: TsgcWSConnection);
begin
  DoLog('#Bitget Connected');
end;

Events

The Bitget client implements the following events to control the connection flow and get data sent from the WebSocket server:

WebSocket API

The websocket feed provides real-time market data updates for orders and trades.

You can subscribe to the following channels:

Method Public or Private Description
SubscribeTicker Public Subscribe to the ticker stream for an instrument.
SubscribeTrade Public Subscribe to the recent trades stream.
SubscribeCandle Public Subscribe to the candlestick stream. Supports multiple intervals (e.g. candle1m, candle5m, candle1H).
SubscribeOrderBook Public Subscribe to the order book stream. Supports different depth levels.
SubscribeOrders Private Subscribe to order updates. Requires authentication.
SubscribePositions Private Subscribe to position updates. Requires authentication.
SubscribeAccount Private Subscribe to account balance updates. Requires authentication.

Find below an example of subscribing to private websocket channels after a successful authentication.


procedure OnBitgetAuthentication(Sender: TObject; aSuccess: Boolean; const aError, aRawMessage: string);
begin
  if aSuccess then
  begin
    oBitget.SubscribeOrders('BTCUSDT');
    oBitget.SubscribeAccount();
  end;
end;

REST API

The REST API provides Public and Private methods to request data from markets and private accounts. Access the REST API through the REST_API property of the component.

Method Public / Private Description
GetServerTime Public Get the server time.
GetTickers Public Get ticker information for one or all symbols.
GetOrderBook Public Get the order book for a symbol.
GetCandles Public Get candlestick/kline data for a symbol.
GetRecentTrades Public Get the most recent trades for a symbol.
PlaceOrder Private Place a new order.
CancelOrder Private Cancel an existing order.
GetOpenOrders Private Get the list of open orders.
GetOrderDetail Private Get details of a specific order.
GetOrderHistory Private Get the order history.
GetAccountAssets Private Get account asset information.
GetAccountInfo Private Get account information.

Find below an example of using the REST API.


oBitget := TsgcWS_API_Bitget.Create(nil);
oBitget.Bitget.ApiKey := 'your_api_key';
oBitget.Bitget.ApiSecret := 'your_api_secret';
oBitget.Bitget.Passphrase := 'your_passphrase';
// Get tickers
oBitget.REST_API.GetTickers('SPOT');
// Place an order
oBitget.REST_API.PlaceOrder('BTCUSDT', 'buy', 'market', 'normal', '0.01');