API dokümantasyonu
Temel URL: https://metalapi.com/api/v1. Tüm yanıtlar HTTPS üzerinden JSON formatındadır. Mevcut MetalAPI entegrasyonları hiçbir değişiklik gerektirmeden çalışmaya devam eder.
Hızlı başlangıç
Ücretsiz bir hesap oluşturun, panelden API anahtarınızı kopyalayın ve en güncel altın ve gümüş fiyatlarını isteyin:
curl "https://metalapi.com/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=XAU,XAG,EUR"Kimlik doğrulama
Her istek API anahtarınızı gerektirir. Anahtarı üç yoldan biriyle gönderin (header seçenekleri anahtarların log kayıtlarına düşmesini önler):
# Header (recommended)
curl -H "Authorization: Bearer YOUR_API_KEY" https://metalapi.com/api/v1/latest
curl -H "X-API-Key: YOUR_API_KEY" https://metalapi.com/api/v1/latest
# Query string
curl "https://metalapi.com/api/v1/latest?api_key=YOUR_API_KEY"Anahtarlar mk_live_… biçimindedir ve yalnızca oluşturuldukları anda bir kez gösterilir; biz yalnızca hash değerini saklarız. Panelden birden fazla anahtar oluşturabilir, bunları adlandırabilir, yenileyebilir ve web sitenizin alan adlarıyla sınırlandırabilirsiniz. Başka alan adlarındaki tarayıcılardan gelen istekler 107 hatasıyla reddedilir; sunucudan sunucuya istekler her zaman kabul edilir.
Yanıt formatı
Kurlar iki yönde döndürülür. Baz USD ve sembol XAU için:
rates.USDXAU— bir troy ons altının USD cinsinden fiyatı (ör. 3997.89).rates.XAU— bir USD ile alınabilecek altın miktarı, ons cinsinden (1 / 3997.89 = 0.00025013).
Her yanıt success alanını ve aylık kotanızı gösteren bir rate_limit bloğunu içerir. Hatalarda success: false ve code, type ve info alanlarından oluşan bir error nesnesi döner. Zaman damgaları Unix saniyesidir (UTC); tarihler YYYY-MM-DD formatındadır (UTC).
Latest rates
/api/v1/latestCurrent rates for every requested symbol. The data you receive is as fresh as your plan's update interval allows (daily on Free, down to 5 seconds on Enterprise).
Add XAU-BID / XAU-ASK to currencies for the book (Standard plan and above). Available for precious metals, major currencies and crypto; futures-based symbols (industrial metals, energy) have no bid/ask.
timestamp is the time of the data, not of the request.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
base | Currency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU. |
currencies | Comma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored. |
unit | Weight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto. |
curl "https://metalapi.com/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=XAU,XAG,EUR"{
"success": true,
"timestamp": 1792834892,
"date": "2026-10-24",
"base": "USD",
"rates": {
"XAU": 0.0002501319,
"USDXAU": 3997.89,
"XAG": 0.0185392857,
"USDXAG": 53.94,
"EUR": 0.8925,
"USDEUR": 1.1204
},
"rate_limit": { "limit": 10000, "remaining": 9875, "reset": 1793491200, "used": 125, "plan": "Standard", "reset_date": "2026-11-01T00:00:00.000Z" }
}Historical rates
/api/v1/{YYYY-MM-DD}Closing rates for a past day. Use /yesterday as a shortcut, or /historical?date=YYYY-MM-DD. For weekends and holidays the most recent trading day's close is returned.
History: currencies since 1999-01-04, metals and energy since 2000, crypto since 2014.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
base | Currency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU. |
currencies | Comma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored. |
unit | Weight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto. |
curl "https://metalapi.com/api/v1/2024-01-15?api_key=YOUR_API_KEY¤cies=XAU,XAG"{
"success": true,
"timestamp": 1705276800,
"historical": true,
"date": "2024-01-15",
"base": "USD",
"rates": {
"XAU": 0.0004874244,
"USDXAU": 2051.6,
"XAG": 0.0431741646,
"USDXAG": 23.162
},
"rate_limit": { "...": "..." }
}Convert
/api/v1/convertConvert an amount from one symbol to another, at the latest rate or on a given date.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
fromzorunlu | Symbol to convert from. |
tozorunlu | Symbol to convert to. |
amountzorunlu | Amount to convert (decimal). |
date | Optional YYYY-MM-DD for a historical conversion. |
unit | Weight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto. |
curl "https://metalapi.com/api/v1/convert?api_key=YOUR_API_KEY&from=USD&to=XAU&amount=1000&unit=gram"{
"success": true,
"query": { "from": "USD", "to": "XAU", "amount": 1000, "unit": "gram" },
"info": { "timestamp": 1792834892, "rate": 0.0077799, "quote": 0.0077799 },
"date": "2026-10-24",
"result": 7.7799,
"rate_limit": { "...": "..." }
}Timeframe
/api/v1/timeframeDaily closing rates between two dates (inclusive). /timeseries is an alias that returns "timeseries": true. Maximum range: 30 days on Free, 365 days on paid plans.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
start_datezorunlu | YYYY-MM-DD |
end_datezorunlu | YYYY-MM-DD |
base | Currency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU. |
currencies | Comma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored. |
unit | Weight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto. |
curl "https://metalapi.com/api/v1/timeframe?api_key=YOUR_API_KEY&start_date=2026-10-19&end_date=2026-10-23¤cies=XAU"{
"success": true,
"timeframe": true,
"start_date": "2026-10-19",
"end_date": "2026-10-23",
"base": "USD",
"rates": {
"2026-10-19": { "XAU": 0.0002403788, "USDXAU": 4160.1 },
"2026-10-20": { "XAU": 0.0002413943, "USDXAU": 4142.6 },
"2026-10-21": { "XAU": 0.0002409639, "USDXAU": 4150 },
"2026-10-22": { "XAU": 0.0002462812, "USDXAU": 4060.4 },
"2026-10-23": { "XAU": 0.0002495072, "USDXAU": 4007.9 }
},
"rate_limit": { "...": "..." }
}Change
/api/v1/changeHow each rate moved between two dates, as absolute and percentage change.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
start_datezorunlu | YYYY-MM-DD |
end_datezorunlu | YYYY-MM-DD |
base | Currency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU. |
currencies | Comma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored. |
curl "https://metalapi.com/api/v1/change?api_key=YOUR_API_KEY&start_date=2026-01-02&end_date=2026-10-23¤cies=XAU"{
"success": true,
"change": true,
"start_date": "2026-01-02",
"end_date": "2026-10-23",
"base": "USD",
"rates": {
"XAU": { "start_rate": 0.0002309682, "end_rate": 0.0002495072, "change": 0.000018539, "change_pct": 8.02665 },
"USDXAU": { "start_rate": 4329.6, "end_rate": 4007.9, "change": -321.7, "change_pct": -7.43025 }
},
"rate_limit": { "...": "..." }
}Open / High / Low / Close
/api/v1/ohlcDaily OHLC for a date (default: today, intraday so far). Both directions are returned: USDXAU in USD per unit and XAU as the inverse.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
date | YYYY-MM-DD or latest (default). |
base | Currency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU. |
currencies | Comma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored. |
unit | Weight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto. |
curl "https://metalapi.com/api/v1/ohlc?api_key=YOUR_API_KEY&date=2026-10-23¤cies=XAU"{
"success": true,
"ohlc": true,
"date": "2026-10-23",
"base": "USD",
"rates": {
"USDXAU": { "open": 4042.2, "high": 4050.2, "low": 3989.1, "close": 4007.9 },
"XAU": { "open": 0.000247390, "high": 0.000250683, "low": 0.000246901, "close": 0.000249507 }
},
"rate_limit": { "...": "..." }
}Gold by karat
/api/v1/caratGold price for jewellery karats (purity = karat / 24). Paid plans.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
carat | 24 (default), 23, 22, 21, 20, 18, 16, 14, 12, 10, 9, 8 or all. |
base | Currency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU. |
unit | Weight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto. |
date | Optional YYYY-MM-DD. |
curl "https://metalapi.com/api/v1/carat?api_key=YOUR_API_KEY&carat=22&unit=gram&base=EUR"{
"success": true,
"carat": "22",
"date": "2026-10-24",
"base": "EUR",
"timestamp": 1792834892,
"rates": {
"XAU22K": { "price": 105.5297, "unit": "gram", "carat": "22", "purity": 0.916667 }
},
"rate_limit": { "...": "..." }
}Symbols
/api/v1/symbolsFree — does not count towards your quota.Every supported symbol and its name. Add details=1 for category and unit.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
details | 1 to return an array with code, name, category, unit. |
curl "https://metalapi.com/api/v1/symbols?api_key=YOUR_API_KEY"{
"success": true,
"symbols": {
"XAU": "Gold",
"XAG": "Silver",
"XPT": "Platinum",
"XPD": "Palladium",
"XCU": "Copper",
"USD": "US Dollar",
"EUR": "Euro",
"BTC": "Bitcoin"
},
"rate_limit": { "...": "..." }
}Usage
/api/v1/usageFree — does not count towards your quota.Your requests this month and what is left.
| Parametre | Açıklama |
|---|---|
api_keyzorunlu | Your API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>. |
curl "https://metalapi.com/api/v1/usage?api_key=YOUR_API_KEY"{
"success": true,
"usage": {
"requests_made": 125,
"requests_quota": 10000,
"requests_remaining": 9875,
"plan": "standard",
"period_start": "2026-10-01T00:00:00.000Z",
"period_end": "2026-11-01T00:00:00.000Z"
},
"result": { "plan": "Standard", "used": 125, "total": 10000, "remaining": 9875 },
"rate_limit": { "...": "..." }
}Gerçek zamanlı akış (SSE)
/api/v1/streamPro ve üzeri planlarPlanınızın güncelleme aralığında (5–60 sn) prices olayları gönderen bir Server-Sent Events akışıdır; /latest ile aynı base, currencies ve unit parametrelerini kullanır. Her 15 saniyede bir yorum satırı olarak heartbeat gönderilir. Her bağlantı açıldığında bir istek, açık kaldığı süre boyunca da dakikada bir istek harcar.
const es = new EventSource(
"https://metalapi.com/api/v1/stream?api_key=YOUR_API_KEY¤cies=XAU,XAG,EUR"
);
es.addEventListener("prices", (e) => {
const { timestamp, rates } = JSON.parse(e.data);
console.log(timestamp, rates.USDXAU);
});
es.addEventListener("error", (e) => console.warn("stream error", e));event: prices
data: {"timestamp":1792834897,"base":"USD","rates":{"XAU":0.0002501,"USDXAU":3998.12,"XAG":0.01853,"USDXAG":53.97}}Birimler ve alış/satış
Metal fiyatları, unit parametresi göndermediğiniz sürece troy ons başınadır: gram, kilogram, ounce (avoirdupois), pound, metric_ton veya short_ton. Birim yalnızca metaller için geçerlidir — döviz, enerji (varil, MMBtu, galon) ve kripto için yok sayılır. Bir metal base olarak kullanıldığında da uygulanır.
Standard ve üzeri planlarda, bir koda -BID / -ASK ekleyerek alış ve satış fiyatlarını isteyebilirsiniz, ör. currencies=XAU,XAU-BID,XAU-ASK. Bu durumda yanıt, orta fiyatın yanında XAU-BID ve USDXAU-BID değerlerini de içerir.
Kotalar ve istek limitleri
Her planın aylık bir istek kotası (her ayın 1'inde, 00:00 UTC'de sıfırlanır) ve dakika başına bir limiti vardır. Her ikisi de her yanıtta bildirilir:
X-RateLimit-Limit: 10000 # monthly quota
X-RateLimit-Remaining: 9875
X-RateLimit-Used: 125
X-RateLimit-Reset: 1793491200 # unix time of the next reset
X-RateLimit-Reset-Date: 2026-11-01T00:00:00.000Z
X-RateLimit-Plan: Standard
X-RateLimit-Minute-Limit: 60
X-RateLimit-Minute-Remaining: 58
Retry-After: 21 # only on 429 responses/symbolsve/usageücretsizdir.- İstek limitleri, plan kısıtlamaları, alan adı kısıtlamaları veya sunucu hataları nedeniyle reddedilen istekler ücretlendirilmez.
- Doğrulama hataları (2xx kodları) kotadan düşülür; bu nedenle bir döngü içinde yeniden denemeden önce girdiyi doğrulayın.
Planınız verinin güncelliğini de belirler: Free bir önceki günün kapanışını, Lite 30 dakikalık, Standard 10 dakikalık, Advanced/Pro 60 saniyelik, Ultra/Business 15 saniyelik ve Enterprise 5 saniyelik veriyi görür. Planları karşılaştırın.
Hatalar
{
"success": false,
"error": { "code": 105, "type": "quota_exceeded", "info": "User has reached or exceeded his subscription plan's monthly API request allowance" },
"rate_limit": { "limit": 100, "remaining": 0, "used": 100, "plan": "Free", "...": "..." }
}| Kod | HTTP | Tür | Anlamı |
|---|---|---|---|
| 101 | 401 | no_api_key | No API key was supplied. |
| 102 | 401 | invalid_api_key | The key does not exist or was revoked. |
| 103 | 403 | account_inactive | The account is suspended. Contact support. |
| 104 | 429 | too_many_requests | Per-minute rate limit exceeded. Retry after the Retry-After seconds. |
| 105 | 429 | quota_exceeded | Monthly quota used up. Resets on the 1st (UTC) or upgrade your plan. |
| 106 | 403 | plan_restriction | Endpoint or parameter not available on your plan. |
| 107 | 403 | origin_not_allowed | Browser request from a domain the key is not restricted to. |
| 201 | 400 | invalid_base | Unknown base. |
| 202 | 400 | invalid_from | Unknown from. |
| 203 | 400 | invalid_to | Missing or unknown to. |
| 204 | 400 | invalid_amount | Missing or non-numeric amount. |
| 205 | 400 | invalid_date | Not a valid YYYY-MM-DD date, or a future date. |
| 206 | 400 | invalid_timeframe | Missing dates or start_date after end_date. |
| 207 | 400 | timeframe_too_long | Range longer than your plan allows. |
| 208 | 400 | invalid_symbols | None of the requested currencies exist. |
| 209 | 400 | invalid_unit | Unknown unit. |
| 210 | 400 | invalid_carat | Unknown carat. |
| 300 | 404 | no_results | No data for this query (e.g. before history starts). |
| 404 | 404 | invalid_function | Unknown endpoint. |
| 500 | 500 | server_error | Unexpected error. The request is not billed; retry later. |
| 503 | 503 | service_unavailable | Price data temporarily unavailable. |
Webhook'lar
Fiyat alarmları (panel → Alerts) sizi e-posta veya bir HTTPS webhook'u ile bilgilendirebilir (Advanced ve üzeri planlar). Her gönderim JSON gövdeli bir POST isteğidir ve başarısız olursa en fazla üç kez yeniden denenir. İmzayı panelinizde gösterilen webhook gizli anahtarıyla doğrulayın:
import crypto from "node:crypto";
// Express example: use the raw request body.
app.post("/metalapi-webhook", express.raw({ type: "application/json" }), (req, res) => {
const header = req.get("X-MetalAPI-Signature") ?? ""; // "t=1792834892,v1=5f0c…"
const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const expected = crypto
.createHmac("sha256", process.env.METALAPI_WEBHOOK_SECRET)
.update(`${t}.${req.body}`)
.digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
if (!fresh || !crypto.timingSafeEqual(Buffer.from(v1, "hex"), Buffer.from(expected, "hex"))) {
return res.status(400).end();
}
const event = JSON.parse(req.body); // { event: "alert.triggered", alert: {...}, price: 4012.5 }
res.status(200).end();
});Widget'lar
Panelde bir widget oluşturun ve gömme kodunu istediğiniz sayfaya yapıştırın. Widget'lar otomatik olarak güncellenir ve API anahtarınızı asla açığa çıkarmaz.
<div id="metalapi-widget-w_abc123"></div>
<script src="https://metalapi.com/js/widget.js" data-widget="w_abc123" async></script>Veriler ve piyasa saatleri
- Spot değerli metaller ve başlıca dövizler: bankalar arası alış/satış akışları, yaklaşık 5 saniyede bir toplanır.
- Endüstriyel metaller ve enerji: COMEX, NYMEX ve ICE en yakın vadeli kontratları.
- Diğer dövizler: piyasa kotasyonları; yedek olarak Avrupa Merkez Bankası referans kurları.
- Kripto: Kraken ve Binance, 7/24.
- Birden fazla kaynak medyan ile birleştirilir ve yayınlanmadan önce hatalı fiyatlara karşı kontrol edilir.
- Metaller, döviz ve vadeli kontratlar New York saatiyle pazar 17:00'den cuma 17:00'ye kadar işlem görür. Hafta sonu fiyatlar cuma kapanışında sabit kalır.
- Metaller için Ekim 2026 öncesine ait günlük geçmiş veriler, en yakın vadeli kontratların uzlaşma fiyatlarına dayanır.
Fiyatlar gösterge niteliğindedir ve yalnızca bilgi amaçlıdır; alım satım teklifi değildir.
Eski endpoint'ler
Önceki sürüme ait şu endpoint'ler uyumluluk için kullanılmaya devam etmektedir:
/api/v1/rates/metals,/api/v1/rates/metal/{symbol}— meta verileriyle birlikte USD fiyatları./api/v1/rates/currencies,/api/v1/rates/currency/{code}— USD başına döviz kurları./api/v1/timeseries—/timeframeiçin takma ad;/api/v1/historical?date=—/{date}ile aynı./api/v1/user— hesap özeti (ücretsiz).