From sgcWebSockets 2022.3.0, Kucoin API is supported. Currently the following APIs are implemented:
In order to connect to Kucoin WebSocket API, just create a new Kucoin API client and attach to TsgcWebSocketClient.
See below an example:
oClient := TsgcWebSocketClient.Create(nil); oKucoin := TsgcWSAPI_Kucoin.Create(nil); oKucoin.Client := oClient; oClient.Active := True;
Kucoin 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); oKucoin := TsgcWSAPI_Kucoin.Create(nil); oKucoin.Client := oClient; oKucoin.SubscribeSymbolTicker('BTC-USDT'); procedure OnMessage(Connection: TsgcWSConnection; const aText: string); begin // here you will receive the ticker updates end;
Kucoin allows to trade with spot using his REST API.
First you must create an API Key in your Kucoin account and add privileges to trading with Spot.
Once this is done, you can start spot trading.
First, set your ApiKey, ApiSecret and Passphrase in the Kucoin Client Component, this will be used to sign the requests sent to Kucoin server.
// Place Market Order 1 BTC-USDT oKucoin := TsgcWSAPI_Kucoin.Create(nil); oKucoin.Kucoin.ApiKey := '<api key>'; oKucoin.Kucoin.ApiSecret := '<api secret>'; oKucoin.Kucoin.Passphrase := '<passphrase>'; ShowMessage(oKucoin.REST_API.PlaceMarketOrder(kosBuy, 'BTC-USDT', 1)); // Place Limit Order 1 BTC-USDT at 40000 oKucoin := TsgcWSAPI_Kucoin.Create(nil); oKucoin.Kucoin.ApiKey := '<api key>'; oKucoin.Kucoin.ApiSecret := '<api secret>'; oKucoin.Kucoin.Passphrase := '<passphrase>'; ShowMessage(oKucoin.REST_API.PlaceLimitOrder(kosBuy, 'BTC-USDT', 1, 40000));
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.