Grand Exchange Offer Type
GrandExchangeOffer
A GrandExchangeOffer represents a buy or sell offer in the Grand Exchange.
Methods
index
offer:index() -> number
Returns the slot index (0-7) of this offer in the Grand Exchange.
Returns:
number: The slot index
Example:
local offers = grand_exchange:all_offers()
for _, offer in ipairs(offers) do
logger:info("Slot " .. offer:index() .. ": " .. offer:name())
end
item_id
offer:item_id() -> number
Returns the item ID for this offer.
Returns:
number: The item ID
Example:
local offer = grand_exchange:get_offer(0)
if offer and offer:valid() then
logger:info("Item ID: " .. offer:item_id())
end
name
offer:name() -> string
Returns the item name for this offer.
Returns:
string: The item name
Example:
local offers = grand_exchange:all_offers()
for _, offer in ipairs(offers) do
if offer:is_in_progress() then
logger:info("Trading: " .. offer:name())
end
end
unit_price
offer:unit_price() -> number
Returns the price per item.
Returns:
number: The price per unit
Example:
local offer = grand_exchange:get_offer(0)
if offer and offer:valid() then
logger:info("Price per item: " .. offer:unit_price() .. " gp")
end
total_quantity
offer:total_quantity() -> number
Returns the total quantity to buy/sell.
Returns:
number: The total quantity
Example:
local offer = grand_exchange:get_offer(0)
if offer and offer:valid() then
logger:info("Total quantity: " .. offer:total_quantity())
end
current_quantity
offer:current_quantity() -> number
Returns the current quantity bought/sold so far.
Returns:
number: The current quantity traded
Example:
local offer = grand_exchange:get_offer(0)
if offer and offer:is_in_progress() then
local current = offer:current_quantity()
local total = offer:total_quantity()
local percent = (current / total) * 100
logger:info("Progress: " .. current .. "/" .. total .. " (" .. percent .. "%)")
end
is_sell
offer:is_sell() -> boolean
Checks if this is a sell offer (false means it's a buy offer).
Returns:
boolean: True if selling, false if buying
Example:
local offer = grand_exchange:get_offer(0)
if offer and offer:valid() then
if offer:is_sell() then
logger:info("Selling " .. offer:name())
else
logger:info("Buying " .. offer:name())
end
end
valid
offer:valid() -> boolean
Checks if this offer is valid.
Returns:
boolean: True if valid
is_available
offer:is_available() -> boolean
Checks if this slot is available (empty).
Returns:
boolean: True if the slot is empty
Example:
-- Find first empty slot
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer and offer:is_available() then
logger:info("Empty slot found: " .. i)
break
end
end
is_aborted
offer:is_aborted() -> boolean
Checks if this offer was aborted/cancelled.
Returns:
boolean: True if aborted
Example:
local offers = grand_exchange:all_offers()
for _, offer in ipairs(offers) do
if offer:is_aborted() then
logger:info("Aborted offer in slot " .. offer:index())
end
end
is_complete
offer:is_complete() -> boolean
Checks if this offer is complete (fully bought/sold).
Returns:
boolean: True if complete
Example:
local offers = grand_exchange:all_offers()
for _, offer in ipairs(offers) do
if offer:is_complete() then
logger:info("Completed: " .. offer:name())
-- Collect the offer
grand_exchange.collect(offer:index())
end
end
is_in_progress
offer:is_in_progress() -> boolean
Checks if this offer is currently in progress.
Returns:
boolean: True if in progress
Example:
local offers = grand_exchange:all_offers()
local active_count = 0
for _, offer in ipairs(offers) do
if offer:is_in_progress() then
active_count = active_count + 1
end
end
logger:info("Active offers: " .. active_count)
state
offer:state() -> string
Returns the offer state as a string.
Returns:
string: One of:"empty"- Slot is empty"aborted_buy"- Buy offer was cancelled"aborted_sell"- Sell offer was cancelled"buying"- Buy offer in progress"selling"- Sell offer in progress"bought"- Buy offer completed"sold"- Sell offer completed
Example:
local offer = grand_exchange:get_offer(0)
if offer and offer:valid() then
logger:info("Offer state: " .. offer:state())
end
Common Patterns
Monitoring Offer Progress
local function monitor_offer(slot_index)
local offer = grand_exchange:get_offer(slot_index)
if not offer or not offer:valid() then
logger:warn("Invalid offer in slot " .. slot_index)
return
end
if offer:is_available() then
logger:info("Slot " .. slot_index .. " is empty")
return
end
local action = offer:is_sell() and "Selling" or "Buying"
local current = offer:current_quantity()
local total = offer:total_quantity()
local percent = math.floor((current / total) * 100)
logger:info(action .. " " .. offer:name() .. ": " .. current .. "/" .. total .. " (" .. percent .. "%)")
if offer:is_complete() then
logger:info("Offer complete!")
elseif offer:is_aborted() then
logger:warn("Offer was cancelled")
end
end
monitor_offer(0)
Auto-Collect Completed Offers
local function collect_completed_offers()
local collected = 0
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer and offer:valid() and offer:is_complete() then
logger:info("Collecting completed offer: " .. offer:name())
grand_exchange.collect(i)
collected = collected + 1
sleep(600)
end
end
return collected
end
local count = collect_completed_offers()
logger:info("Collected " .. count .. " offers")
Wait for Offer Completion
local function wait_for_offer(slot_index, timeout)
local start = os.time()
while os.time() - start < timeout do
local offer = grand_exchange:get_offer(slot_index)
if not offer or not offer:valid() then
logger:warn("Offer became invalid")
return false
end
if offer:is_complete() then
logger:info("Offer completed!")
return true
end
if offer:is_aborted() then
logger:warn("Offer was cancelled")
return false
end
-- Log progress every 10 seconds
if (os.time() - start) % 10 == 0 then
local current = offer:current_quantity()
local total = offer:total_quantity()
logger:info("Progress: " .. current .. "/" .. total)
end
sleep(1000)
end
logger:warn("Offer timed out")
return false
end
wait_for_offer(0, 300) -- Wait up to 5 minutes
Finding Available Slot
local function find_empty_slot()
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer and offer:is_available() then
return i
end
end
return nil
end
local slot = find_empty_slot()
if slot then
logger:info("Empty slot: " .. slot)
-- Create new offer in this slot
else
logger:warn("No empty slots available")
end
Offer Summary Display
local function display_all_offers()
logger:info("===== Grand Exchange =====")
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer and offer:valid() then
if offer:is_available() then
logger:info("Slot " .. i .. ": [Empty]")
else
local action = offer:is_sell() and "SELL" or "BUY"
local state = offer:state()
local progress = offer:current_quantity() .. "/" .. offer:total_quantity()
logger:info("Slot " .. i .. ": " .. action .. " " .. offer:name() .. " - " .. state .. " (" .. progress .. ")")
end
end
end
logger:info("==========================")
end
display_all_offers()
Cancel Slow Offers
local function cancel_slow_offers(min_progress_percent)
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer and offer:valid() and offer:is_in_progress() then
local current = offer:current_quantity()
local total = offer:total_quantity()
local percent = (current / total) * 100
if percent < min_progress_percent then
logger:info("Cancelling slow offer: " .. offer:name() .. " (" .. percent .. "%)")
grand_exchange.abort(i)
sleep(600)
end
end
end
end
-- Cancel offers with less than 10% progress
cancel_slow_offers(10)
Calculate Total Value
local function calculate_offer_value(offer)
if not offer or not offer:valid() or offer:is_available() then
return 0
end
local quantity = offer:current_quantity()
local price = offer:unit_price()
return quantity * price
end
local function total_ge_value()
local total = 0
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer then
total = total + calculate_offer_value(offer)
end
end
return total
end
local value = total_ge_value()
logger:info("Total value in GE: " .. value .. " gp")
Smart Offer Management
local function manage_offers()
-- Collect completed offers
for i = 0, 7 do
local offer = grand_exchange:get_offer(i)
if offer and offer:valid() then
if offer:is_complete() then
logger:info("Collecting: " .. offer:name())
grand_exchange.collect(i)
sleep(600)
elseif offer:is_aborted() then
logger:info("Collecting aborted: " .. offer:name())
grand_exchange.collect(i)
sleep(600)
end
end
end
end
while script_running() do
manage_offers()
sleep(5000) -- Check every 5 seconds
end
Accessing Grand Exchange Offers
Offers are accessed through the grand_exchange API module:
-- Get offer by slot index
local offer = grand_exchange:get_offer(0)
-- Get all offers
local all_offers = grand_exchange:all_offers()
-- Create a buy offer
grand_exchange.buy(item_id, quantity, price)
-- Create a sell offer
grand_exchange.sell(item_id, quantity, price)
-- Collect offer
grand_exchange.collect(slot_index)
-- Abort offer
grand_exchange.abort(slot_index)
See Also
- Grand Exchange API documentation
- Item - Item information