Add market value: tiered prices and an eBay Browse provider

Researched the options first. PriceCharting is the standard for retro prices
but requires a paid subscription for both its API and its bulk download.
eBay's sold-price data sits behind the Marketplace Insights API, which is a
limited release closed to new developers. The free game-price APIs cover
current digital storefronts, not physical retro copies. So there is no free
route to sold prices, and this uses eBay Browse — active listings, which are
asking prices, labelled as such rather than presented as valuations.

Schema now holds three prices per game (loose, CIB, new), with marketValue
as whichever tier matches that copy's condition. Changing a condition
re-prices from the stored tiers with no further lookup, and the dashboard
can later show both actual value and what a collection would be worth
complete.

The judgement lives in classification and aggregation, both pure and both
tested without credentials:

  * listings are sorted into tiers from their titles, and accessories,
    reproductions and multi-game lots are discarded — a "box only" listing
    at $45 counted as a copy would halve the loose estimate for a $130 cart
  * the discard qualifier is required. The first version matched a bare
    "box", which threw out "complete in box" and "with box and manual",
    i.e. most of the CIB tier, while keeping exactly the listings the
    filter existed to remove. A test asserting on tiers rather than counts
    caught it.
  * median with an interquartile trim, since one optimist asking 50x moves
    a mean and not a median
  * sample counts travel with the estimate, because a tier drawn from two
    listings warrants less confidence than one drawn from thirty

Credentials are optional: with none set, /api/prices/status reports
configured=false and refresh answers 503 with instructions, while the rest
of the app is unaffected.

101 backend tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-04 15:21:32 -04:00
co-authored by Claude Opus 5
parent d5a0e42fed
commit ca70bcef34
19 changed files with 1475 additions and 9 deletions
+40
View File
@@ -74,6 +74,13 @@ public class Game
// captured and where it came from, because a figure with neither is not
// something you can reason about — a total is only as good as its staleness.
/// <summary>
/// The figure used for totals, sorting and display: the tier matching this
/// copy's condition when tiers are known, otherwise whatever was entered by
/// hand. Denormalised deliberately — SQLite can sort and SUM a column, and
/// recomputing a CASE across three nullable columns in every query is worse
/// than keeping one value in step via <see cref="RecalculateEffectiveValue"/>.
/// </summary>
public decimal? MarketValue { get; set; }
public DateTimeOffset? MarketValueUpdatedAt { get; set; }
@@ -82,6 +89,39 @@ public class Game
[MaxLength(100)]
public string? MarketValueSource { get; set; }
// Price sources quote per condition, and the spread between them is
// routinely a multiple. Keeping all three means changing a copy's condition
// re-prices it without another lookup, and the dashboard can answer both
// "what is this worth" and "what would it be worth complete".
public decimal? ValueLoose { get; set; }
public decimal? ValueCib { get; set; }
public decimal? ValueNew { get; set; }
/// <summary>The tier that applies to a given condition, if it is known.</summary>
public decimal? TierFor(GameCondition condition) => condition switch
{
GameCondition.Sealed => ValueNew,
GameCondition.Cib => ValueCib,
GameCondition.Loose => ValueLoose,
// Digital has no physical tier, and an unspecified condition is most
// often a loose cart or disc, which is also the conservative estimate.
_ => ValueLoose,
};
/// <summary>
/// Brings <see cref="MarketValue"/> back in step with the tiers. A hand-typed
/// figure survives: it is only replaced once a source has supplied tiers.
/// </summary>
public void RecalculateEffectiveValue()
{
var tier = TierFor(Condition);
if (tier is not null)
{
MarketValue = tier;
}
}
/// <summary>
/// Owning user. Every query is filtered on this server-side, from the JWT subject —
/// it is never accepted from the client.