Get Thai Baht (THB) prices using this API (REST example for developers)
You need to show live Thai Baht (THB) prices inside your app—so you can reprice a catalog in THB, run a currency-aware trading model, or alert when USD/THB crosses a threshold. By the end of this guide, you’ll fetch real-time THB rates from Metals-API’s REST /latest endpoint, parse the response, understand units and base currency, and apply the data to two concrete tasks: catalog repricing and threshold alerts.
What THB is and who needs its live price
THB (Thai Baht) is Thailand’s fiat currency, central to Southeast Asia’s manufacturing and jewelry supply chains and a common quote currency for regional trade. Developers in fintech, commodities trading, jewelry e‑commerce, and ERP systems often need an authoritative THB rate to normalize prices, optimize hedging, or localize checkout flows. With Metals-API, you can retrieve THB alongside metals and other currencies through a consistent JSON schema to power smart pricing, analytics, and automation.
Endpoint you’ll use: /latest for real-time THB
We’ll use the latest endpoint to request the current THB rate with USD as the base. Metals-API delivers currency and metals quotes in one unified API; for currency-only use, you simply request the THB symbol.
- Endpoint: /latest
- Parameters: access_key, base, symbols
- Symbol for Thai Baht: THB (verify on the Metals-API Supported Symbols)
If you’re new to the service, create an API key here: Register. For endpoint details and plan-specific refresh intervals, see the Documentation.
Fetch THB with curl (copy-pasteable)
curl "https://metals-api.com/api/latest?access_key=YOUR_API_KEY&base=USD&symbols=THB"
Replace YOUR_API_KEY with your key. This request asks for the latest exchange rates with USD as the base currency and returns only the THB symbol in the payload.
Python example to read the THB rate
import os
import time
import requests
API_KEY = os.getenv("METALS_API_KEY", "YOUR_API_KEY")
URL = "https://metals-api.com/api/latest"
params = {
"access_key": API_KEY,
"base": "USD",
"symbols": "THB"
}
resp = requests.get(URL, params=params, timeout=10)
resp.raise_for_status()
data = resp.json()
# Validate success
if not data.get("success", False):
raise RuntimeError(f"API error: {data}")
timestamp = data.get("timestamp") # Unix epoch seconds
date = data.get("date") # ISO date string
base = data.get("base") # "USD"
rates = data.get("rates", {})
thb_per_usd = rates.get("THB") # e.g., 33.6135 means 1 USD = 33.6135 THB
# Optional: some payloads may include convenience fields like USDTHB
usd_per_thb = rates.get("USDTHB")
if usd_per_thb is None and thb_per_usd:
usd_per_thb = 1.0 / thb_per_usd
print(f"Timestamp: {timestamp} ({time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))} UTC)")
print(f"Base: {base}")
print(f"THB per USD: {thb_per_usd}")
print(f"USD per THB: {usd_per_thb}")
A real JSON response you will see
Below is an official example response for the USD/THB request. Use these fields directly in your integration.
{"success":true,"timestamp":1790813280,"date":"2026-10-01","base":"USD","rates":{"THB":33.6135,"USD":1,"USDTHB":0.029749951656328558}}
What the key fields mean for your code
- success: Boolean; confirm this before using any numbers.
- timestamp: Unix epoch seconds; interpret in UTC for consistency across services and caches.
- date: An ISO date for the snapshot; useful for labeling UI or logging.
- base: The base currency of all rate quotes in the response. Here it is USD.
- rates: A dictionary of symbol to numeric quote. For currency:
- THB: 33.6135 means 1 USD = 33.6135 THB.
- USD: Typically 1 when base is USD.
- USDTHB: A convenience cross present in some payloads; here it represents USD per THB or a related computed cross. If you only need USD per THB, compute 1 / THB when base is USD.
Understanding units and inversion
For currency quotes, the “unit” concept is the quote currency per base. With base=USD:
- rates.THB = THB per USD (THB/USD). If you display “THB per $1,” use this directly.
- If you need USD/THB (USD per THB), invert: usd_per_thb = 1 / rates.THB. In the sample, 1 / 33.6135 ≈ 0.02974995, which matches the USDTHB field included in the response.
For metals, the API typically returns units per troy ounce; if you later combine metal quotes with THB, keep unit conversions (troy ounce vs grams) explicit in your code. See units and symbols on the Symbols page.
Two practical uses that ship today
1) Repricing a product catalog into THB
Scenario: Your ERP or e-commerce system stores base prices in USD and you want to localize the storefront in THB, refreshed on a schedule.
Data you’ll use:
- rates.THB for THB per USD.
- timestamp for cache freshness and UI labels (“Updated at …”).
- Optional: Inversion if you use USD per THB for internal accounting (1 / rates.THB).
Implementation steps:
- Fetch /latest with base=USD and symbols=THB.
- Multiply each USD price by rates.THB to get a raw THB figure.
- Round according to your pricing policy (e.g., to the nearest 1 THB or 0.01 THB).
- Store both the converted price and the timestamp. Only reprice when your cache TTL expires or when the timestamp changes beyond your threshold.
Example: If a ring costs 120 USD and rates.THB = 33.6135, then price_thb = 120 × 33.6135 = 4,033.62 THB (before rounding and tax/shipping). Keep tax and fees in THB to avoid repeated conversions.
2) An alert when USD/THB breaks a threshold
Scenario: A trading model or treasury dashboard must trigger a Slack or email alert if USD/THB drops below 0.0298 (i.e., THB strengthens), or rises above 0.0300 (THB weakens).
Data you’ll use:
- rates.THB (THB per USD) and its inversion for USD per THB.
- timestamp to ensure you’re not alerting on stale data.
Implementation tips:
- Get /latest with base=USD and symbols=THB.
- Compute usd_per_thb = 1 / rates.THB if USDTHB is not already provided in the response.
- Compare usd_per_thb to the configured bounds and publish the event only if the new timestamp is greater than your last processed timestamp.
- Debounce alerts to avoid spam during choppy moves (e.g., notify only on crossing, not while inside the range).
Caching, refresh intervals, and operational tips
The latest endpoint updates at plan-specific intervals. Avoid querying faster than your plan’s refresh window and use a cache to protect both latency and quotas:
- Cache scope: Key by (endpoint, base, symbols). Example cache key: latest:USD:THB.
- TTL: Align with your plan’s update frequency from the Documentation.
- Revalidation: If the response’s timestamp hasn’t changed since your last poll, keep serving from cache.
- Edge caching: Coalesce identical concurrent requests into one upstream fetch to cut API calls during traffic spikes.
Resilience patterns:
- Fallback to the most recent cached value if the latest call fails, and mark the quote as “stale” in your UI.
- Alert when data is older than your business tolerance (e.g., timestamp older than 2× your expected update interval).
- Log the exact payload you used for pricing for audit trails (timestamp, base, symbols, rates).
Time zones, weekends, and data hygiene
- timestamp is Unix epoch seconds in UTC. Always convert with UTC-aware libraries.
- date accompanies timestamp for easy labeling; the timestamp is the canonical freshness field.
- Weekends and holidays: Currencies can show fewer meaningful moves on certain non-trading days. If you need historical or time-window analysis, use the dedicated endpoints in the Documentation (historical, time-series) and respect their date constraints.
- Rounding discipline: Decide whether to round each line item or only at the cart total to minimize conversion noise.
- Auditability: Store base, symbols, and timestamp with each price you compute for reproducibility.
Security and deployment checklists
- Do not embed your API key in public repositories or client-side code. Use server-side fetching or serverless functions with encrypted environment variables.
- Set timeouts and retries with backoff; alert on repeated failures.
- Write contract tests that assert JSON fields you depend on (success, timestamp, base, rates.THB) are present before releasing.
- Monitor your cache hit rate and upstream call volume to keep latency and costs under control.
Smart integrations: where THB meets metals
Many teams price metals or jewelry in THB. With Metals-API, you can combine currency and metal quotes in one pipeline and keep unit conversions explicit:
- Currency leg: Get THB per USD (rates.THB) from /latest.
- Metal leg: If you later add metals, note that metal quotes are typically per troy ounce. Convert to grams if needed (1 troy ounce ≈ 31.1034768 grams) in your own code.
- Final price: Metal unit price in USD × USD→THB rate = THB-denominated metal price (mind the unit, fees, and margins).
For refining or LME-based workflows, review advanced endpoints in the MCP section and the main Documentation for plan availability.
Troubleshooting common issues
- rates is empty or THB missing: Confirm symbols=THB and that your key is valid. Check Supported Symbols.
- Stale data: Compare current timestamp to the previous one. If unchanged beyond your tolerance, surface a warning and retry on your backoff schedule.
- Inversion confusion: Remember with base=USD, rates.THB is THB per USD. Compute USD per THB as 1 / rates.THB if that’s what your logic expects. If present, confirm USDTHB aligns with your computed inversion.
- Spike in conversions: Implement rate-limiting and circuit breakers around your conversion service. Cache aggressively with TTL aligned to your plan.
Related references for THB and FX context
- Bank of Thailand for macro context and policy updates that may affect THB volatility.
- BIS statistics for broader FX market structure insights.
- TradingView USDTHB chart to visualize real-time movements (for operator dashboards).
FAQ
Q: How often does the /latest THB rate update?
A: Update frequency depends on your subscription plan. Check the refresh interval notes in the Documentation and set your cache TTL accordingly.
Q: What is the correct symbol for Thai Baht?
A: Use THB. You can confirm this and other symbols on the Metals-API Supported Symbols page.
Q: How do I get USD per THB from the API?
A: With base=USD, rates.THB gives THB per USD. Compute USD per THB as 1 / rates.THB. Some responses may include a convenience field like USDTHB—verify it matches your calculation before relying on it.
Q: Can I also get historical THB data?
A: Yes. Use the historical or time-series endpoints for backfills and research. See endpoint details and limits in the Documentation.
Q: How should I handle pricing on weekends or holidays?
A: Many FX markets are quieter or closed. Use the timestamp to detect staleness, keep your last good cached rate, and label the UI as “as of [date/time UTC].” Only force updates when freshness requirements are not met.
Get your key and ship your THB integration
Ready to localize prices and build THB-aware automation? Create your key and start calling /latest within minutes: Register. For endpoint parameters, examples, and plan capabilities, read the Documentation and explore advanced workflows in MCP.