1"""Auction house prices: public prices, member price-watch alerts, and the bot's sync/alert feed.
2
3``local://auctions-contract.md`` is the source of truth. Battle.net serves fifteen auction houses per ruleset (five
4each for Alliance, Horde and Blackwater); SideQuest prices items from every house of its own faction. Money is
5copper (an ``int``); the website and bot each format it as ``1g 20s 5c``.
6"""
7
8from datetime import date, datetime # pydantic needs them at runtime
9from uuid import UUID # pydantic needs it at runtime
10
11from pydantic import BaseModel, Field
12
13AUCTION_TREND_DAYS = 14
14AUCTION_HISTORY_DAYS = 90
15MAX_AUCTION_WATCHES = 25
16MAX_PRICE_IDS = 200
17IMPORT_PRICES_LIMIT = 500
18AUCTION_ALERT_COOLDOWN_HOURS = 24
19
20
[docs]
21class AuctionHousePrice(BaseModel):
22 """One auction house's current price for an item."""
23
24 house_id: int = Field(description="The auction house's Battle.net ID.")
25 house_name: str = Field(description="The house's name, such as `Alliance Auction House`.")
26 unit_price: int = Field(description="The lowest unit price listed at this house, in copper.")
27 quantity: int = Field(description="Total quantity of priced listings at this house.")
28 listings: int = Field(description="How many listings this house's price was built from.")
29 updated_at: datetime = Field(description="When this house's price was last synced.")
30
31
[docs]
32class AuctionTrendPoint(BaseModel):
33 """One day's lowest unit price in an item's price trend."""
34
35 day: date
36 unit_price: int = Field(description="The lowest unit price seen that day across the guild's faction houses.")
37
38
[docs]
39class ItemAuctionPrice(BaseModel):
40 """``GET /api/auctions/prices/{item_id}``: one item's current price across every house of the guild's faction."""
41
42 item_id: int = Field(description="The item's game ID.")
43 unit_price: int | None = Field(
44 description="The lowest unit price across every house, in copper. Null if nobody lists it."
45 )
46 quantity_total: int = Field(description="Total priced quantity across every house.")
47 houses: list[AuctionHousePrice] = Field(description="Every house currently pricing this item.")
48 trend: list[AuctionTrendPoint] = Field(description=f"The last {AUCTION_TREND_DAYS} days of daily low prices.")
49 updated_at: datetime | None = Field(description="When the price was last synced. Null if nobody lists it.")
50
51
[docs]
52class ItemPriceSummary(BaseModel):
53 """One item's price in a batch price lookup, without its per-house breakdown or trend."""
54
55 item_id: int = Field(description="The item's game ID.")
56 unit_price: int | None = Field(description="The lowest unit price across every house. Null if nobody lists it.")
57 quantity_total: int = Field(description="Total priced quantity across every house.")
58 updated_at: datetime | None = Field(description="When the price was last synced. Null if nobody lists it.")
59
60
[docs]
61class AuctionPriceMap(BaseModel):
62 """``GET /api/auctions/prices?ids=...``: one entry per requested item ID, in request order."""
63
64 prices: list[ItemPriceSummary]
65
66
[docs]
67class AuctionSyncHouse(BaseModel):
68 """One house's counts from an auction sync."""
69
70 house_id: int = Field(description="The auction house's Battle.net ID.")
71 house_name: str = Field(description="The house's name, such as `Alliance Auction House`.")
72 auctions: int = Field(description="Non-stackable auctions fetched from this house.")
73 commodities: int = Field(description="Stackable commodity listings fetched from this house.")
74
75
[docs]
76class AuctionSyncReport(BaseModel):
77 """``POST /api/guilds/{guild_id}/auctions/sync``: what the sync fetched, priced and queued."""
78
79 houses: list[AuctionSyncHouse]
80 items_priced: int = Field(description="Distinct items priced by this sync.")
81 alerts_queued: int = Field(description="Price-watch alerts queued by this sync.")
82
83
[docs]
84class AuctionWatch(BaseModel):
85 """One of a member's auction price watches."""
86
87 id: UUID
88 item_id: int = Field(description="The item's game ID.")
89 item_name: str | None = Field(description="The item's name, if Battle.net knows it.")
90 icon_url: str | None = Field(description="The item's icon, if Battle.net has one.")
91 max_unit_price: int = Field(description="Alert when the item's lowest unit price is at or below this, in copper.")
92 current_unit_price: int | None = Field(description="The item's current lowest unit price. Null if unpriced.")
93 created_at: datetime
94 last_alerted_at: datetime | None = Field(description="When this watch last queued an alert, if ever.")
95
96
[docs]
97class AuctionWatchCreate(BaseModel):
98 """Body for ``POST /api/me/auction-watches`` (and the bot's member variant): upserts by ``item_id``."""
99
100 item_id: int = Field(gt=0, description="The item's game ID.")
101 max_unit_price: int = Field(
102 ge=1, le=10_000_000_000, description="Alert when the item's lowest unit price is at or below this, in copper."
103 )
104
105
[docs]
106class AuctionAlertSchema(BaseModel):
107 """One queued price alert, as the bot's pending-alerts feed returns it."""
108
109 id: UUID
110 discord_user_id: int = Field(description="The watching member's Discord user ID, to DM.")
111 member_name: str = Field(description="The watching member's display name at the time of the alert.")
112 item_id: int = Field(description="The item's game ID.")
113 item_name: str | None = Field(description="The item's name, if Battle.net knows it.")
114 icon_url: str | None = Field(description="The item's icon, if Battle.net has one.")
115 unit_price: int = Field(description="The price that triggered the alert, in copper.")
116 max_unit_price: int = Field(description="The watch's threshold at the time of the alert, in copper.")
117 quantity: int = Field(description="Total priced quantity at that price, across houses.")
118 house_name: str = Field(description="The cheapest house's name.")
119 created_at: datetime