Source code for sidequest_common.schemas.market

  1"""The guild market report: what to gather and what to craft for gold, from one auction house's sale data.
  2
  3The numbers come from a feed (``POST /api/market/feed``) that a price tracker sends for the guild's auction house:
  4each item's current price, what it really sold for and how many sell a day, plus the recipes that use them. The
  5site turns that feed into a daily and a weekly report, shown to guild members on the site and posted once a day by
  6the bot. The report only covers raw materials and crafted goods; it never names single listings or resale deals.
  7Money is copper (an ``int``).
  8"""
  9
 10from datetime import date, datetime  # pydantic needs them at runtime
 11from typing import Literal
 12
 13from pydantic import BaseModel, Field
 14
 15MARKET_FEED_DAYS = 30
 16"""Days of daily prices the feed carries for each item."""
 17MARKET_STALE_HOURS = 36
 18"""A feed older than this is too old to post: the bot skips the day's report and the site says so."""
 19MARKET_AH_CUT = 0.05
 20"""The auction house's cut of a sale at a faction house."""
 21
 22MarketReportKind = Literal["daily", "weekly"]
 23
 24
[docs] 25class MarketFeedDay(BaseModel): 26 """One day of an item's prices in the feed.""" 27 28 day: date 29 min_price: int = Field(ge=0, description="The day's lowest listed unit price, in copper. 0 if nobody listed it.") 30 market: int = Field(ge=0, description="The day's typical unit price, in copper. 0 if unknown.")
31 32
[docs] 33class MarketFeedItem(BaseModel): 34 """One item's current numbers in the feed.""" 35 36 item_id: int = Field(gt=0, description="The item's game ID.") 37 name: str = Field(min_length=1, max_length=200, description="The item's name.") 38 quality: str | None = Field(default=None, description="The item's quality, such as `COMMON` or `RARE`.") 39 stack_size: int = Field(default=1, ge=1, description="How many fit in one stack.") 40 vendor_buy: int = Field(default=0, ge=0, description="What a vendor sells it for, in copper. 0 if none does.") 41 vendor_sell: int = Field(default=0, ge=0, description="What a vendor pays for it, in copper.") 42 min_price: int = Field(ge=0, description="The lowest unit price listed now, in copper. 0 if nobody lists it.") 43 quantity: int = Field(ge=0, description="How many are listed now.") 44 market: int = Field(ge=0, description="The typical unit price over the last 14 days, in copper. 0 if unknown.") 45 sale_price: int = Field( 46 ge=0, description="The average unit price it actually sold for over the last 14 days, in copper. 0 if unknown." 47 ) 48 sold_per_day: float = Field(ge=0, description="How many sold a day, on average, over the last 14 days.") 49 days: list[MarketFeedDay] = Field( 50 default_factory=list, description=f"Up to {MARKET_FEED_DAYS} days of daily prices, oldest first." 51 )
52 53
[docs] 54class MarketFeedReagent(BaseModel): 55 """One reagent of a recipe in the feed.""" 56 57 item_id: int = Field(gt=0, description="The reagent's game ID.") 58 quantity: int = Field(gt=0, description="How many one craft uses.")
59 60
[docs] 61class MarketFeedRecipe(BaseModel): 62 """One recipe in the feed: what it makes and what it uses.""" 63 64 recipe_id: int = Field(gt=0, description="The recipe's game ID.") 65 name: str = Field(min_length=1, max_length=200, description="The recipe's name.") 66 profession: str = Field(min_length=1, max_length=60, description="The profession, such as `Alchemy`.") 67 crafted_item_id: int = Field(gt=0, description="The item it makes.") 68 crafted_quantity: float = Field(default=1, gt=0, description="How many one craft makes, on average.") 69 reagents: list[MarketFeedReagent] = Field(min_length=1, description="What one craft uses.")
70 71
[docs] 72class MarketFeed(BaseModel): 73 """``POST /api/market/feed``: one auction house's numbers. Replaces the previous feed for that house.""" 74 75 house_id: int = Field(gt=0, description="The auction house's Battle.net ID.") 76 house_name: str = Field(min_length=1, max_length=100, description="The house's name.") 77 snapshot_at: datetime = Field(description="When the auction house data behind these numbers was taken.") 78 items: list[MarketFeedItem] = Field(max_length=20_000, description="Every item the report may use.") 79 recipes: list[MarketFeedRecipe] = Field(max_length=20_000, description="Every recipe the report may use.")
80 81
[docs] 82class MarketFeedReceipt(BaseModel): 83 """What the site stored from a feed.""" 84 85 items: int = Field(description="Items stored.") 86 recipes: int = Field(description="Recipes stored.")
87 88
[docs] 89class MarketItemRef(BaseModel): 90 """An item named in the report.""" 91 92 item_id: int = Field(description="The item's game ID.") 93 name: str = Field(description="The item's name.") 94 quality: str | None = Field(default=None, description="The item's quality, such as `COMMON` or `RARE`.")
95 96
[docs] 97class MarketPoint(BaseModel): 98 """One day of an item's price, for a small chart.""" 99 100 day: date 101 price: int = Field(description="The day's typical unit price, in copper.")
102 103
[docs] 104class MarketZone(BaseModel): 105 """A zone where a material can be gathered.""" 106 107 name: str = Field(description="The zone's name.") 108 min_level: int = Field(description="The zone's lowest monster level.") 109 max_level: int = Field(description="The zone's highest monster level.")
110 111
[docs] 112class MarketGatherPick(BaseModel): 113 """A material worth gathering: what it sells for, how fast it sells, and where to get it.""" 114 115 item: MarketItemRef 116 price: int = Field(description="What one sells for, in copper, before the auction house cut.") 117 stack_size: int = Field(description="How many fit in one stack.") 118 stack_price: int = Field(description="What a full stack sells for, in copper, before the cut.") 119 sold_per_day: float = Field(description="How many sell a day.") 120 change_pct: float | None = Field( 121 description="Price change against the period before, in percent. Null without enough history." 122 ) 123 skill: int = Field(description="The gathering skill needed. 0 if any character can get it.") 124 min_level: int = Field(description="The lowest zone level where it can be gathered.") 125 max_level: int = Field(description="The highest zone level where it can be gathered.") 126 zones: list[MarketZone] = Field(description="Where to gather it, lowest level first.") 127 trend: list[MarketPoint] = Field(description="Daily prices, oldest first.")
128 129
[docs] 130class MarketGatherSection(BaseModel): 131 """The best materials for one gathering profession.""" 132 133 profession: str = Field(description="The profession, such as `Herbalism`, or `Cloth` for cloth from monsters.") 134 picks: list[MarketGatherPick] = Field(description="Best first.")
135 136
[docs] 137class MarketReagentLine(BaseModel): 138 """One reagent of a craft, with its cost.""" 139 140 item: MarketItemRef 141 quantity: int = Field(description="How many one craft uses.") 142 unit_price: int = Field(description="What one costs, in copper.") 143 from_vendor: bool = Field(description="Whether a vendor sells it for less than the auction house.")
144 145
[docs] 146class MarketCraftPick(BaseModel): 147 """A craft worth making: what it sells for, what its materials cost, and how fast it sells.""" 148 149 recipe_id: int = Field(description="The recipe's game ID.") 150 recipe_name: str = Field(description="The recipe's name.") 151 item: MarketItemRef 152 makes: float = Field(description="How many one craft makes, on average.") 153 price: int = Field(description="What one sells for, in copper, before the auction house cut.") 154 mats_cost: int = Field(description="What the materials for one craft cost to buy, in copper.") 155 profit: int = Field(description="Profit from one craft when you buy the materials, after the cut, in copper.") 156 margin_pct: float = Field(description="Profit as a percent of the material cost.") 157 sold_per_day: float = Field(description="How many sell a day.") 158 change_pct: float | None = Field( 159 description="Price change against the period before, in percent. Null without enough history." 160 ) 161 cooldown_hours: float | None = Field( 162 default=None, description="Hours before the recipe can be crafted again. Null if it has no cooldown." 163 ) 164 reagents: list[MarketReagentLine] = Field(description="The materials for one craft.") 165 trend: list[MarketPoint] = Field(description="Daily prices, oldest first.")
166 167
[docs] 168class MarketCraftSection(BaseModel): 169 """The best crafts for one crafting profession.""" 170 171 profession: str = Field(description="The profession, such as `Alchemy`.") 172 picks: list[MarketCraftPick] = Field(description="Best first.")
173 174
[docs] 175class MarketMover(BaseModel): 176 """A material or craft whose price moved a lot.""" 177 178 item: MarketItemRef 179 price: int = Field(description="What one sells for now, in copper.") 180 change_pct: float = Field(description="Price change against the period before, in percent.") 181 profession: str = Field(description="The profession that gathers or crafts it.")
182 183
[docs] 184class MarketReport(BaseModel): 185 """``GET /api/market/report``: what to gather and craft for gold on the guild's auction house.""" 186 187 kind: MarketReportKind = Field(description="`daily` compares with the week before; `weekly` with last week.") 188 house_name: str = Field(description="The auction house the numbers come from.") 189 data_at: datetime = Field(description="When the auction house data was taken.") 190 stale: bool = Field(description=f"Whether the data is more than {MARKET_STALE_HOURS} hours old.") 191 period_start: date = Field(description="The first whole day the report covers.") 192 period_end: date = Field(description="The last whole day the report covers: the day before `data_at`.") 193 gathering: list[MarketGatherSection] = Field(description="One section per gathering profession.") 194 crafting: list[MarketCraftSection] = Field(description="One section per crafting profession.") 195 risers: list[MarketMover] = Field(description="Biggest price rises, largest first.") 196 fallers: list[MarketMover] = Field(description="Biggest price drops, largest first.")