MetalAPI
XAU3,997.89−1.54‎%‎XAG53.936−1.51‎%‎XPT1,554.47−0.83‎%‎XPD1,047.03−0.44‎%‎XCU6.5080+2.29‎%‎WTI103.27+3.82‎%‎BRENT111.70−1.30‎%‎EUR1.120400−0.01‎%‎GBP1.337500−0.01‎%‎JPY0.0063761+0.14‎%‎CHF1.213445−0.25‎%‎TRY0.020125−0.12‎%‎BTC80,329.75−0.55‎%‎ETH2,329.36−1.13‎%‎
REST · JSON · v1

توثيق API

عنوان URL الأساسي https://metalapi.com/api/v1. جميع الاستجابات بصيغة JSON عبر HTTPS. وتستمر تكاملات MetalAPI الحالية في العمل دون أي تغيير.

البدء السريع

أنشئ حسابًا مجانيًا، وانسخ مفتاح API من لوحة التحكم، ثم اطلب أحدث أسعار الذهب والفضة:

curl "https://metalapi.com/api/v1/latest?api_key=YOUR_API_KEY&base=USD&currencies=XAU,XAG,EUR"

المصادقة

يحتاج كل طلب إلى مفتاح API الخاص بك. أرسله بإحدى ثلاث طرق (تُبقي طريقتا الترويسة المفاتيحَ خارج السجلات):

خيارات المصادقة
# 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"

تكون المفاتيح على شكل mk_live_… ولا تُعرض إلا مرة واحدة عند إنشائها، ونحن نخزّن قيمة تجزئة لها. يمكنك من لوحة التحكم إنشاء عدة مفاتيح وتسميتها وتدويرها وتقييدها بنطاقات موقعك. تُرفض الطلبات الصادرة من متصفحات على نطاقات أخرى بالخطأ 107، أما الطلبات من خادم إلى خادم فمسموح بها دائمًا.

صيغة الاستجابة

تُرجَع الأسعار في الاتجاهين. لعملة الأساس USD والرمز XAU:

  • rates.USDXAU — سعر أونصة تروي واحدة من الذهب بالدولار الأمريكي (مثلًا 3997.89).
  • rates.XAU — عدد أونصات الذهب التي يشتريها دولار أمريكي واحد (1 / 3997.89 = 0.00025013).

تتضمن كل استجابة الحقل success وكتلة rate_limit تحتوي على حصتك الشهرية. وفي حالة الخطأ تُرجَع القيمة success: false وكائن error يحتوي على code وtype وinfo. الطوابع الزمنية بثواني Unix (UTC)، والتواريخ بصيغة YYYY-MM-DD (UTC).

Latest rates

GET/api/v1/latest

Current 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.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
baseCurrency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU.
currenciesComma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored.
unitWeight 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&currencies=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

GET/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.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
baseCurrency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU.
currenciesComma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored.
unitWeight 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&currencies=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

GET/api/v1/convert

Convert an amount from one symbol to another, at the latest rate or on a given date.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
fromإلزاميSymbol to convert from.
toإلزاميSymbol to convert to.
amountإلزاميAmount to convert (decimal).
dateOptional YYYY-MM-DD for a historical conversion.
unitWeight 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

GET/api/v1/timeframe

Daily 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.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
start_dateإلزاميYYYY-MM-DD
end_dateإلزاميYYYY-MM-DD
baseCurrency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU.
currenciesComma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored.
unitWeight 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&currencies=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

GET/api/v1/change

How each rate moved between two dates, as absolute and percentage change.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
start_dateإلزاميYYYY-MM-DD
end_dateإلزاميYYYY-MM-DD
baseCurrency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU.
currenciesComma-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&currencies=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

GET/api/v1/ohlc

