一、引言
在贵金属业务开发场景中,无论是行情小程序、银饰进销存ERP,还是资产估值工具,都需要接入实时白银行情数据。很多开发者会遇到多数据源对接繁琐、海外接口国内访问不稳定、缺少盘口数据等问题。
二、应用场景
- 行情H5/小程序:展示国内外白银实时报价、涨跌幅、高低点位。
- 贵金属加工、销售:定时拉取银价,方便计算原料成本,给产品定价参考。
- 数据分析:历史K线、银价时序数据,做趋势研判与策略分析。
三、接口概述
白银价格查询API提供3个独立子接口,分别对应上海黄金交易所、上海期货交易所、伦敦金银市场LBMA,采用GET请求、标准JSON返回,仅需key作为鉴权参数。
| 市场 | 品种 | 单位 | 更新频率 | 核心亮点 | 使用场景 |
|---|---|---|---|---|---|
| 上海黄金交易所 | Ag(T+D)、Ag9999 | 元 / 千克 | 1min | 包含买价、卖价盘口 | 实物银销售、延期理财、库存估值 |
| 上海期货交易所 | 沪银 AG 连续合约 | 元 / 千克 | 5min | 期货主力合约、成交量 | 国内期货行情、原料成本核算 |
| 伦敦金银市场 | XAGUSD 伦敦现货白银 | 美元 / 盎司 | 5min | 国际基准,连续行情 | 国际银价、金银比价、跨境业务 |
休市时段接口自动返回最后一笔有效行情,避免页面空白报错。
返回参数
| 返回字段 | 类型 | 说明 |
|---|---|---|
| type | string | 品种代码 |
| typename | string | 品种中文名称 |
| price | string | 最新行情价格 |
| buyprice | string | 买价(仅上金所接口返回,其余接口不返回此字段) |
| sellprice | string | 卖价(仅上金所接口返回,其余接口不返回此字段) |
| changequantity | string | 涨跌额 |
| changepercent | string | 涨跌幅 |
| openingprice | string | 开盘价 |
| maxprice | string | 最高价 |
| minprice | string | 最低价 |
| lastclosingprice | string | 昨收价 |
| tradeamount | string | 成交量 |
| unit | string | 报价单位 |
| updatetime | string | 行情更新时间 |
四、Python调用示例
import urllib, urllib3, sys, uuid
import ssl
host = 'https://tssilver.market.alicloudapi.com'
path = '/silver/london'
method = 'GET'
appcode = '你自己的AppCode'
querys = ''
bodys = {}
url = host + path
http = urllib3.PoolManager()
headers = {
'Authorization': 'APPCODE ' + appcode
}
response = http.request('GET', url, headers=headers)
content = response.data.decode('utf-8')
if (content):
print(content)
五、返回示例
伦敦交易所
{
"code": 1,
"msg": "操作成功",
"data": {
"list": [
{
"type": "伦敦金",
"price": "4307.22",
"changepercent": "+0.2%",
"changequantity": "+8.59",
"openingprice": "4301.51",
"maxprice": "4311.60",
"minprice": "4307.57",
"lastclosingprice": "4298.63",
"updatetime": "2026-09-15 10:03:52"
},
{
"type": "伦敦银",
"price": "63.38",
"changepercent": "+0.27%",
"changequantity": "+0.17",
"openingprice": "63.29",
"maxprice": "63.54",
"minprice": "63.43",
"lastclosingprice": "63.21",
"updatetime": "2026-09-15 10:03:52"
},
{
"type": "铂金期货",
"price": "1767.652",
"changepercent": "-0.69%",
"changequantity": "-12.15",
"openingprice": "1767.600",
"maxprice": "1774.000",
"minprice": "1767.500",
"lastclosingprice": "1779.800",
"updatetime": "2026-09-15 10:03:52"
},
{
"type": "钯金期货",
"price": "1299.580",
"changepercent": "-0.62%",
"changequantity": "-8.12",
"openingprice": "1297.500",
"maxprice": "1300.500",
"minprice": "1300.000",
"lastclosingprice": "1307.700",
"updatetime": "2026-09-15 10:03:52"
}
]
}
}
上海黄金交易所
{
"code": 1,
"msg": "操作成功",
"data": {
"list": [
{
"type": "Ag(T+D)",
"typename": "白银延期",
"price": "15455",
"openingprice": "15315",
"maxprice": "15550",
"minprice": "15237",
"changepercent": "-0.85",
"lastclosingprice": "15460",
"tradeamount": "119306",
"updatetime": "2026-09-15 10:01:01"
},
{
"type": "Ag99.99",
"typename": "白银9999",
"price": "15570",
"openingprice": "0",
"maxprice": "0",
"minprice": "0",
"changepercent": "-0.35",
"lastclosingprice": "15570",
"tradeamount": "12",
"updatetime": "2026-09-15 10:01:01"
}
]
}
}
上海期货交易所
{
"code": 1,
"msg": "操作成功",
"data": {
"list": [
{
"type": "AG0",
"typename": "白银连续",
"price": "15527.00",
"changepercent": "-1.43%",
"changequantity": "-225",
"maxprice": "15618.00",
"minprice": "15285.00",
"openingprice": "15310.00",
"lastclosingprice": "15752.000",
"tradeamount": "79726",
"holdamount": "203007",
"buyamount": "1",
"buyprice": "15524.000",
"sellamount": "1",
"sellprice": "15526.000",
"updatetime": "2026-09-15 10:05:16"
},
{
"type": "AG2612",
"typename": "白银2612",
"price": "15527.00",
"changepercent": "-1.43%",
"changequantity": "-225",
"maxprice": "15618.00",
"minprice": "15285.00",
"openingprice": "15310.00",
"lastclosingprice": "15752.000",
"tradeamount": "79726",
"holdamount": "203007",
"buyamount": "1",
"buyprice": "15524.000",
"sellamount": "1",
"sellprice": "15526.000",
"updatetime": "2026-09-15 10:05:16"
},……
六、注意事项
- 行情数据仅用于展示、数据分析参考,不可作为实盘交易决策依据。
- 密钥不要硬编码暴露在前端,容易被盗刷的。
- 价格字段为字符串类型,业务计算时请转为数字。