Thread Tools Display Modes
10-01-20, 03:39 PM   #1
Opertune
A Murloc Raider
Join Date: Sep 2020
Posts: 4
Auction house : get specific item price

Hello everyone, i'm new developer and i would like to create an addon who show specific item price when i click on a button (item set in code and no with in game auction house research).

Currently i can create frame and button when i open auction house but i don't know how work auction house api (C_AuctionHouse.GetReplicateItemInfo or C_AuctionHouse.GetCommoditySearchResultInfo).

I try with Xrystal code : https://www.wowinterface.com/forums/...ad.php?t=57985 but nothing really gets done.

My currently code :

Code:
local UIConfig = CreateFrame("Frame", "OpertuneAH", UIParent, "BasicFrameTemplateWithInset");

UIConfig:RegisterEvent("AUCTION_HOUSE_SHOW") -- Event when auction house is opened
UIConfig:RegisterEvent("AUCTION_HOUSE_CLOSED") -- Event when auction house is closed

UIConfig:SetSize(600, 535) -- Window size
UIConfig:SetScript("OnEvent",
	function(self,event,...)
		if event == "AUCTION_HOUSE_SHOW" then -- If auction house is opened we create frame
			-- Frame Settings
			UIConfig:SetPoint("CENTER", UIParent, "CENTER", 200, 155) -- Position
			UIConfig:SetMovable(true) -- Drag and drop option's
			UIConfig:EnableMouse(true) -- Drag and drop option's
			UIConfig:RegisterForDrag("LeftButton") -- Drag and drop option's
			UIConfig:SetScript("OnDragStart", UIConfig.StartMoving) -- Drag and drop option's
			UIConfig:SetScript("OnDragStop", UIConfig.StopMovingOrSizing) -- Drag and drop option's
			-- Show Frame
			UIConfig:Show()
		end
		if event == "AUCTION_HOUSE_CLOSED" then -- If auction house is closed we close the frame
			UIConfig:Hide() -- Hide Frame
			UIConfig.text:SetText("") -- Reset text area
		end 
	end)


-- Child frames and regions
-- Frame title
UIConfig.title = UIConfig:CreateFontString(nil, "OVERLAY")
UIConfig.title:SetFontObject("GameFontHighlight")
UIConfig.title:SetPoint("LEFT", UIConfig.TitleBg, "LEFT", 5, 0)
UIConfig.title:SetText("OpertuneAH")

-- Scan button
UIConfig.scanButton = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate")
UIConfig.scanButton:SetPoint("TOPLEFT", UIConfig, "TOPLEFT", 10, -28)
UIConfig.scanButton:SetSize(90, 25)
UIConfig.scanButton:SetText("Scan")
UIConfig.scanButton:SetNormalFontObject("GameFontNormalLarge") -- Text Color
UIConfig.scanButton:SetHighlightFontObject("GameFontHighlightLarge") -- Text Color

-- Event click button scan
UIConfig.scanButton:SetScript("OnClick",function(self,event,...)
	UIConfig.text:SetText("Hello World")
end)

-- Label text
UIConfig.text = UIConfig:CreateFontString(nil, "TEST")
UIConfig.text:SetFontObject("GameFontNormalLarge")
UIConfig.text:SetPoint("CENTER", UIConfig, "CENTER", 0, 0)
  Reply With Quote
10-02-20, 01:35 PM   #2
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
I don't know why my posts keep getting ignored.

Did you try to work with the example I posted in that thread and https://wow.gamepedia.com/API_C_Auct...ReplicateItems
  Reply With Quote
10-03-20, 07:37 PM   #3
Opertune
A Murloc Raider
Join Date: Sep 2020
Posts: 4
Ohhhh my bad, i see your post but i missed
ItemMixin:ContinueOnItemLoad()
and ItemMaxin api.
I try with that but i'm on the right way. Thank you for your answer.
  Reply With Quote
10-09-20, 06:32 PM   #4
Opertune
A Murloc Raider
Join Date: Sep 2020
Posts: 4
Okay, i have an another problem, i can print information's from my specific item but when i want to print minimum buyout price (after gold conversion and after retrieve the minimum value in my table) my function return a random value.

Auction house price :
https://imgur.com/hoWL390

When i print all price and min price :
https://imgur.com/Sqb9AP8

On the screen he return the second price but with other item he return other price.
After many research i've tried differents ways but i have always the same result.

My functions :

Code:
local auctions = {}
local allPrice = {}
local initialQuery
local silverPrice, goldPrice, min

UIConfig.scanButton:SetScript("OnClick",function(self, button, down)
    if initialQuery then
        ScanAuctions()     
        initialQuery = false
    end
end)


function ScanAuctions()
    local continuables = {}

    for i = 0, C_AuctionHouse.GetNumReplicateItems() - 1 do
        auctions[i] = {C_AuctionHouse.GetReplicateItemInfo(i)}
        local item = Item:CreateFromItemID(auctions[i][17])
        continuables[item] = true

        item:ContinueOnItemLoad(function()
            auctions[i] = {C_AuctionHouse.GetReplicateItemInfo(i)}
            continuables[item] = nil
        end)
    end

    getLowestPrice()
end

function getLowestPrice()
    for i, _ in pairs(auctions) do
        if auctions[i][17] == 152510 then -- Anchor Weed id
            silverPrice = (auctions[i][10] / auctions[i][3]) -- copper price / count
            goldPrice = (silverPrice / 10000) 
            allPrice = {goldPrice}

            min = allPrice[1]
            for j = 1, #allPrice do
                print(allPrice[j]) -- print all price
                if allPrice[j] < min then
                    min = allPrice[j]
                end
            end
        end
    end

    print("Min Price : " .. min) -- print min price
