使用説明
1. 前期溝通
信息收集完畢后,Kucoin將添加並上傳第三方信息,為第三方平臺建立數據庫並生成partner、broker-key以及broker-name
2. 訪問KucoinAPI
Kucoin將為第三方平臺提供partner和broker-key,請在請求中添加如下請求頭:
KC-API-PARTNER:partner
KC-API-PARTNER-SIGN:base64-encoded簽名方式(請參見簽名信息)
KC-BROKER-NAME:broker-name
KC-API-PARTNER-VERIFY: true
此請求頭是不是強制需要添加的,不過強烈建議加上
當加入KC-API-PARTNER-VERIFY請求頭時,KC-API-PARTNER-SIGN請求頭簽名失敗,但KC-API-SIGN簽章成功,也能下單成功,但是不會收到返佣
當不使用此請求頭後,只要KC-API-PARTNER-SIGN請求頭簽名失敗,就會報錯誤{"code":"400201","msg":"Invalid KC-API-PARTNER-SIGN"}
3. 簽名信息
請求頭中的 KC-API-PARTNER-SIGN:
使用 broker-key 對 timestamp + partner + apiKey 拼接的字符串進行HMAC-sha256加密。
再將加密內容使用 base64 編碼。 timestamp 值与 KC-API-TIMESTAMP 請求頭相同。
partner 值与 KC-API-PARTNER 請求頭相同。
apiKey 值与KC-API-KEY 相同
4. 举例
(1)用戶信息
String apikey = "6422da9c97b45100018c6e62";
String apiSecretKey = "cde06451-dbed";
String passphrase = "1111111";
(2)Broker信息
broker-name:goodbrokerND
partner:goodbroker
broker-key:e8512b82-a4aa
(3)訂單信息
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)用戶不通過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)用户通过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) 檢查是否配置成功
對於現貨,通過查詢訂單接口 GET /api/v1/orders/{orderId},如果返回的tags不爲空,則配置成功
對於合約,通過查詢訂單接口 GET /api/v1/orders/{order-id}?clientOid={client-order-id},如果返回的tags不爲空,則配置成功