Delphi OKX API

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.

  • Public channels: include tickers channel, K-Line channel, limit price channel, order book channel, and mark price channel, etc -- do not require log in.
  • Private channels: including account channel, order channel, and position channel, etc -- require log in.

You can configure the following properties in the OKS property.

  • ApiKey: you can request a new api key in your OKX account, just copy the value to this property.
  • ApiSecret: it's the secret value of the api.
  • Passphrase: it's the custom string defined when creating a new api key.
  • IsDemo: if enabled, will connect to the OKX Demo account (disabled by default).
  • IsPrivate: if enabled, you will be able to connect to private channels (disabled by default).

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);
  
×
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.

ICE Client (Interactive Connectivity Establishment...
.NET WhatsApp Cloud API

Related Posts