end
  Reply With Quote
10-09-20, 11:48 PM   #5
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Opertune View Post
but when i want to print minimum buyout price (after gold conversion and after retrieve the minimum value in my table) my function return a random value.

I'm guessing it's because you're not waiting for all auction items to get cached, and skip ahead to checking the auctions

Here's another example which prints the lowest price for an item ID right after it's done scanning or when you press the button or run a script
Lua Code:
  1. local initialQuery
  2. local auctions = {}
  3. local f = CreateFrame("Frame", "SomeAddon")
  4.  
  5. -- you can also press the button or use this script when scanning is done
  6. -- /run print(GetMoneyString(SomeAddon:GetLowestPrice(152510)))
  7. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  8. btn:SetPoint("CENTER")
  9. btn:SetSize(120, 40)
  10. btn:SetText("Example")
  11. btn:SetScript("OnClick", function(self, button)
  12.     if next(auctions) then
  13.         f:SomeExample()
  14.     else
  15.         print("No data")
  16.     end
  17. end)
  18.  
  19. function f:SomeExample()
  20.     local price = self:GetLowestPrice(152510)
  21.     print("Min Price:", GetMoneyString(price))
  22. end
  23.  
  24. function f:GetLowestPrice(itemID)
  25.     local minPrice = math.huge
  26.     for _, v in pairs(auctions) do
  27.         if v[17] == itemID then
  28.             local unitPrice = v[10] / v[3] -- totalPrice / count
  29.             --print(unitPrice)
  30.             minPrice = min(minPrice, unitPrice)
  31.         end
  32.     end
  33.     if minPrice < math.huge then
  34.         return minPrice
  35.     end
  36. end
  37.  
  38. function f:ScanAuctions(callback)
  39.     local continuables = {}
  40.     wipe(auctions)
  41.     for i = 0, C_AuctionHouse.GetNumReplicateItems()-1 do
  42.         auctions[i] = {C_AuctionHouse.GetReplicateItemInfo(i)}
  43.         local item = Item:CreateFromItemID(auctions[i][17]) -- itemID
  44.         continuables[item] = true
  45.  
  46.         item:ContinueOnItemLoad(function()
  47.             auctions[i] = {C_AuctionHouse.GetReplicateItemInfo(i)}
  48.             continuables[item] = nil
  49.             if not next(continuables) then
  50.                 print("I'm done scanning")
  51.                 callback()
  52.             end
  53.         end)
  54.     end
  55. end
  56.  
  57. function f:OnEvent(event)
  58.     if event == "AUCTION_HOUSE_SHOW" then
  59.         C_AuctionHouse.ReplicateItems()
  60.         initialQuery = true
  61.     elseif event == "REPLICATE_ITEM_LIST_UPDATE" then
  62.         if initialQuery then
  63.             self:ScanAuctions(function() self:SomeExample() end)
  64.             initialQuery = false
  65.         end
  66.     end
  67. end
  68.  
  69. f:RegisterEvent("AUCTION_HOUSE_SHOW")
  70. f:RegisterEvent("REPLICATE_ITEM_LIST_UPDATE")
  71. f:SetScript("OnEvent", f.OnEvent)

Last edited by Ketho : 12-19-20 at 02:48 PM.
  Reply With Quote
10-10-20, 03:43 PM   #6
Opertune
A Murloc Raider
Join Date: Sep 2020
Posts: 4
Thanks for your help Ketho, i reused a part of your code and now my addon works great. I think i need more practice with lua and wow api but it's pretty cool to create a wow addon.
  Reply With Quote
12-18-20, 04:40 PM   #7
deres
A Defias Bandit
Join Date: Dec 2020
Posts: 3
awesome code!

Is there any other way besides using C_AuctionHouse.ReplicateItems? The 15 min throttle seems too long for me as prices change quite quickly and the cached value becomes out of date pretty fast.

Or did you manage to use some other API?
  Reply With Quote
12-19-20, 05:13 PM   #8
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by deres View Post
Is there any other way besides using C_AuctionHouse.ReplicateItems?

I added an example to C_AuctionHouse.SendSearchQuery()
  Reply With Quote
12-19-20, 06:17 PM   #9
deres
A Defias Bandit
Join Date: Dec 2020
Posts: 3
Awesome, this one looks even better as I'd only need to query max 20 items. Thanks for this one!

The REPLICATE_ITEM_LIST_UPDATE event however acts weirdly for me. sometimes the 15 min throttle is accurate, sometime it just doesn't happen. I even waited several hours (tried reopening the AH) but nothing happened.

Shouldn't it trigger automatically after this 15 min throttle expires?

Thanks!
  Reply With Quote
12-19-20, 06:42 PM   #10
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by deres View Post
Shouldn't it trigger automatically after this 15 min throttle expires?

You mean that the event should fire automatically after the 15 minutes cooldown expires?
No, it only fires once you call C_AuctionHouse.ReplicateItems() and while it's not throttled
  Reply With Quote
12-20-20, 05:09 AM   #11
deres
A Defias Bandit
Join Date: Dec 2020
Posts: 3
The C_AuctionHouse.ReplicateItems() is called on the AUCTION_HOUSE_SHOW event like in your code. It worked 2 times in a row, now it seems to be bricked. Interesting. Tried attaching it to a button click, 35 minutes passed but nothing.

I might be throttled for more than 15 min I guess. Anyways the C_AuctionHouse.SendSearchQuery() works perfectly and suits my needs as I don't really need to scan the whole AH!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Auction house : get specific item price

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off