Delphi OKX API

· Components

From sgcWebSockets 2022.6.0 OKX Crypto Broker is supported, OKX, formerly known as OKEx, is one of the largest crypto spot and derivatives trading exchanges. OKX is a Seychelles-based cryptocurrency exchange that provides a platform for trading various instruments such as spot and derivative. Some of the exchange's core features include spot and derivative trading.

sgcWebSockets supports the WebSocket API including the Public and Private Channels. Placing orders is also supported.

Configuration 

WebSocket channels are divided into two categories: public and private channels.

You can configure the following properties in the OKS property.

Connection

When the client successfully connects to OKX servers, the event OnOKXConnect is fired. If there is any error while trying to connect, the event OnOKXError will be fired with the error details.

After the event OnOKXConnect is fired, then you can start to send and receive messages from OKX servers.

oClient := TsgcWebSocketClient.Create(nil);
oOKX := TsgcWSAPI_OKX.Create(nil);
oOKX.Client := oClient;
oOKX.OKX.ApiKey := 'alsdjk23kandfnasbdfdkjhsdf';
oOKX.OKX.ApiSecret := 'aldskjfk3jkadknfajndsjfj23j';
oOKX.OKX.Passphrase := 'secret_passphrase';
oClient.Active := True;
procedure OnOKXConnect(Sender: TObject; aMessage, aCode, aRawMessage: string);
begin
  DoLog('#OKX Connected');
end;
procedure OnOKXError(Sender: TObject; aCode, aMessage, aRawMessage: string);
begin
  DoLog('#error: ' + aMessage);
end; 

Subscribe to Channels 

The websocket feed provides real-time market data updates for orders and trades. The websocket feed has some public channels like ticker, trades...

oClient := TsgcWebSocketClient.Create(nil);
oOKX := TsgcWSAPI_OKX.Create(nil);
oOKX.Client := oClient;
oOKX.OKX.ApiKey := 'alsdjk23kandfnasbdfdkjhsdf';
oOKX.OKX.ApiSecret := 'aldskjfk3jkadknfajndsjfj23j';
oOKX.OKX.Passphrase := 'secret_passphrase';
oClient.Active := True;
procedure OnOKXConnect(Sender: TObject; aMessage, aCode, aRawMessage: string);
begin
  oOKX.SubscribeInstruments(okxitFutures);
end; 

Place Orders 

You can place an order only if you have sufficient funds.

// Place Martket Order
TsgcWSAPI_OKX1.PlaceMarketOrder(okxosBuy, 'ETH-BTC', 1);
// Place Limit Order
TsgcWSAPI_OKX1.PlaceLimitOrder(okxosBuy, 'ETH-BTC', 1, 0.25);

Delphi WebSockets OKX API

Read more about sgcWebSockets OKX API. https://www.esegece.com/products/websockets/apis/cryptos/okx