貴金屬 現貨 API 參考文件
貴金屬 現貨 API 參考提供黃金、白銀、鉑金和鈀金的現貨價格,另有 WTI、布蘭特原油與銅的參考價格,每筆資料都附上單位和 UTC 時間戳記,方便你核對報價的對應單位與時間。
身分驗證與請求
請以 Bearer 驗證方式,在 Authorization 標頭中傳送你的 API 金鑰。 產品概覽 →
curl "https://api.narwhalapi.com/v1/commodities/spot/XAU/USD" \
--header "Authorization: Bearer $NARWHAL_API_KEY"操作
| 端點 | 操作 |
|---|---|
GET /v1/commodities/spot/{commodity}/{currency} | 取得現貨價格或基於期貨的參考價格。 |
GET /v1/commodities/spot/{commodity}/{currency}/bars | 取得黃金、白銀、鉑金、鈀金、銅、WTI 和 BRENT 的開盤價、最高價、最低價和收盤價價格柱。銅的歷史資料也可用。 |
參數
| 欄位 | 含義 |
|---|---|
commodity | 路徑參數。XAU、XAG、XPT、XPD、WTI(WTI 原油)、BRENT(布蘭特原油)或 XCU(銅)。 |
currency | 路徑參數,使用大寫。黃金:USD, AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, EUR, GBP, HKD, HUF, IDR, ILS, INR, ISK, JPY, KRW, MXN, MYR, NOK, NZD, PHP, PLN, RON, SEK, SGD, THB, TRY 或 ZAR。白銀、鉑金、鈀金、WTI、BRENT 和 XCU:僅支援 USD。 |
unit | 現貨與價格柱請求均可使用。選填,可填troy_、gram、kilogram、pound或metric_。價格以該單位計價,回應中的unit和unit_會標明該單位。黃金、白銀、鉑、鈀和銅(XCU)可使用全部五種單位;WTI與BRENT以桶報價,只能使用barrel。其他值會回傳400 unit_。未傳unit時,回應與先前相同。 |
interval | 僅適用於價格柱。1m、5m、15m、1h、4h或1d(預設值)。 |
start / | 僅適用於價格柱。兩項均必填。使用位於間隔邊界的UTC時間(4h為00、04、08時等;1d為午夜)。包含開始時間,不包含結束時間。 |
limit / | 僅適用於價格柱。預設100,最多500。使用相同查詢重複使用next_cursor。 |
報價欄位
| 欄位 | 含義 |
|---|---|
symbol, currency, unit | 代碼和報價貨幣。貴金屬的 unit 為 troy_ounce,WTI 和 BRENT 為 barrel,XCU 為 pound。 |
commodity_ | commodity_ 在現貨、期貨、預測與實物價格中以相同方式命名商品,例如 gold 或 crude-oil。原油另有 benchmark(wti、brent、urals 或 dubai),期貨則有 exchange_,也就是交易所的標準代碼。 |
unit_ | unit_ 以單一標準寫法表示單位,例如 troy_ounce、barrel 或 tonne;unit 保留來源的原始寫法。當價格以分報價時,price_ 為 0.01:將價格乘以它,即可得到以 currency 計價的金額。 |
price | 一個正數參考價格,以十進位字串表示。 |
timestamp, stale | 報價的 UTC 時間戳記與明確的資料時效旗標。 |
bars | 僅適用於價格柱。依從舊到新的順序回傳已收盤的價格柱。每個價格柱都有timestamp(柱的開始時間),以及十進位字串形式的open、high、low和close。非USD貨幣的黃金僅有close。 |
start, end | 僅在 Narwhal 變更了請求的範圍時,才回傳 start 和 end。 |
next_ | 僅適用於價格柱。用於繼續查詢的游標;沒有更多價格柱時為null。 |
範例回應: GET /v1/commodities/spot/{commodity}/{currency}。
{
"symbol": "XAU-USD",
"commodity_key": "gold",
"price": "3550.6320",
"currency": "USD",
"unit": "troy_ounce",
"unit_key": "troy_ounce",
"timestamp": "2026-11-20T05:54:00Z",
"stale": false
}{
"symbol": "WTI-USD",
"commodity_key": "crude-oil",
"benchmark": "wti",
"price": "82.5990",
"currency": "USD",
"unit": "barrel",
"unit_key": "barrel",
"timestamp": "2026-11-20T05:52:00Z",
"stale": false
}With unit=gram, a silver quote is priced per gram.
curl "https://api.narwhalapi.com/v1/commodities/spot/XAG/USD?unit=gram" \
--header "Authorization: Bearer $NARWHAL_API_KEY"{
"symbol": "XAG-USD",
"commodity_key": "silver",
"price": "1.31824",
"currency": "USD",
"unit": "gram",
"unit_key": "gram",
"timestamp": "2026-11-21T18:11:00Z",
"stale": false
}A converted price is worked out in exact decimals from the price shown without unit, with 1 troy ounce = 31.1034768 g and 1 pound = 453.59237 g. It keeps as many significant figures as that price (trailing zeros of a whole number do not count), and a price under 10 keeps at least 4 decimals. Halves round up and zeros after the decimal point are dropped. Bars convert open, high, low and close the same way.
Bars response for GET /. start and end are returned only when Narwhal changes the requested range.
{
"symbol": "XAU-USD",
"commodity_key": "gold",
"currency": "USD",
"unit": "troy_ounce",
"unit_key": "troy_ounce",
"bars": [
{
"timestamp": "2026-10-01T00:00:00Z",
"open": "4156.8352",
"high": "4192.5215",
"low": "4139.7787",
"close": "4177.4458"
},
{
"timestamp": "2026-10-02T00:00:00Z",
"open": "4177.2183",
"high": "4225.6497",
"low": "4125.9232",
"close": "4141.5280"
}
],
"next_cursor": null
}Gold in a currency other than USD has close only.
{
"symbol": "XAU-EUR",
"commodity_key": "gold",
"currency": "EUR",
"unit": "troy_ounce",
"unit_key": "troy_ounce",
"bars": [
{
"timestamp": "2026-10-01T00:00:00Z",
"close": "3715.66"
},
{
"timestamp": "2026-10-02T00:00:00Z",
"close": "3680.67"
}
],
"next_cursor": null
}A request may span at most 3 days of 1m bars, 14 days of 5m bars, 60 days of 15m bars; a longer range returns 400 invalid_. Wider intervals have no cap.
解讀資料
WTI, BRENT and XCU are reference prices derived from futures markets, not physical spot cargo prices. Display the unit and timestamp with the price. The timestamp is the start of the minute the price belongs to; during the daily 17:00 New York metals pause (21:00 UTC in summer, 22:00 UTC in winter), which is not a market closure, a quote can carry stale: true. A closed market never makes a quote stale: from Friday 17:00 to Sunday 17:00 New York time you get the last price with stale: false. A quote is stale when its price is more than 10 minutes old, counting only open-market time; do not present a stale quote as a fresh market price. An unknown commodity returns 404 commodity_. A known commodity with an unsupported currency returns 404 currency_. Price history is available for gold, silver, platinum, palladium, copper (XCU), WTI and BRENT. We never fill gaps: missing bars stay missing. We keep 1m and 5m bars for 30 days and 15m, 1h, 4h and 1d bars indefinitely. A range outside retention returns an empty bars list, not an error. WTI and BRENT have 15-minute and hourly history from 2020.
現貨價格對所有帳戶即時開放,包括僅使用免費額度的帳戶。價格串流已結束;請改為輪詢此路由。 價格串流參考文件 →
錯誤
- 路徑值無效、開始或結束時間不在間隔邊界、價格柱請求缺少
start或end,或價格柱範圍超過該間隔允許的長度時,回傳400 invalid_。query - Bearer金鑰缺少或無效時回傳
401 invalid_。api_ key 400 unit_:所指定的not_ supported unit不適用於該商品。錯誤詳情會列出該商品允許使用的單位。- Narwhal不提供的商品回傳
404 commodity_;該商品不支援的貨幣回傳not_ supported 404 currency_。not_ supported - 達到每分鐘上限時回傳
429 rate_,餘額不足以支付呼叫時回傳limit_ exceeded 402 insufficient_。credits - 無法讀取價格資料時回傳
503 upstream_。unavailable
MCP 工具
commodities_get_spot_pricecommodities_get_price_history此頁面對你有幫助嗎?