Instructions

1. Add Third Party Info. to Database

After information collection, KuCoin will add and upload the third party info. to database and generate 'partner'、'broker-key' and 'broker-name' for the third party platform.

2. Access to KuCoin OpenAPI

KuCoin will provide 'partner'、'broker-key' and 'broker-name' for the third party platforms. Please add the following headers in the request :

  • KC-API-PARTNER:partner

  • KC-API-PARTNER-SIGN: The base64-encoded signature (see Signing a Message)

  • KC-BROKER-NAME:broker-name

  • KC-API-PARTNER-VERIFY: true

It is not mandatory to add this request header, but it is strongly recommended to add it.

When the KC-API-PARTNER-VERIFY request header is not added, the KC-API-PARTNER-SIGN request header fails to be signed, but the KC-API-SIGN signature is successful and the order can be placed successfully without carry broker info.

After adding this request header, as long as the KC-API-PARTNER-SIGN request header fails to be signed, an error {"code":"400201","msg":"Invalid KC-API-PARTNER-SIGN"} will be reported.

3. Signing a Message

For the header of KC-API-PARTNER-SIGN:

  • Use broker-key to encrypt the prehash string timestamp + partner + apiKey with sha256 HMAC.

  • After that, use base64-encode to encrypt the result in step 1 again.

The timestamp value is the same as the KC-API-TIMESTAMP header.

The partner value is the same as the KC-API-PARTNER header.

The apiKey value is the same as KC-API-KEY

4. For Example

(1)User Info

String apikey = "6422da9c97b45100018c6e62";
String apiSecretKey = "cde06451-dbed";
String passphrase = "1111111";

(2)Broker Info

broker-name:goodbrokerND
partner:goodbroker
broker-key:e8512b82-a4aa

(3)Order Info

REQ TIMESTAMP: 1680885532722
REQ URL:https://api.kucoin.com/api/v1/orders
REQ BODY:{"symbol":"BTC-USDT","side":"buy","size":"0.0001","price":"30000","type":"limit","clientOid":"2b802154-8d31-42e6-88ea-c8c18d3e4822","tradeType":"TRADE"}

(4)The request header for user to place order normally without through the broker

① preSignString:

1680885532722POST/api/v1/orders{"symbol":"BTC-USDT","side":"buy","size":"0.0001","price":"30000","type":"limit","clientOid":"2b802154-	8d31-42e6-88ea-c8c18d3e4822","tradeType":"TRADE"}

② KC-API-SIGN:

ncPuAcZW8WYUZyvblRVVgMfYoVH+FlCTO6K45/FMLFQ=

③ Header:

{
   KC-API-TIMESTAMP=1680885532722,
   KC-API-KEY=6422da9c97b45100018c6e62,
   KC-API-SIGN=ncPuAcZW8WYUZyvblRVVgMfYoVH+FlCTO6K45/FMLFQ=,
   KC-API-PASSPHRASE=rl1Ki0WuwidRT48JnoGQo+AJ4UtZ6mQEKt6F5XYVnT4=,
   KC-API-KEY-VERSION=2,
   Content-Type=application/json,
   accept=*/*
}
(5)The request header for user to place order through the broker

① code

header.put("KC-BROKER-NAME", "goodbrokerND");
header.put("KC-API-PARTNER", "goodbroker");
String partnerSign = Base64.encodeBase64String( SHA256Util.hmac_sha256("e8512b82-a4aa", timestamp+"goodbroker"+apiKey));
header.put("KC-API-PARTNER-SIGN", partnerSign);
header.put("KC-API-PARTNER-VERIFY", "true");

② preSignString:

1680885532722POST/api/v1/orders{"symbol":"BTC-USDT","side":"buy","size":"0.0001","price":"30000","type":"limit","clientOid":"2b802154-8d31-42e6-88ea-c8c18d3e4822","tradeType":"TRADE"}

③ KC-API-SIGN:

ncPuAcZW8WYUZyvblRVVgMfYoVH+FlCTO6K45/FMLFQ=

④ prePartnerSignString:

1680885532722goodbroker6422da9c97b45100018c6e62

⑤ KC-API-PARTNER-SIGN:

CN1imIGUz/USkPuhOtGWi5DlZ08VeuVfknJNOPqUEac=

⑥ Header:

{
   KC-API-TIMESTAMP=1680885532722,
   KC-API-KEY=6422da9c97b45100018c6e62,
   KC-API-PASSPHRASE=rl1Ki0WuwidRT48JnoGQo+AJ4UtZ6mQEKt6F5XYVnT4=,
   KC-API-SIGN=ncPuAcZW8WYUZyvblRVVgMfYoVH+FlCTO6K45/FMLFQ=,
   KC-API-PARTNER=goodbroker,
   KC-API-PARTNER-SIGN=CN1imIGUz/USkPuhOtGWi5DlZ08VeuVfknJNOPqUEac=,
   KC-BROKER-NAME=goodbrokerND,
   KC-API-PARTNER-VERIFY=true,
   KC-API-KEY-VERSION=2,
   Content-Type=application/json,
   accept=*/*
}
(6) Check whether the configuration is successful

For Spot, By querying the order interface GET /api/v1/orders/{orderId}, if the returned tags are not empty, the config is successful

For Futures, By querying the order interface GET /api/v1/orders/{order-id}?clientOid={client-order-id}, if the returned tags are not empty, the config is successful