Egyptian Pound (EGP) - N/A Price API in PHP: Getting Started Guide
You need to display or convert prices in Egyptian Pound (EGP) from your PHP backend—whether to quote a jewelry SKU in EGP, settle an invoice, or localize a dashboard—and you want a fast, reliable API call you can ship today. By the end of this guide you will fetch the latest USD⇄EGP rate with PHP cURL, understand the response structure (including the inverted USDEGP field), and safely turn that data into amounts your app can use.
What we’re building
We’ll implement a minimal PHP function that:
- Calls the Metals-API Latest endpoint for EGP.
- Reads rates.EGP (EGP per 1 USD) and rates.USDEGP (USD per 1 EGP).
- Performs a couple of sanity checks and simple conversions for downstream pricing.
Why Metals-API for EGP? Many teams using Metals-API for precious or industrial metals also need currency localization. The same API provides currency pairs like EGP so you can convert a USD-based metals quote to Egyptian Pound in one place.
Before you start: keys, symbols, and docs
- Create an API key: Register.
- Confirm supported codes: see EGP in Symbols.
- Reference parameters and error formats in the Documentation.
Note on plans: Metals-API updates the latest endpoint at different intervals depending on plan. If you need higher-frequency updates or enterprise options, review the marketplace at MCP. For reference, the Copper Monthly plan is $19.99/mo.
Understanding EGP fields on the Latest endpoint
Metals-API quotes are by default relative to USD (base=USD). For EGP requests you’ll typically see two relevant fields:
- rates.EGP: EGP per 1 USD (how many Egyptian Pounds you get for one US Dollar).
- rates.USDEGP: USD per 1 EGP (the inverted pair, how many US Dollars one Egyptian Pound buys).
This dual representation is convenient because pricing code sometimes needs either direction without computing inversions itself.
Quick test with curl
Run this from your terminal to fetch the latest USD⇄EGP rates. Replace YOUR_API_KEY with your actual key.
curl -s "https://metals-api.com/api/latest?access_key=YOUR_API_KEY&symbols=EGP,USD,USDEGP"
Example JSON (real response)
{"success":true,"timestamp":1790640660,"date":"2026-09-29","base":"USD","rates":{"EGP":52.10755,"USD":1,"USDEGP":0.01919107691687673}}
What you’ll actually use:
- timestamp: Unix seconds (UTC). Useful for cache keys and freshness checks.
- date: ISO date associated with the snapshot.
- base: USD here; indicates all rates are quoted relative to USD.
- rates.EGP: EGP per USD (e.g., 52.10755 EGP for 1 USD).
- rates.USDEGP: USD per EGP (e.g., ~0.01919 USD for 1 EGP).
PHP cURL implementation (production-ready minimum)
This PHP example calls the same Latest endpoint, verifies success, and exposes a tiny helper to convert values either way using the direct or inverted field.
<?php
function getLatestEgpRates(string $apiKey): array {
$url = "https://metals-api.com/api/latest?access_key=" . urlencode($apiKey) . "&symbols=EGP,USD,USDEGP";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
$raw = curl_exec($ch);
if ($raw === false) {
throw new RuntimeException("cURL error: " . curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("HTTP error: status {$status}, body: {$raw}");
}
$data = json_decode($raw, true);
if (!is_array($data) || empty($data['success'])) {
$msg = isset($data['error']['info']) ? $data['error']['info'] : 'Unknown API error';
throw new RuntimeException("API reported an error: {$msg}");
}
// Required fields check
foreach (['timestamp','date','base','rates'] as $k) {
if (!array_key_exists($k, $data)) {
throw new RuntimeException("Missing field '{$k}' in response");
}
}
foreach (['EGP','USDEGP'] as $pair) {
if (!array_key_exists($pair, $data['rates'])) {
throw new RuntimeException("Missing rate '{$pair}' in response");
}
}
return $data;
}
// Example usage
$apiKey = getenv('METALS_API_KEY') ?: 'YOUR_API_KEY';
try {
$latest = getLatestEgpRates($apiKey);
$egpPerUsd = (float)$latest['rates']['EGP']; // EGP per 1 USD
$usdPerEgp = (float)$latest['rates']['USDEGP']; // USD per 1 EGP
$asOfUtc = (int)$latest['timestamp'];
// Convert 100 USD to EGP using the direct quote
$priceInEgp = 100 * $egpPerUsd;
// Convert 1000 EGP to USD using the inverted quote
$priceInUsd = 1000 * $usdPerEgp;
echo "As of {$asOfUtc} UTC: 100 USD ≈ {$priceInEgp} EGP, 1000 EGP ≈ {$priceInUsd} USD\n";
} catch (Throwable $e) {
// Instrument this for logs / alerts in production
error_log($e->getMessage());
http_response_code(502);
echo "Upstream error fetching EGP quotes";
}
Optional: Convert endpoint for USD⇄EGP amounts
If your workflow is primarily “convert a known amount,” you can also call the Convert endpoint directly. This is handy when you want consistent rounding at the API layer. Example request converting USD to EGP (values below are illustrative):
https://metals-api.com/api/convert?access_key=YOUR_API_KEY&from=USD&to=EGP&amount=125.50
Illustrative JSON response structure:
{
"success": true,
"query": { "from": "USD", "to": "EGP", "amount": 125.5 },
"info": { "timestamp": 1790640660, "rate": 52.10755 },
"result": 6548.97
}
Fields:
- info.rate: the effective EGP per USD rate used for the conversion.
- result: your converted amount in EGP.
Tip: For many apps, calling Latest once per request cycle and doing the multiply/divide locally is faster and more cache-friendly. Use Convert when you specifically want the API to return the final amount or to centralize conversion rounding.
A tiny JavaScript example (same endpoint)
For teams with mixed stacks, here is a JS snippet that fetches the same fields and mirrors the PHP logic:
async function fetchEgpRates(apiKey) {
const url = `https://metals-api.com/api/latest?access_key=${encodeURIComponent(apiKey)}&symbols=EGP,USD,USDEGP`;
const res = await fetch(url, { method: 'GET' });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (!data.success) throw new Error(data?.error?.info || 'API error');
const egpPerUsd = Number(data.rates.EGP);
const usdPerEgp = Number(data.rates.USDEGP);
// Example: convert 250 USD to EGP and 5000 EGP to USD
return {
asOf: data.timestamp,
egpPerUsd,
usdPerEgp,
usd250ToEgp: 250 * egpPerUsd,
egp5000ToUsd: 5000 * usdPerEgp
};
}
Interpreting the base and doing safe inversions
- Base is USD by default. That means rates.X is “X per 1 USD.” For EGP, rates.EGP is EGP per USD.
- Metals-API also returns the inverted synthetic code USDEGP, which is “USD per 1 EGP.” Prefer this instead of computing 1 / rates.EGP to avoid floating-point edge cases when rates are extremely small or when the provider normalizes precision.
Caching, timestamps, and weekend behavior
- Timestamps: The timestamp field is Unix time (UTC). If your SLA allows, cache until a newer timestamp appears. Many teams cache for 30–60 seconds or align to the documented update interval in the Documentation.
- FX market hours: Currency rates typically update during 24×5 market hours. On weekends/holidays, expect the API to return the last available quote with an unchanged timestamp/date. Program your job not to treat an identical timestamp as an error.
- Retry budget: Use short timeouts with a single retry and backoff. Keep logs keyed by timestamp so you can reconcile whether a “stale” quote was expected (weekend) or unexpected (network issue).
- Versioning: If you proxy results internally, include the timestamp and base in your cache key: egp:base=USD:ts=1790640660.
Precision and formatting for EGP amounts
- Display: Many apps format EGP to 2 decimal places for UI display. For internal accounting, keep full precision from the API and round only at the final posting step.
- Rounding: Use banker's rounding on ledger entries if required by your finance policies. If you rely on the Convert endpoint’s result, store the returned value and rate used in your audit trail.
How this integrates with metals pricing
If your core quote is USD-based (for example, a per-ounce gold or copper price you already pull elsewhere in Metals-API), you can convert the final invoice to EGP using the latest USD⇄EGP rate. The currency calls shown here are intentionally decoupled from metal symbols so you can reuse them in any pricing pipeline that ends in EGP.
Practical pitfalls to avoid
- Assuming local time: The timestamp is UTC. Convert to Africa/Cairo only for display.
- Dropping the inverted pair: Keep both EGP and USDEGP to avoid manual inversion in hot code paths.
- Over-calling the API: If your users refresh frequently, cache the latest payload in memory or a KV store keyed by timestamp. Serve from cache until the timestamp changes.
- Mixing bases: If you later change the base parameter, make sure downstream math is updated accordingly. In this guide we keep base=USD and read EGP/USDEGP.
- Weekend alerts: Don’t page your team when the timestamp doesn’t move on Saturday; mark FX-closed periods as informational.
Where to verify EGP market context
- Official monetary authority: Central Bank of Egypt exchange rate resources.
- FX market overview and terms: BIS Triennial FX Survey.
Quick reference: reading EGP and USDEGP correctly
| Field | Meaning | Use for… | Example calculation |
|---|---|---|---|
| rates.EGP | EGP per 1 USD | Convert USD amounts to EGP | amount_egp = amount_usd × rates.EGP |
| rates.USDEGP | USD per 1 EGP | Convert EGP amounts to USD | amount_usd = amount_egp × rates.USDEGP |
| timestamp | Quote time (UTC, Unix seconds) | Caching, freshness checks | invalidate cache when timestamp changes |
Extending this guide
Once you have Latest and/or Convert working for EGP, browse the Documentation to add historical context for analysis or PnL reporting. The time-series and fluctuation endpoints can help quantify daily or weekly moves in EGP relative to USD so you can tailor hedging or price update policies. Always test new endpoints with EGP and verify the base/inversion rules before release.
FAQ
- Which field do I use to convert USD to EGP?
Use rates.EGP (EGP per 1 USD). Multiply your USD amount by rates.EGP. - Which field do I use to convert EGP to USD?
Use rates.USDEGP (USD per 1 EGP). Multiply your EGP amount by rates.USDEGP. - What timezone is the timestamp?
UTC Unix seconds. Convert for display; keep UTC internally for caching and comparisons. - Why didn’t the timestamp change over the weekend?
FX markets are closed on weekends/holidays, so the API returns the last available quote. Treat this as expected behavior. - Can I get historical USD⇄EGP?
Yes—query the historical or time-series endpoints with EGP. See examples in the Documentation.
Ready to add EGP pricing to your stack? Create your API key at Register, confirm symbols at Symbols, and, if you need higher-frequency updates, explore options at MCP. Ship the PHP snippet above and start returning accurate USD⇄EGP numbers today.