Chart 3 years of eBay history
eBay’s sold search shows the last few months. GET /history goes back up to 3 years, so you can see a price trend:
did a card peak last spring, is a console falling, does a toy jump every December? This guide pulls a keyword’s
history and charts the average sold price and units sold month by month.
Step 1: see the totals first
One request returns eBay’s own totals for the whole period: units sold, average, lowest and highest price, and the sell-through rate.
import requests
API = "https://api.sellercomps.com"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
r = requests.get(f"{API}/history", params={"keyword": "lego 75192", "limit": 50}, headers=HEADERS, timeout=120)
r.raise_for_status()
first = r.json()
t = first["totals"]
print(first["startDate"], "to", first["endDate"])
print(t["totalSold"], "sold, average", t["averageSoldPrice"]["display"], "sell-through", t["sellThroughPercent"], "%")With a keyword alone you get the last 3 years. Prices are in US dollars on every eBay site.
Step 2: page through the sales
Each row is a listing. A listing that sold several units has soldUnits above 1 and its average price, so weight by
units when you average.
import time
rows = first["results"]
page = first["nextPage"]
while page and page <= 20: # 20 pages x 50 = 1,000 listings, 20 requests
r = requests.get(f"{API}/history", params={"keyword": "lego 75192", "limit": 50, "page": page}, headers=HEADERS, timeout=120)
if r.status_code in (429, 503):
time.sleep(int(r.headers.get("Retry-After", 10))) # not counted, try the page again
continue
r.raise_for_status()
data = r.json()
rows += data["results"]
page = data["nextPage"]
print(len(rows), "listings")Step 3: group by month and chart
from collections import defaultdict
import matplotlib.pyplot as plt
units = defaultdict(int)
money = defaultdict(float)
for row in rows:
month = row["lastSoldDate"][:7] # YYYY-MM
n = row["soldUnits"]
price = float((row.get("soldPrice") or row["averageSoldPrice"])["amount"])
units[month] += n
money[month] += price * n
months = sorted(units)
avg = [money[m] / units[m] for m in months]
fig, ax = plt.subplots(figsize=(10, 4))
ax.plot(months, avg, marker="o", color="#0e1525")
ax.set_ylabel("Average sold price (USD)")
ax2 = ax.twinx()
ax2.bar(months, [units[m] for m in months], alpha=0.25, color="#ffcc1a")
ax2.set_ylabel("Units sold")
ax.set_xticks(months[::3])
plt.tight_layout()
plt.savefig("lego-75192.png")Rows are newest first, so a page limit cuts the oldest months. For an even chart over 3 years, run one call per
quarter with startDate and endDate and keep the first pages of each: every quarter gets its share of rows.
The same in Node
const API = "https://api.sellercomps.com";
const headers = { Authorization: "Bearer YOUR_API_KEY" };
const byMonth = new Map();
for (let page = 1; page && page <= 10; ) {
const url = new URL(`${API}/history`);
url.search = new URLSearchParams({ keyword: "lego 75192", limit: "50", page: String(page) }).toString();
const res = await fetch(url, { headers });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const data = await res.json();
for (const row of data.results) {
const month = row.lastSoldDate.slice(0, 7);
const price = Number((row.soldPrice ?? row.averageSoldPrice).amount);
const m = byMonth.get(month) ?? { units: 0, money: 0 };
m.units += row.soldUnits;
m.money += price * row.soldUnits;
byMonth.set(month, m);
}
page = data.nextPage;
}
for (const [month, m] of [...byMonth].sort()) console.log(month, m.units, (m.money / m.units).toFixed(2));Cleaner charts
clean=trueleaves out lots, parts and accessories.singleUnitOnly=truekeeps listings that sold one item, for exact per-sale prices.relevance=truedrops rows that are not the searched product.
See 3 years of eBay history for every parameter.
Costs and pace
One request per page, whatever the date range. A 20 page chart is 20 requests. History searches also have their own
pace: a burst can answer 429 history_rate_limited with a Retry-After; wait and continue, it is not counted. Very
broad keywords over 3 years answer slower; a narrower keyword or a shorter range is faster.
FAQ
Why do totals and my rows disagree?
totals covers every sale in the range. Your rows are the pages you fetched. Use totals for the headline numbers
and the rows for the shape of the trend.
Can I chart other countries?
Yes, with ebaySite. History prices are in US dollars on every site.
How far back does it go?
Up to 3 years before today. A startDate earlier than that answers 400 and is not counted.