Daily OHLC for a date (default: today, intraday so far). Both directions are returned: USDXAU in USD per unit and XAU as the inverse.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
dateYYYY-MM-DD or latest (default).
baseCurrency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU.
currenciesComma-separated symbols to return (alias: symbols). Default: all symbols. Unknown codes are ignored.
unitWeight 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&currencies=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

GET/api/v1/carat

Gold price for jewellery karats (purity = karat / 24). Paid plans.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
carat24 (default), 23, 22, 21, 20, 18, 16, 14, 12, 10, 9, 8 or all.
baseCurrency or symbol the rates are expressed in. Default USD. Any supported symbol works, e.g. EUR, TRY, XAU.
unitWeight unit for metals: troy_oz (default), gram, kilogram, ounce, pound, metric_ton, short_ton. Ignored for currencies, energy and crypto.
dateOptional 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

GET/api/v1/symbolsFree — does not count towards your quota.

Every supported symbol and its name. Add details=1 for category and unit.

المعاملالوصف
api_keyإلزاميYour API key. Alternatively send Authorization: Bearer <key> or X-API-Key: <key>.
details1 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

GET/api/v1/usageFree — does not count towards your quota.

Your requests this month and what is left.

المعاملالوصف
api_keyإلزامي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": { "...": "..." }
}

البث اللحظي (SSE)

GET/api/v1/streamخطة Pro وما فوقها

بث Server-Sent Events يرسل أحداث prices وفق فترة التحديث في خطتك (5–60 ثانية)، مع المعاملات base وcurrencies وunit نفسها المستخدمة في /latest. تُرسَل نبضة على شكل تعليق كل 15 ثانية. ويكلّف كل اتصال طلبًا واحدًا عند فتحه وطلبًا واحدًا عن كل دقيقة يبقى فيها مفتوحًا.

المتصفح / Node.js
const es = new EventSource(
  "https://metalapi.com/api/v1/stream?api_key=YOUR_API_KEY&currencies=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}}

الوحدات والطلب/العرض

أسعار المعادن لكل أونصة تروي ما لم تمرّر unit: gram أو kilogram أو ounce (أونصة أفواردوبوا) أو pound أو metric_ton أو short_ton. تنطبق الوحدة على المعادن فقط — وتُتجاهل للعملات والطاقة (البرميل وMMBtu والغالون) والعملات المشفرة. كما تنطبق عندما يكون المعدن هو base.

في خطة Standard وما فوقها، اطلب دفتر الأسعار بإضافة -BID / -ASK إلى الرمز، مثل currencies=XAU,XAU-BID,XAU-ASK. وستتضمن الاستجابة حينها XAU-BID وUSDXAU-BID إلى جانب السعر الوسطي.

الحصص وحدود المعدل

لكل خطة حصة طلبات شهرية (تُعاد في اليوم الأول من الشهر، الساعة 00:00 UTC) وحد للطلبات في الدقيقة. ويُبلَّغ عن كليهما في كل استجابة:

الترويسات
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
  • نقطتا /symbols و/usage مجانيتان.
  • لا تُحتسب الطلبات المرفوضة بسبب حدود المعدل أو قيود الخطة أو قيود النطاق أو أخطاء الخادم.
  • تُحتسب أخطاء التحقق (الرموز 2xx)، لذا تحقّق من صحة المدخلات قبل إعادة المحاولة في حلقة.

تحدد خطتك أيضًا حداثة البيانات: ترى خطة Free سعر إغلاق اليوم السابق، وLite بيانات كل 30 دقيقة، وStandard كل 10 دقائق، وAdvanced/Pro كل 60 ثانية، وUltra/Business كل 15 ثانية، وEnterprise كل 5 ثوانٍ. قارن الخطط.

الأخطاء

استجابة خطأ
{
  "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", "...": "..." }
}
الرمزHTTPالنوعالمعنى
101401no_api_keyNo API key was supplied.
102401invalid_api_keyThe key does not exist or was revoked.
103403account_inactiveThe account is suspended. Contact support.
104429too_many_requestsPer-minute rate limit exceeded. Retry after the Retry-After seconds.
105429quota_exceededMonthly quota used up. Resets on the 1st (UTC) or upgrade your plan.
106403plan_restrictionEndpoint or parameter not available on your plan.
107403origin_not_allowedBrowser request from a domain the key is not restricted to.
201400invalid_baseUnknown base.
202400invalid_fromUnknown from.
203400invalid_toMissing or unknown to.
204400invalid_amountMissing or non-numeric amount.
205400invalid_dateNot a valid YYYY-MM-DD date, or a future date.
206400invalid_timeframeMissing dates or start_date after end_date.
207400timeframe_too_longRange longer than your plan allows.
208400invalid_symbolsNone of the requested currencies exist.
209400invalid_unitUnknown unit.
210400invalid_caratUnknown carat.
300404no_resultsNo data for this query (e.g. before history starts).
404404invalid_functionUnknown endpoint.
500500server_errorUnexpected error. The request is not billed; retry later.
503503service_unavailablePrice data temporarily unavailable.

