"""Bidding and buying tools for Trade Me MCP server."""
from typing import Any
from ..client import TradeMeClient
async def place_bid(
client: TradeMeClient, listing_id: int, amount: float, **kwargs: Any
) -> dict[str, Any]:
"""
Place a bid on an auction listing.
Submit a bid on an active Trade Me auction. Requires authentication.
Args:
listing_id: The Trade Me listing ID to bid on
amount: The bid amount in NZD
shipping_option: Shipping option ID (optional)
Returns:
Bid confirmation with current auction status
Example:
place_bid(listing_id=4567890123, amount=150.00)
"""
json_data = {
"ListingId": listing_id,
"Amount": amount
}
if "shipping_option" in kwargs:
json_data["ShippingOption"] = kwargs["shipping_option"]
return client.post("/Bidding/Place.json", json_data=json_data, requires_auth=True)
async def buy_now(
client: TradeMeClient, listing_id: int, **kwargs: Any
) -> dict[str, Any]:
"""
Purchase a listing using Buy Now.
Immediately purchase a listing that has Buy Now enabled. Requires authentication.
Args:
listing_id: The Trade Me listing ID to purchase
quantity: Number of items to purchase (default: 1)
shipping_option: Shipping option ID
accept_terms: Accept seller's terms and conditions (true/false)
Returns:
Purchase confirmation with order details
Example:
buy_now(listing_id=4567890123, quantity=1, accept_terms=true)
"""
json_data = {
"ListingId": listing_id,
"Quantity": kwargs.get("quantity", 1)
}
if "shipping_option" in kwargs:
json_data["ShippingOption"] = kwargs["shipping_option"]
if "accept_terms" in kwargs:
json_data["AcceptTerms"] = kwargs["accept_terms"]
return client.post("/Buying/BuyNow.json", json_data=json_data, requires_auth=True)
async def make_offer(
client: TradeMeClient, listing_id: int, price: float, **kwargs: Any
) -> dict[str, Any]:
"""
Make a fixed price offer on a listing.
Submit an offer on listings that accept offers. Requires authentication.
Args:
listing_id: The Trade Me listing ID
price: The offer amount in NZD
message: Optional message to seller
Returns:
Offer confirmation with offer ID and status
Example:
make_offer(listing_id=4567890123, price=500.00, message="Is this negotiable?")
"""
json_data = {
"ListingId": listing_id,
"Price": price
}
if "message" in kwargs:
json_data["Message"] = kwargs["message"]
return client.post(
"/Buying/MakeOffer.json", json_data=json_data, requires_auth=True
)
async def withdraw_offer(
client: TradeMeClient, offer_id: int, **kwargs: Any
) -> dict[str, Any]:
"""
Withdraw a previously made fixed price offer.
Cancel an offer you've made on a listing. Requires authentication.
Args:
offer_id: The offer ID to withdraw
Returns:
Confirmation of withdrawal
Example:
withdraw_offer(offer_id=123456)
"""
return client.post(
f"/Buying/WithdrawOffer/{offer_id}.json", requires_auth=True
)
async def accept_offer(
client: TradeMeClient, offer_id: int, **kwargs: Any
) -> dict[str, Any]:
"""
Accept an offer made on your listing (seller action).
Accept a buyer's offer on one of your listings. Requires authentication.
Args:
offer_id: The offer ID to accept
Returns:
Confirmation of acceptance
Example:
accept_offer(offer_id=123456)
"""
return client.post(
f"/Selling/AcceptOffer/{offer_id}.json", requires_auth=True
)
async def decline_offer(
client: TradeMeClient, offer_id: int, **kwargs: Any
) -> dict[str, Any]:
"""
Decline an offer made on your listing (seller action).
Decline a buyer's offer on one of your listings. Requires authentication.
Args:
offer_id: The offer ID to decline
Returns:
Confirmation of decline
Example:
decline_offer(offer_id=123456)
"""
return client.post(
f"/Selling/DeclineOffer/{offer_id}.json", requires_auth=True
)
async def get_purchase_history(
client: TradeMeClient, **kwargs: Any
) -> dict[str, Any]:
"""
Get the authenticated user's purchase history.
Retrieve all items you've purchased on Trade Me. Requires authentication.
Args:
page: Page number for pagination
rows: Number of results per page (max 500)
filter: Filter by status (All, EmailSent, PaymentReceived, GoodsShipped)
Returns:
List of purchased items with details
Example:
get_purchase_history(page=1, rows=50, filter="All")
"""
params = {}
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "filter" in kwargs:
params["filter"] = kwargs["filter"]
return client.get(
"/MyTradeMe/PurchaseHistory.json", params=params, requires_auth=True
)
async def get_won_items(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Get auctions the authenticated user has won.
Retrieve all auctions you've successfully won. Requires authentication.
Args:
page: Page number for pagination
rows: Number of results per page (max 500)
Returns:
List of won auctions
Example:
get_won_items(page=1, rows=25)
"""
params = {}
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
return client.get(
"/MyTradeMe/Won.json", params=params, requires_auth=True
)
async def get_lost_items(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Get auctions the authenticated user bid on but lost.
Retrieve all auctions you bid on but didn't win. Requires authentication.
Args:
page: Page number for pagination
rows: Number of results per page (max 500)
Returns:
List of lost auctions
Example:
get_lost_items(page=1, rows=25)
"""
params = {}
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
return client.get(
"/MyTradeMe/Lost.json", params=params, requires_auth=True
)
async def get_bidding_on(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Get items the authenticated user is currently bidding on.
Retrieve all active auctions you have bids on. Requires authentication.
Args:
page: Page number for pagination
rows: Number of results per page (max 500)
Returns:
List of active bids with current status
Example:
get_bidding_on(page=1, rows=25)
"""
params = {}
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
return client.get(
"/MyTradeMe/Buying.json", params=params, requires_auth=True
)