黄金数据查询API提供上海黄金交易所所有黄金品种的实时行情数据。数据每分钟更新一次,周六日闭市期间返回最后一次行情数据。
| Header名称 | 默认值 | 必填 | 说明 |
|---|---|---|---|
X-API-Key |
你的API密钥
|
是 | 逗号APIKEY,用户后台首页获取 |
Content-Type |
application/json
|
是 | 请求内容类型 |
| 参数名 | 默认值 | 必填 | 说明 |
|---|---|---|---|
api_id |
7 |
是 | API接口ID,系统默认 |
endpoint_id |
ep_40618eed3d571763778d21a40209440b |
是 | 端点ID,系统默认 |
method |
POST |
是 | 请求方式,可选值:GET,POST |
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| 暂无业务参数 | ||||
| 参数名 | 类型 | 说明 | 示例 |
|---|---|---|---|
success |
boolean | 请求是否成功 | |
data.list |
object | 各品种行情数据,key为品种代码 | |
data.update_time |
string | 数据更新时间(取Au9999品种) | |
data.count |
integer | 品种总数 | |
generated_at |
string | 接口响应时间 | |
type |
string | 品种代码 | |
typename |
string | 品种中文名称 | |
price |
string | 最新价 | |
buyprice |
string | 买入价 | |
sellprice |
string | 卖出价 | |
changequantity |
string | 涨跌额 | |
changepercent |
string | 涨跌幅 | |
openingprice |
string | 开盘价 | |
maxprice |
string | 最高价 | |
minprice |
string | 最低价 | |
lastclosingprice |
string | 昨收价 | |
tradeamount |
string | 总成交量(kg) | |
unit |
string | 单位(元/克) | |
updatetime |
string | 更新时间 | |
{"success":true,"data":{"list":{"AuT+D":{"type":"AuT+D","typename":"黄金延期","price":"881.80","buyprice":"881.50","sellprice":"881.90","changequantity":"-0.69","changepercent":"-0.08%","openingprice":"878.40","maxprice":"882.34","minprice":"874.93","lastclosingprice":"882.78","tradeamount":"25032.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"mAuT+D":{"type":"mAuT+D","typename":"M黄金延期","price":"881.02","buyprice":"881.02","sellprice":"882.00","changequantity":"-1.84","changepercent":"-0.21%","openingprice":"878.50","maxprice":"882.30","minprice":"875.10","lastclosingprice":"882.89","tradeamount":"55686.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"Au9999":{"type":"Au9999","typename":"黄金9999","price":"882.00","buyprice":"881.50","sellprice":"881.70","changequantity":"-1.28","changepercent":"-0.14%","openingprice":"877.00","maxprice":"885.00","minprice":"875.03","lastclosingprice":"883.28","tradeamount":"532164.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"Au9995":{"type":"Au9995","typename":"黄金9995","price":"881.50","buyprice":"880.00","sellprice":"884.00","changequantity":"1.54","changepercent":"0.18%","openingprice":"878.00","maxprice":"881.50","minprice":"878.00","lastclosingprice":"879.96","tradeamount":"4.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"Au100g":{"type":"Au100g","typename":"100克金条","price":"882.70","buyprice":"882.50","sellprice":"886.50","changequantity":"-0.77","changepercent":"-0.09%","openingprice":"883.20","maxprice":"883.20","minprice":"877.00","lastclosingprice":"883.47","tradeamount":"168.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"AuT+N1":{"type":"AuT+N1","typename":"黄金单月延期","price":"1096.70","buyprice":"","sellprice":"","changequantity":"134.70","changepercent":"14.00%","openingprice":"","maxprice":"","minprice":"","lastclosingprice":"1096.70","tradeamount":"2.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"AuT+N2":{"type":"AuT+N2","typename":"黄金双月延期","price":"1050.00","buyprice":"","sellprice":"1050.00","changequantity":"25.00","changepercent":"2.44%","openingprice":"","maxprice":"","minprice":"","lastclosingprice":"1050.00","tradeamount":"2.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"SGiAu100g":{"type":"SGiAu100g","typename":"i黄金100g","price":"782.00","buyprice":"775.00","sellprice":"","changequantity":"24.19","changepercent":"3.19%","openingprice":"","maxprice":"","minprice":"","lastclosingprice":"782.00","tradeamount":"10.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"SGiAu9999":{"type":"SGiAu9999","typename":"i黄金9999","price":"880.60","buyprice":"880.16","sellprice":"880.96","changequantity":"-1.32","changepercent":"-0.15%","openingprice":"877.64","maxprice":"880.78","minprice":"873.97","lastclosingprice":"881.92","tradeamount":"96940.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"},"PT9995":{"type":"PT9995","typename":"铂金9995","price":"400.82","buyprice":"395.00","sellprice":"402.60","changequantity":"-1.50","changepercent":"-0.37%","openingprice":"401.86","maxprice":"401.86","minprice":"400.82","lastclosingprice":"402.32","tradeamount":"6.00","unit":"元\/克","updatetime":"2026-07-29 17:18:01"}},"update_time":"2026-07-29 17:18:01","count":10},"generated_at":"2026-07-29 17:18:17"}
HTTP/1.1 401 Unauthorized
{
"success": false,
"error": "invalid_api_key",
"message": "认证失败,请提供有效的API密钥"
}
| 错误代码 | HTTP状态 | 错误信息 | 详细说明 |
|---|---|---|---|
401 |
401 | invalid_api_key | API密钥无效或未提供 |
405 |
404 | method_not_allowed | 使用了GET以外的方法 |
500 |
500 | config_error | 服务配置异常 |
500 |
500 | api_request_failed | 第三方接口请求异常 |
500 |
500 | api_parse_failed | 第三方接口响应解析失败 |
500 |
500 | query_failed | 黄金数据查询失败 |
| 错误代码 | HTTP状态 | 错误信息 | 详细说明 |
|---|---|---|---|
401 | HTTP 401 | 认证失败 | 请求头中缺少 X-API-Key 或 API Key 无效 |
400 | HTTP 400 | 参数错误 | 缺少必要参数(api_id、endpoint_id、method)或必填业务参数缺失 |
404 | HTTP 404 | 资源不存在 | API不存在、已下架或端点不存在 |
403 | HTTP 403 | 未开通 | 您尚未开通此API,请先开通 |
405 | HTTP 405 | 方法不允许 | 请求方法不在端点允许列表中 |
402 | HTTP 402 | 积分不足 | 账户积分不足以调用该API |
500 | HTTP 500 | 服务器内部错误 | 系统异常 |
| 代码 | 名称 | 代码 | 名称 |
|---|---|---|---|
| AuT+D | 黄金延期 | mAuT+D | M黄金延期 |
| Au9999 | 黄金9999 | Au9995 | 黄金9995 |
| Au100g | 100克金条 | AuT+N1 | 黄金单月延期 |
| AuT+N2 | 黄金双月延期 | PT9995 | 铂金9995 |
| SGiAu100g | i黄金100g | SGiAu9999 | i黄金9999 |
⚠ 注意:周六日及节假日闭市,闭市期间返回最后一次行情数据。数据由上海黄金交易所提供,仅供参考。
<?php
// 以 黄金数据查询(ID:7) 为例,以下为PHP请求示例:
$gateway_url = "https://api.douhao.com/gateway";
// 系统参数
$gatewayData = array(
'api_id' => 7,
'endpoint_id' => 'ep_40618eed3d571763778d21a40209440b',
'method' => 'GET,POST'
);
// 业务参数(请填写实际值)
$bizParams = array(
);
// 合并请求数据
$requestData = array_merge($gatewayData, $bizParams);
// 请求头(请替换为您的API密钥)
$headers = array(
'Content-Type: application/json',
'X-API-Key: 您的API密钥'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $gateway_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$error = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($error) {
echo "请求错误: " . $error;
} else {
echo "HTTP状态码: " . $httpCode . "\n";
echo "响应数据: " . $response;
}
?>
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import json
# API网关地址
gateway_url = "https://api.douhao.com/gateway"
# 系统参数
gateway_data = {
'api_id': 7,
'endpoint_id': 'ep_40618eed3d571763778d21a40209440b',
'method': 'GET,POST'
}
# 业务参数(请填写实际值)
biz_params = {
}
# 合并请求参数
request_data = {**gateway_data, **biz_params}
# 请求头(请替换为您的API密钥)
headers = {
'Content-Type': 'application/json',
'X-API-Key': '您的API密钥'
}
try:
response = requests.post(
gateway_url,
json=request_data,
headers=headers,
timeout=180,
verify=False # 生产环境建议设为True
)
print(f"HTTP状态码: {response.status_code}")
print("响应数据:")
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except requests.exceptions.RequestException as e:
print(f"请求错误: {e}")
// 以 黄金数据查询(ID:7) 为例,以下为Node.js请求示例
// 需要先安装 axios: npm install axios
const axios = require('axios');
// API网关地址
const gatewayUrl = 'https://api.douhao.com/gateway';
// 系统参数
const gatewayData = {
api_id: 7,
endpoint_id: 'ep_40618eed3d571763778d21a40209440b',
method: 'GET,POST'
};
// 业务参数(请填写实际值)
const bizParams = {
};
// 合并请求参数
const requestData = { ...gatewayData, ...bizParams };
// 请求头(请替换为您的API密钥)
const headers = {
'Content-Type': 'application/json',
'X-API-Key': '您的API密钥'
};
async function callApi() {
try {
const response = await axios.post(gatewayUrl, requestData, {
headers: headers,
timeout: 180000
});
console.log('HTTP状态码:', response.status);
console.log('响应数据:');
console.log(JSON.stringify(response.data, null, 2));
} catch (error) {
if (error.response) {
console.log('HTTP状态码:', error.response.status);
console.log('错误响应:', error.response.data);
} else {
console.log('请求错误:', error.message);
}
}
}
callApi();
// 以 黄金数据查询(ID:7) 为例,以下为Java请求示例
// 需要依赖:okhttp 和 gson
import okhttp3.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class ApiDemo {
private static final String GATEWAY_URL = "https://api.douhao.com/gateway";
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
public static void main(String[] args) throws Exception {
// 系统参数
Map<String, Object> gatewayData = new HashMap<>();
gatewayData.put("api_id", 7);
gatewayData.put("endpoint_id", "ep_40618eed3d571763778d21a40209440b");
gatewayData.put("method", "GET,POST");
// 业务参数(请填写实际值)
Map<String, Object> bizParams = new HashMap<>();
// 合并请求数据
Map<String, Object> requestData = new HashMap<>(gatewayData);
requestData.putAll(bizParams);
// 请求体JSON
String jsonBody = gson.toJson(requestData);
// 创建请求
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(180, TimeUnit.SECONDS)
.readTimeout(180, TimeUnit.SECONDS)
.build();
RequestBody body = RequestBody.create(
jsonBody,
MediaType.parse("application/json; charset=utf-8")
);
Request request = new Request.Builder()
.url(GATEWAY_URL)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("X-API-Key", "您的API密钥") // 请替换为您的API密钥
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println("HTTP状态码: " + response.code());
String responseBody = response.body().string();
System.out.println("响应数据:");
System.out.println(gson.toJson(gson.fromJson(responseBody, Object.class)));
}
}
}
# 以 黄金数据查询(ID:7) 为例,以下为cURL请求示例
curl -X POST "https://api.douhao.com/gateway" \
-H "Content-Type: application/json" \
-H "X-API-Key: 您的API密钥" \
-d '{
"api_id": 7,
"endpoint_id": "ep_40618eed3d571763778d21a40209440b",
"method": "GET,POST",
}'
浙公网安备 33059102000262号