خطافات الويب (Webhooks)

يمكن لتنبيهات الأسعار (لوحة التحكم ← Alerts) إخطارك بالبريد الإلكتروني أو عبر خطاف ويب HTTPS (خطة Advanced وما فوقها). كل عملية تسليم هي طلب POST بجسم JSON، ويُعاد إرسالها حتى ثلاث مرات عند الفشل. تحقّق من التوقيع باستخدام سر الخطاف المعروض في لوحة التحكم:

التحقق من X-MetalAPI-Signature (Node.js)
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();
});

الودجات

أنشئ ودجة من لوحة التحكم والصق شيفرة التضمين في أي صفحة. تتحدث الودجات تلقائيًا ولا تكشف مفتاح API الخاص بك أبدًا.

التضمين
<div id="metalapi-widget-w_abc123"></div>
<script src="https://metalapi.com/js/widget.js" data-widget="w_abc123" async></script>

البيانات وساعات التداول

  • المعادن الثمينة الفورية والعملات الرئيسية: مصادر أسعار الطلب/العرض ما بين البنوك، تُجمع كل 5 ثوانٍ تقريبًا.
  • المعادن الصناعية والطاقة: العقود الآجلة للشهر الأقرب في COMEX وNYMEX وICE.
  • العملات الأخرى: أسعار السوق، مع الأسعار المرجعية للبنك المركزي الأوروبي كمصدر احتياطي.
  • العملات المشفرة: Kraken وBinance، على مدار الساعة طوال أيام الأسبوع.
  • تُدمج المصادر المتعددة باستخدام الوسيط وتُفحص لاستبعاد الأسعار الشاذة قبل النشر.
  • يجري تداول المعادن والعملات والعقود الآجلة من الأحد 17:00 إلى الجمعة 17:00 بتوقيت نيويورك. وخلال عطلة نهاية الأسبوع تبقى الأسعار ثابتة عند إغلاق يوم الجمعة.
  • يستند السجل اليومي للمعادن قبل أكتوبر 2026 إلى أسعار تسوية العقود الآجلة للشهر الأقرب.

الأسعار استرشادية ولأغراض إعلامية فقط، وليست عرضًا للتداول.

نقاط النهاية القديمة

تبقى نقاط النهاية التالية من الإصدار السابق متاحة لأغراض التوافق:

  • /api/v1/rates/metals و/api/v1/rates/metal/{symbol} — أسعار بالدولار الأمريكي مع بيانات وصفية.
  • /api/v1/rates/currencies و/api/v1/rates/currency/{code} — أسعار العملات مقابل الدولار الأمريكي.
  • /api/v1/timeseries — اسم بديل لـ /timeframe؛ و/api/v1/historical?date= — مماثل لـ /{date}.
  • /api/v1/user — ملخص الحساب (مجاني).