Feed real-time competitor prices from PriceFetch into a rule engine that adjusts your prices automatically, respecting margin floors and price ceilings.
Dynamic pricing adjusts your product prices in response to market conditions — primarily competitor pricing, but also demand signals, inventory levels, and time of day. Airlines and hotels have done this for decades. E-commerce caught up.
The spectrum runs from simple to complex:
**Rule-based** — "Match Amazon's price minus $1, but never go below $15." Easy to implement, easy to understand, easy to debug. Start here.
**Algorithmic** — use historical price data and demand curves to find the optimal price point that maximizes revenue or profit. Requires more data and more math.
**ML-driven** — train models on price elasticity, conversion rates, and competitor behavior. Powerful but hard to explain when your CEO asks why a product costs $17.43.
For most businesses, rule-based dynamic pricing captures 80% of the value with 20% of the complexity. The price API is the foundation for all three approaches — you need accurate, real-time competitor data regardless of how sophisticated your pricing logic is.
A pricing rule has three components: a condition, an action, and constraints.
- **Condition** — when does this rule fire? (e.g., "competitor price is lower than ours") - **Action** — what do we do? (e.g., "set price to competitor price minus $0.50") - **Constraints** — what limits apply? (e.g., "minimum price $12, maximum discount 20%")
Rules are evaluated in priority order. The first matching rule wins. Always include a fallback rule that preserves the current price if no conditions match.
from dataclasses import dataclass
from decimal import Decimal
@dataclass
class PricingRule:
name: str
priority: int # Lower = higher priority
min_price: Decimal
max_discount_pct: Decimal
def evaluate(self, our_price: Decimal, competitor_price: Decimal, cost: Decimal) -> Decimal | None:
raise NotImplementedError
class UnderCutRule(PricingRule):
"""Beat the competitor by a fixed amount."""
undercut_amount: Decimal = Decimal("1.00")
def evaluate(self, our_price, competitor_price, cost):
if competitor_price < our_price:
new_price = competitor_price - self.undercut_amount
# Enforce margin floor
if new_price < cost * Decimal("1.15"): # 15% minimum margin
return None # Don't match — margin too thin
if new_price < self.min_price:
return self.min_price
return new_price
return None # Competitor isn't cheaper, no action
class MatchRule(PricingRule):
"""Match competitor price exactly."""
def evaluate(self, our_price, competitor_price, cost):
if abs(competitor_price - our_price) / our_price > Decimal("0.05"):
new_price = competitor_price
if new_price >= self.min_price and new_price >= cost * Decimal("1.10"):
return new_price
return None
def apply_rules(rules: list[PricingRule], our_price, competitor_price, cost) -> Decimal:
sorted_rules = sorted(rules, key=lambda r: r.priority)
for rule in sorted_rules:
result = rule.evaluate(our_price, competitor_price, cost)
if result is not None:
return result
return our_price # No rule matched — keep current priceThe rule engine needs fresh competitor prices. PriceFetch provides these via a single endpoint. The integration pattern is:
1. Fetch the current competitor price from PriceFetch 2. Look up your current price and cost from your product database 3. Run the rule engine 4. If the engine returns a new price, update your storefront via its API 5. Log every price change with the rule that triggered it
Run this on a schedule. For most retailers, every 4-6 hours keeps you competitive without burning through API credits. For high-velocity categories, hourly checks on your top sellers are worth the cost.
import requests
def reprice_product(sku: str, competitor_url: str, our_price: float, cost: float):
# Step 1: Get competitor price
resp = requests.get(
"https://api.pricefetch.dev/v1/price",
params={"url": competitor_url},
headers={"X-API-Key": "pf_live_abc123"},
timeout=30,
)
data = resp.json()
if not data["success"]:
return # Skip this product
competitor_price = data["data"]["price"]
# Step 2: Apply rules
from decimal import Decimal
new_price = apply_rules(
rules=MY_RULES,
our_price=Decimal(str(our_price)),
competitor_price=Decimal(str(competitor_price)),
cost=Decimal(str(cost)),
)
# Step 3: Update if changed
if float(new_price) != our_price:
update_storefront_price(sku, float(new_price))
log_price_change(sku, our_price, float(new_price), competitor_price)Automated repricing without guardrails is a fast path to selling everything at a loss. Build these safety nets:
**Margin floor** — never set a price below cost plus your minimum acceptable margin. Hardcode this as the final check before any price update.
**Maximum daily changes** — limit how many times a product's price can change per day. This prevents ping-pong wars where you and a competitor keep undercutting each other in an automated loop.
**Price band limits** — set a maximum percentage change per adjustment. A rule that would drop your price by 40% in one move probably indicates bad data, not a real market shift.
**Human review queue** — flag large price changes (say, more than 15%) for manual approval instead of auto-applying them. The automation handles the routine 1-5% adjustments; humans handle the outliers.
**Kill switch** — build a way to instantly disable automated repricing. When something goes wrong at 2 AM, you want to stop the system with one command, not debug it live.
Dynamic pricing is only worth the complexity if it moves the needle. Track these metrics:
- **Win rate** — percentage of time your price is the lowest among tracked competitors - **Average margin** — ensure dynamic pricing isn't eroding margins over time - **Revenue per product** — did repricing increase revenue, or just reduce price? - **Price change frequency** — how often are prices actually changing? Too much volatility confuses customers
Run A/B tests if you can. Keep a control group of products on static pricing and compare performance against dynamically priced products over 30-60 days. This tells you whether the system is actually generating incremental value or just adding complexity.
Sign up in 30 seconds. No credit card required. One credit per successful API call.