Delphi FTX API Client

From sgcWebSockets 4.5.0 FTX API is supported.

APIs supported

  • WebSockets API: connect to a public websocket server and provides real-time market data updates.
  • REST API: The REST API has endpoints for account and order management as well as public market data.

FTX WebSocket API 

In order to connect to FTX WebSocket API, just create a new FTX API client and attach to TsgcWebSocketClient.

Find below an example:

oClient := TsgcWebSocketClient.Create(nil);
oFTX := TsgcWSAPI_FTX.Create(nil);
oFTX.Client := oClient;
oClient.Active := True; 

FTX offers a variety of channels where you can subscribe to get real-time updates of market data, orders...

Find below a sample of how subscribe to a Ticker:

oClient := TsgcWebSocketClient.Create(nil);
oFTX := TsgcWSAPI_FTX.Create(nil);
oFTX.Client := oClient;
oFTX.SubscribeTicker('BTC-PERP');

procedure OnFTXMessage(Sender: TObject; aType, aRawMessage: string);
begin
// here you will receive the ticker updates
end; 

FTX REST API 

FTX offers public Market Data through REST Endpoints, when you call one of these endpoints, you will get an snapshot of the market data requested.

The Market Data Endpoints doesn't require authentication, so are freely available to all users.

Example: to get an snapshot of the market BTC-PERP, do the following call

oFTX := TsgcWSAPI_FTX.Create(nil);
ShowMessage(oFTX.REST_API.GetMarket('BTC-PERP')); 

The FTX REST API offer public and private endpoints. The Private endpoints requires that messages are signed to increase the security of transactions.

First you must login to your FTX account and create a new API, you will get the following values:

  • ApiKey
  • ApiSecret

These fields must be configured in the FTX property of the FTX API client component.

Once configured, you can start to do private requests to the FTX REST API

oFTX := TsgcWSAPI_FTX.Create(nil);
oFTX.FTX.ApiKey := '<your api key>';
oFTX.FTX.ApiSecret := '<your api secret>';
ShowMessage(oFTX.REST_API.GetAccount); 

Place Orders 

Market Order

Place a new Market Order, buy 0.002 contracts of BTC-PERP

oFTX := TsgcWSAPI_FTX.Create(nil);
oFTX.FTX.ApiKey := 'your api key';
oFTX.FTX.ApiSecret := 'your api secret';
ShowMessage(oFTX.REST_API.PlaceMarketOrder('BTC-PERP', ftosBuy, 0.002)); 

Limit Order

Place a new Limit Order, buy 0.002 contracts of BTC-PERP at price limit of 10000 

oFTX := TsgcWSAPI_FTX.Create(nil);
oFTX.FTX.ApiKey := 'your api key';
oFTX.FTX.ApiSecret := 'your api secret';
ShowMessage(oFTX.REST_API.PlaceLimitOrder('BTC-PERP', ftosBuy, 0.002, 10000)); 
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Place Orders Binance - Trade Bar
TIME_WAIT TCP Connections

Related Posts