Get New Taiwan Dollar (TWD) - N/A prices using this API with hourly polling examples
If you need New Taiwan Dollar (TWD) prices for precious and industrial metals with an hourly polling workflow, this guide shows exactly how to do it using the Metals-API JSON REST service. We’ll convert metal prices into TWD for live product pricing, hedging dashboards, and quant backtests; schedule hourly updates; and cover practical details like units (troy ounces vs grams), base currency handling, timestamps and time zones, weekend/holiday behavior, and caching. You’ll see concrete requests, a JavaScript polling snippet, and realistic JSON responses you can wire into your tools right away. To follow along, you’ll need a free API key from the Metals-API Website.
Why quote metals in New Taiwan Dollar (TWD)?
Taiwan’s export-driven manufacturing, electronics, and jewelry ecosystems increasingly rely on programmatic data to manage exposure to gold, silver, platinum, copper, aluminum, and other metals. Quoting in TWD removes conversion noise for Taiwanese customers and accounting systems, supports tighter P&L control, and improves the user experience in local fintech products. In digital transformation initiatives, bringing metal prices to TWD aligns ERP, invoicing, and procurement flows end-to-end and lets analytics teams build smarter hedging signals, alerts, and forecasts native to the home currency.
Key outcomes you’ll implement here
- Fetch live metal prices and express them in TWD per troy ounce, then optionally convert to grams or kilograms.
- Schedule hourly polling with lightweight caching to control request volume.
- Backfill daily historical TWD pricing using a time-series pull for analytics.
- Handle timestamps, weekend/holiday behavior, and edge cases gracefully.
What this API provides and the endpoints we’ll use
Metals-API delivers real-time and historical precious and industrial metals prices, plus currency rates, via a simple JSON REST API. For TWD workflows, we will focus on two to three endpoints that directly support hourly pricing and analytics:
- Latest Rates: get the most recent rates. We’ll use this when polling hourly to stay updated.
- Convert: return a converted amount between any two symbols. We’ll use this to quote a specific metal directly in TWD.
- Time-Series: backfill daily closing prices to power charts, risk models, and reports in TWD.
For detailed coverage of every endpoint and parameter, see the Metals-API Documentation. To confirm the exact symbol codes you’ll use (e.g., TWD for New Taiwan Dollar, and the metal symbols), use the Metals-API Supported Symbols page.
How TWD pricing works in practice
By default, Metals-API returns rates relative to USD and denominated in troy ounces for metals. There are two practical ways to get TWD prices per troy ounce:
- Use the Convert endpoint to ask for 1 troy ounce of a metal priced in TWD directly (from=XAU, to=TWD, amount=1). This returns “TWD per troy ounce.”
- Alternatively, fetch Latest for the metal (USD-base), fetch USD→TWD via currency rates, and compute locally. Convert is simpler and reduces moving parts.
In both approaches, ensure you normalize units consistently (troy ounce vs gram) across your app and note the timestamp and base currency shown in responses. Metals-API timestamps are Unix epoch seconds; dates are ISO 8601. Prices are per troy ounce unless you explicitly convert amounts or compute different units locally.
Endpoint 1: Latest Rates for hourly updates
Purpose: retrieve the latest exchange rates for supported symbols. Depending on your plan, updates are available every 60 minutes, 10 minutes, or faster. For hourly polling, this endpoint provides a stable cadence.
Typical request flow for TWD workflows
- Use Latest Rates to capture the freshest metal reference prices.
- If you also need the corresponding TWD conversion factor for local calculations, you can perform an additional conversion via the Convert endpoint. Many developers prefer Convert directly to get a one-shot “TWD per ounce” result (see next section).
Latest Rates: example JSON (structure)
The core structure of a successful response looks like this:
{
"success": true,
"timestamp": 1790035866,
"base": "USD",
"date": "2026-09-22",
"rates": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912,
"XPD": 0.000744,
"XCU": 0.294118,
"XAL": 0.434783,
"XNI": 0.142857,
"XZN": 0.344828
},
"unit": "per troy ounce"
}
How to interpret the fields you’ll actually use
- success: Boolean indicating whether the query succeeded.
- timestamp: Unix epoch seconds for the data snapshot; use this to version your cache and align with your time zone.
- base: Currency used for the rates (default USD). Values in rates are metals-per-USD in troy ounces. For example, XAU=0.000482 means 1 USD buys 0.000482 troy ounces of gold.
- date: ISO date (UTC) associated with the timestamp.
- rates: Object keyed by metal symbols.
- unit: Expected to be “per troy ounce” for metals.
Using Latest Rates with TWD
Two paths:
- If you plan to compute TWD prices locally, also fetch or compute USD→TWD and convert “metals per USD” into “TWD per ounce.”
- Otherwise, skip direct math and use the Convert endpoint to obtain TWD quotes per ounce in a single call.
Recommendation: prefer Convert for production simplicity. Use Latest as a quick heartbeat for metal directions or if you need to bulk-load a metal basket once per hour and then convert selected items to TWD on demand.
Endpoint 2: Convert (recommended for TWD quotes)
Purpose: return a conversion result between any two symbols, including currency-to-metal, metal-to-currency, and metal-to-metal. To quote a metal in TWD per ounce, request from=the metal symbol, to=TWD, amount=1. That gives a ready-to-display TWD price per troy ounce.
Realistic curl example: 1 troy ounce of gold (XAU) in TWD
curl "https://metals-api.com/api/convert?access_key=YOUR_API_KEY&from=XAU&to=TWD&amount=1"
Realistic JSON response (structure)
{
"success": true,
"query": {
"from": "XAU",
"to": "TWD",
"amount": 1
},
"info": {
"timestamp": 1790035866,
"rate": 0.000482
},
"result": 0.000482,
"unit": "troy ounces"
}
Notes:
- query: Echoes the conversion request.
- info.timestamp: Unix epoch seconds for the conversion’s reference time; align this with your caching logic.
- info.rate: The applied rate between from and to. Interpret carefully based on symbols; when from is a metal, result typically represents target units per the specified amount.
- result: The converted value for the supplied amount.
- unit: “troy ounces” indicates the metal quantity unit when amount represents ounces. If you passed amount=1 from a metal symbol, treat result as the destination’s value per one troy ounce of that metal, aligned with Metals-API’s unit conventions.
Hourly JavaScript polling example
This snippet polls once per hour to keep a local cache of gold (XAU) quoted in TWD per troy ounce. You can extend it to multiple symbols or different cadences subject to your plan.
const API_KEY = process.env.METALS_API_KEY; // or hardcode for testing only
const ENDPOINT = "https://metals-api.com/api/convert";
const SYMBOL_FROM = "XAU"; // metal
const SYMBOL_TO = "TWD"; // New Taiwan Dollar
const AMOUNT = 1; // 1 troy ounce
async function fetchTwdPerOunce() {
const url = `${ENDPOINT}?access_key=${API_KEY}&from=${SYMBOL_FROM}&to=${SYMBOL_TO}&amount=${AMOUNT}`;
const res = await fetch(url, { timeout: 10000 });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = await res.json();
if (!json.success) throw new Error(`API error: ${JSON.stringify(json)}`);
// Persist to cache with timestamp
return {
ts: json.info.timestamp,
symbol: SYMBOL_FROM,
ccy: SYMBOL_TO,
amount: AMOUNT,
result: json.result,
unit: json.unit
};
}
// initial run
fetchTwdPerOunce().then(console.log).catch(console.error);
// hourly polling (3600000 ms)
setInterval(() => {
fetchTwdPerOunce().then(console.log).catch(console.error);
}, 3600000);
Practical guidance for Convert in TWD pricing
- Units: Metals-API quotes metals per troy ounce by default. If your app uses grams:
- 1 troy ounce = 31.1034768 grams.
- To get TWD per gram: TWD_per_oz / 31.1034768.
- To get TWD per kilogram: TWD_per_oz * (1000 / 31.1034768).
- Timestamps: Use info.timestamp to determine staleness. Store it alongside your cached price.
- Time zone: Treat timestamps as UTC when rendering charts; convert to Asia/Taipei in the UI layer if needed.
- Weekends/holidays: Metals and FX liquidity is lower outside trading hours. Expect fewer updates; plan for unchanged prices and do not assume continuous intraday ticks.
- Caching: Cache results for at least the plan’s documented update frequency (e.g., every 60 minutes on standard plans). If you poll faster than data updates, your cache will prevent redundant downstream recomputations.
Endpoint 3: Time-Series (daily history in TWD)
Purpose: retrieve daily historical rates between two dates. Use this to build TWD-denominated charts and backtests. Because time-series returns daily values, pair it with Convert logic if you want the final series expressed in TWD.
Time-Series JSON example (structure)
{
"success": true,
"timeseries": true,
"start_date": "2026-09-15",
"end_date": "2026-09-22",
"base": "USD",
"rates": {
"2026-09-15": {
"XAU": 0.000485,
"XAG": 0.03825,
"XPT": 0.000915
},
"2026-09-17": {
"XAU": 0.000483,
"XAG": 0.0382,
"XPT": 0.000913
},
"2026-09-22": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912
}
},
"unit": "per troy ounce"
}
Turning daily USD-based values into TWD
If your plan allows converting directly within time-series, use that. Otherwise, a robust approach is:
- Pull daily metal rates (USD base) via Time-Series.
- For each date, obtain or compute the USD→TWD factor for the same day.
- Convert to “TWD per troy ounce” for each date in your pipeline.
This gives you a daily TWD-denominated OHLC or close-only series suitable for charts and analytics. If you want open/high/low/close specifically, see the OHLC endpoint in the Metals-API Documentation.
Hourly polling architecture for TWD
Minimal viable loop
- Scheduler: trigger once per hour (cron, serverless scheduled job, or a lightweight worker).
- Request: for each metal you care about, call Convert with from=metal, to=TWD, amount=1.
- Cache: upsert by symbol, store price, unit, timestamp, and response JSON for auditability.
- Consumers: pricing widgets, ERP hooks, or alerting services read from the cache.
Scaling to many symbols
- Batching: keep a queue of symbols and rate-limit the request stream.
- Deduplication: if the new timestamp hasn’t advanced since your last snapshot, skip downstream invalidations.
- Backoff: on transient errors, retry with jitter, then fall back to last-known-good values.
Caching strategy
- TTL: set to the plan’s documented update cadence (e.g., 60 minutes).
- Versioning: key cache entries by symbol and timestamp; maintain a small history.
- Invalidation: only invalidate if the timestamp increases or the “success” value is true and data changed meaningfully.
Data handling details developers often miss
Units and conversions
- Default unit: troy ounces (ozt). 1 ozt = 31.1034768 grams, not the same as avoirdupois ounces.
- Grams: display TWD per gram by dividing TWD per troy ounce by 31.1034768.
- Carats: if pricing gold jewelry, consider using the Carat endpoint for karat-based rates. See docs for availability and plan requirements.
Base currency awareness
- Latest and Time-Series commonly use base USD for metals.
- Convert is the cleanest way to obtain TWD-denominated metal prices with minimal assumptions.
Timestamps and time zones
- Timestamps are Unix epoch seconds; convert to ISO for logging and UI.
- Use UTC for storage; convert to Asia/Taipei at render time to reduce confusion.
- For daily series, treat dates as closing values for that day in UTC unless otherwise clarified.
Weekends and market closures
- Metals and FX may be less active during weekends and holidays; expect stable values or fewer updates.
- Do not infer missing intraday ticks as zero or NaN; carry forward the last-known-good price until a new timestamp arrives.
Example: comparing symbols and TWD usage
Before integrating, confirm symbols for the metals you’ll convert into TWD. For the definitive list, consult the Metals-API Supported Symbols. Below is a conceptual comparison of how you might track a few symbols in TWD for pricing workflows:
| Purpose | Metal Symbol | Currency | Unit | Recommended Endpoint |
|---|---|---|---|---|
| Price 1 ozt in TWD every hour | XAU | TWD | troy ounces | Convert |
| Daily close backfill for TWD charts | XAU | TWD | troy ounces | Time-Series + Convert logic |
| Heartbeat on latest metals | XAU, XAG, XPT… | USD (internal), then TWD | troy ounces | Latest (plus Convert) |
End-to-end workflow example for a Taiwan-based e-commerce catalog
- Every hour, call Convert with from=XAU, to=TWD, amount=1 and write result to storage. Repeat for other required metals.
- For catalog items priced per gram, divide the TWD per ounce price by 31.1034768 to derive TWD per gram; multiply by item weight to compute retail price.
- Add a rounding rule and VAT logic specific to your region; store final TWD retail price and a timestamp for audit.
- Expose a read-only endpoint or cache that your storefront and ERP can query, ensuring they see synchronized TWD prices with proper cache headers.
Advanced practices and optimization
Aggregating multiple symbols safely
- Batch scheduling: stagger symbol requests within your hourly window to distribute load.
- Atomic updates: write new prices to a temp table keyed by timestamp, then atomically swap your active view when all symbols for that cycle succeed.
- Fallback hierarchy: if one symbol fails, retry with exponential backoff; if retries exceed a threshold, serve last-known-good and flag monitoring.
Observability
- Log each Convert call with duration, HTTP status, success flag, and timestamp.
- Track the change magnitude between cycles; alert on abnormal jumps to catch upstream anomalies or integration bugs.
Security best practices
- Store your Metals-API key in a secret manager or environment variable, not in source control.
- Use HTTPS exclusively and validate response structure before trusting values.
- Implement input validation for user-selectable symbols; only allow whitelisted symbols from the official symbols list.
Error handling and resilience
- HTTP errors: retry with backoff on 5xx; for 4xx, inspect the body for actionable messages (e.g., invalid symbol) and correct your request.
- API errors: if success=false, log error details and continue with last-known-good data.
- Timeouts: keep practical timeouts (e.g., 10 seconds) and treat them as transient failures with retries.
- Data validation: enforce numeric checks on result fields and reasonable bounds (e.g., reject negative prices).
Putting it all together: a robust hourly TWD pipeline
- Symbols: define the metal symbols you need in TWD, verified against the Supported Symbols list.
- Scheduler: run every 60 minutes (or per your plan’s update interval).
- Fetch: use the Convert endpoint for each symbol with amount=1 and to=TWD.
- Validate: confirm success, timestamp monotonicity, and non-null numeric results.
- Normalize: compute grams/kg if needed and store both raw and derived values.
- Persist: write to a versioned store keyed by symbol and timestamp.
- Publish: atomically update a cache for downstream apps; expose timestamps with your payloads.
- Monitor: alert on stale timestamps or extreme deltas.
Getting started: your next steps
- Sign up and obtain your free API key from the Metals-API Website.
- Review parameters and response schemas in the Metals-API Documentation.
- Verify your exact metal and currency symbols using the Metals-API Supported Symbols page.
- Implement the Convert endpoint call for from=your metal, to=TWD, amount=1 and schedule hourly polling.
- Add unit conversions (grams/kg) and caching to optimize performance and costs.
Additional notes on innovation, analytics, and future trends in TWD metal pricing
As Taiwanese fintech, e-commerce, and manufacturing continue adopting smart technology, TWD-denominated metal feeds become a foundation for:
- Algorithmic pricing: AI models adjusting margins based on TWD volatility and commodity trends.
- Automated hedging: programmatically triggering TWD hedges when metal moves breach value-at-risk thresholds.
- IoT-integrated procurement: machines reserving material at TWD prices, aligned with throughput forecasts to reduce inventory risk.
- Predictive analytics: combining TWD metal prices with macro indicators to anticipate demand and optimize cash flow.
By integrating hourly TWD prices now, you set the stage for these higher-order capabilities with minimal rework later.
FAQ
How do I get a TWD price for a specific metal without manual math?
Use the Convert endpoint with from set to the metal symbol, to=TWD, and amount=1. That returns a TWD-per-troy-ounce quote ready for display.
How often should I poll?
Match your plan’s update frequency. For hourly updates, poll once per hour and cache results. Polling faster than data updates yields no practical benefit and wastes requests.
What unit should I display for end users in Taiwan?
Most upstream data is per troy ounce. If your end users prefer grams or kilograms, convert using 1 ozt = 31.1034768 g. Display “TWD/g” or “TWD/kg” accordingly.
Do I need to handle weekends differently?
Expect fewer updates and occasionally unchanged values. Use last-known-good prices and detect when a fresh timestamp appears before invalidating caches.
Where can I find all valid symbols?
Refer to the Metals-API Supported Symbols page for the authoritative list of metals and currencies, including TWD.
How do I get started?
Get a free API key at the Metals-API Website, review the Metals-API Documentation, and implement the Convert call with hourly polling. This will give you reliable TWD-denominated metal prices for production use cases.