Dynamic Pricing with an Exchange Rate API: Pegging Toman Prices to Live FX
Dynamic pricing with an exchange rate API keeps Toman prices in line with the dollar: formulas, rounding, update thresholds, spike guardrails and customer messaging.

- Stores selling imported goods in Iran lose margin when the dollar rises and price prints stay fixed.
- Store a base price in USD (or AED, EUR) per product and compute the Toman price from the live rate plus margin, with rounding and thresholds.
- Guardrails — minimum change, maximum jump, low-source pause, manual approval — prevent bad data from reaching the shelf.
In a market where the dollar can move several percent in a day, a fixed Toman price list is a bet. If the dollar rises you sell below replacement cost; if it falls you are overpriced. Dynamic pricing with an exchange rate API removes the guesswork. This guide explains the model, formulas and guardrails that make it safe.
toman = base × rate × (1 + margin), round to a friendly step and update the product only if the change exceeds a threshold. Pause updates when the rate is flagged low-source or jumps more than your limit, and log every change.Part of the Iranian Rial exchange rate API guide.
Which rate to use
| Your cost is in… | Rate to use | Why |
|---|---|---|
| US dollars, cash | usd sell | Replacement cost |
| Supplier in Dubai | aed sell or Dubai dollar | You pay via remittance; see AED hawala rate |
| Supplier in Turkey or Europe | try or eur | Match the invoice currency |
| Gold content | g18 | Jewellery: Iran gold price API |
The pricing formula
import math
def toman_price(base, rate, margin=0.18, fees=0.0, step=10_000):
raw = base * rate * (1 + margin) + fees
return int(math.ceil(raw / step) * step) # round up to a friendly step
# $42 product, USD sell 100,000 Toman (illustrative), 18% margin
print(toman_price(42, 100_000)) # 4,960,000- Margin covers your costs and profit; set it per category.
- Fees cover fixed costs such as shipping that are not dollar-linked.
- Rounding to 1,000 / 10,000 / 50,000 Toman keeps prices readable and avoids constant tiny changes.
When to update
| Rule | Typical setting | Purpose |
|---|---|---|
| Schedule | Every 15–60 min | Fresh enough, cheap |
| Minimum change | ≥ 1% vs current price | Avoid churn and customer confusion |
| Maximum jump | ≤ 5% per cycle without approval | Stops bad ticks reaching the shelf |
| Low-source pause | Skip when low_sources is true | No repricing on thin data at night |
| Quiet hours | Optional | Do not change prices while carts are full at peak |
Reference implementation
import os, requests
def live(symbol):
r = requests.get(f"https://api.ezrate.me/v1/rates/{symbol}",
headers={"X-API-Key": os.environ["EZRATE_KEY"]}, timeout=10)
r.raise_for_status()
return r.json()["data"]
def reprice(products, store, min_change=0.01, max_jump=0.05):
usd = live("usd")
if usd["low_sources"]:
return "skipped: low sources"
for p in products:
new = toman_price(p.base_usd, usd["sell"], p.margin)
delta = new / p.price - 1
if abs(delta) < min_change:
continue
if abs(delta) > max_jump:
store.queue_for_approval(p, new, usd)
continue
store.update_price(p, new, reason=f"usd {usd['sell']} at {usd['updated_at']}")WooCommerce users can follow the plugin-based approach in WooCommerce live Toman rates.
US Dollar265,390Toman−0.30%Communicating with customers
- Show “price updated at …” on product pages.
- Honour the price in the cart for a set time (e.g. 30 minutes) to avoid checkout surprises.
- Keep a price-history log for support and for consumer-protection questions.
- Be transparent in your terms that prices follow the exchange rate.
Common mistakes
- Using the official rate: your costs follow the free market — see official vs free market.
- Updating on every tick: customers see prices flicker.
- Mixing Rial and Toman: a 10× pricing error. See IRR vs Toman.
- No guardrails: one bad data point reprices the entire catalogue.
Designing the margin
The margin in the formula has to cover more than profit. It should absorb the cost of currency movements between the time you price a product and the time you replace your stock, payment and shipping costs that are not tied to the dollar, and the spread you pay when you buy currency. Stores with fast stock turnover can use thinner margins; stores that hold stock for months need a buffer or more frequent repricing. Review margins per category every month against actual replacement costs.
Testing before going live
- Run the repricer in “dry run” mode for a week and log the prices it would have set.
- Compare those prices with your manual prices and your actual purchase costs.
- Turn on automatic updates for one category first, then expand.
Related live rates: US dollar rate, 18K gold price, Emami coin price.

Comments (0)
Comments are shown after review. Sign-in is needed to send.


