1. 簡介#
KuCoin 將推出 Fast API 服務,允許經紀商用戶通過 KuCoin OAuth2.0 登錄,一鍵授權連接到第三方應用程序。 快速 API 服務的重大改進在於增強交易的安全性並簡化連接 KuCoin 和經紀商的方式。不需要額外的密碼短語或 API 密鑰 (版本3) 來手動綁定經紀商的機器人。OAuth 連接將自動創建 API 密鑰並自動連接到經紀商。該密鑰具有默認權限,包括現貨交易、期貨交易,以及獲取 KuCoin Earn 的訪問權限。2. 整合前的準備#
要使用 KuCoin Fast API 服務,經紀商合作夥伴需要準備以下三個部分並通過此表格提交.經紀商請求 Fast API 服務的完整 IP 列表。這是經紀商伺服器向我們的 KuCoin Fast API 服務伺服器請求的 IP。
一旦經紀商提供上述三個,KuCoin 將會發送經紀商的唯一client_id3. Fast API 服務#
經紀人用戶可以使用 KuCoin Oauth 登入授權經紀人獲取他們的交易和一般交易相關資訊。未經授權不得進行提現。4. OpenAPI Demo#
method:POST
content-type:application/json
header: "Authorization":"bearer {token}"
parameter: no parameter neededresponse:
{
"success": true,
"code": "200",
"msg": "success",
"retry": false,
"data": {
"apiName": "",
"apiKey": "",
"secret": "",
"passphrase": "",
"brokerId": "",
"authGroup": API_COMMON,API_FUTURES,API_SPOT,API_EARN,API_TRANSFER,API_MARGIN,
"ipWhiteList": ""
}
}
5. 授權碼模式#
KuCoin 只提供授權碼模式。通過授權,經紀商提供 client_secret 來獲取授權碼。可以根據授權碼獲取訪問令牌Access token 和 Refresh token。經紀商保存密鑰並與 KuCoin OAuth2.0 服務器交互。6. Token的使用#
6.1 不同Token的分別#
在經紀商通過授權碼調用 Token API 接口後,將會有兩種類型的 Token。Access token: 用於經紀商調用 KuCoin OpenAPI 接口。
Refresh token: 用於在前一個 Access token 過期時獲取一個新的。
6.2 如何使用 Token#
在經紀商完成授權並獲得token後,它將能夠通過 access token 調用 KuCoin OpenAPI 接口。在請求時,經紀商需要在請求標頭中攜帶以下信息:| 請求標頭參數 | 是否必須 | 描述 |
|---|
| Authorization | Yes | 請將 Access Token 填寫到此欄位中。 |
6.3 Token 有效性#
如果 access token 過期,該接口將不再可訪問。如果 refresh token 仍在有效期限內,經紀商需要調用 refresh token 接口以獲取一對新的 access token 和 refresh token。新的 access token 可以繼續使用。當通過 refresh token 獲取新的access token 時,舊的access token 無論是否過期都不能使用。7. OAuth 控制器 API 設計#
7.1 OAuth 登入頁面#
| Params | |
|---|
| Response Type | 請使用授權碼模式 |
| Client_id | 經紀商的 ID |
| Redirect_url | 經紀商的 URL |
| Scope | access_token 的範圍 |
| State | 經紀商可以在這裡確定你的需求。但這是一個必填字段。你可以在這裡放入你系統的用戶 ID |
Response :
{
"success": true,
"code": "668*********c711",
"msg": "success.",
"retry": false,
"data": null
"state": XXX
}
7.2 請求一個 Token#
| 參數 | 是否必須 | 描述 |
|---|
| Grant_type | Yes | grant_type=authorization_code |
| Code | Yes | |
| Redirect_url | Yes | |
| Client_id | Yes | 經紀商的 ID |
Response :
{
"access_token":"", //access token received from user authorization
"token_type":"bearer" //token type, extension point to facilitate the
addition of more secure tokens in the future
"expires_in":3600, //token expiration time, in seconds
"refresh_token":, //token used to obtain a new access token after
the access token expires
"scope": ["", ""] //scope of permissions for the access token
}
7.3 刷新一個 Token#
| Params | is_required | Description |
|---|
| Grant_type | Yes | grant_type=authorization_code |
| Refresh_token | Yes | 用於刷新身份驗證的 Token |
| Scope | Yes | |
Response :
{
"access_token":"", //token used to access resources
"token_type":"bearer", //token type, an extension point to facilitate the
addition of more secure tokens in the future, such
as MAC (Message Authentication Code). Bearer
indicates a token that does not contain any
information
"expires_in":3600, //token expiration time, in seconds
"refresh_token":, //token used to obtain a new access token after the
access token expires
"scope": [""OAUTH_CREATE_API""] //scope of permissions for the access token
}
Modified at 2025-11-14 03:10:47