Skip to content

鉴权

Web API 支持两种 OAuth 2.0 鉴权方式:客户端凭证(Client Credentials)授权码(Authorization Code)

环境信息

平台支持券商域名
MoomooSG, MFI, CAwebapi.moomoo.com

应用参数

以下参数由 Futu 分配,用于 OAuth 2.0 认证流程:

参数说明
client_id应用唯一标识
client_secret应用密钥
scope权限范围,多个值以空格分隔

scope 取值

取值含义
acc_read只读权限
trade_1007Moomoo US 交易权限
trade_1019Moomoo CA 交易权限

请求规范

所有业务接口请求头必须携带 AccessToken:

Authorization: Bearer <AccessToken>

方式一:客户端凭证(Client Credentials)

适用于服务端对服务端的场景,不涉及用户授权。

请求

POST /api/v1.0/oauth/svr/token HTTP/1.1
Host: webapi.moomoo.com
Authorization: Basic base64({client_id}:{client_secret})
Content-Type: application/x-www-form-urlencoded

grant_type=client_credential
参数位置必填说明
grant_typeBody固定值 client_credential
AuthorizationHeaderBasic base64({client_id}:{client_secret})

示例

使用 client_id: testcli_1002secret: XRYORwFK06lkA6Dz

bash
POST /api/v1.0/oauth/svr/token HTTP/1.1
Host: webapi.moomoo.com
Authorization: Basic dGVzdGNsaV8xMDAyOlhSWU9Sd0ZLMDZsa0E2RHo=
Content-Type: application/x-www-form-urlencoded

grant_type=client_credential

响应

json
{
  "access_token": "eyJhbGc.eyJvYWEiOiIwMDA0NCIsImlzcQ.gElDA_9M0_eDr6Jw...",
  "expires_in": 7200,
  "token_type": "Bearer"
}
字段类型说明
access_tokenstring访问令牌
expires_inint令牌有效期(秒)
token_typestring固定值 Bearer

方式二:授权码(Authorization Code)

适用于需要用户授权的场景,标准 OAuth 2.0 授权码流程。

步骤 1:发起授权请求

将用户重定向到授权链接:

GET https://passport.fututrade.com/authorize?response_type=code&client_id={client_id}&scope={scope}&redirect_uri={redirect_uri}&state={state}
参数说明
client_id应用标识
scope权限范围
redirect_uri回调地址
state状态参数,授权服务器将原值回传,用于防 CSRF

步骤 2:获取授权码

用户授权成功后,授权服务器重定向至 redirect_uri,附带以下参数:

参数说明
code授权码,短时效有效
state与请求中发送的值一致

步骤 3:用授权码换取 Access Token

POST /api/v1.0/oauth/svr/token HTTP/1.1
Host: webapi.moomoo.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&client_id={client_id}&client_secret={client_secret}&code={code}&redirect_uri={redirect_uri}
参数说明
grant_type固定值 authorization_code
client_id应用标识
client_secret应用密钥
code上一步获取的授权码
redirect_uri与授权请求中的 redirect_uri 一致

Token 响应

json
{
  "access_token": "xxxx",
  "refresh_token": "xxxx",
  "token_type": "bearer",
  "expires_in": 7200,
  "refresh_token_expires_in": 649670
}
字段类型说明
access_tokenstring访问令牌,用于调用业务接口
refresh_tokenstring刷新令牌,用于获取新的 access_token
token_typestring固定值 bearer
expires_inintaccess_token 有效期(秒)
refresh_token_expires_inintrefresh_token 有效期(秒)

步骤 4:刷新 Access Token

当 access_token 过期后,使用 refresh_token 获取新令牌:

POST /api/v1.0/oauth/svr/token HTTP/1.1
Host: webapi.moomoo.com
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token={refresh_token}&client_secret={client_secret}
参数说明
grant_type固定值 refresh_token
refresh_token刷新令牌
client_secret应用密钥

响应格式与步骤 3 一致。

错误响应

鉴权失败时返回:

json
{
  "s": "error",
  "errcode": -1200,
  "errmsg": "Error message."
}
字段类型说明
sstring状态,error 表示失败
errcodeint错误码
errmsgstring错误描述