Skip to content

Repository files navigation

trademe-autorelister

A Python library and CLI tool to automatically relist unsold items and make offers on TradeMe.

Installation

pip install -r requirements.txt

For development (includes testing tools):

pip install -r requirements-dev.txt

Setup

  1. Copy creds.py.dist to creds.py
  2. Fill in your TradeMe OAuth credentials:
    • client_key: Your TradeMe consumer key
    • client_secret: Your TradeMe consumer secret
    • resource_owner_key: User OAuth token
    • resource_owner_secret: User OAuth token secret

You need to register your application at https://developer.trademe.co.nz to get these credentials.

CLI Usage

The CLI tool (cli.py) provides several commands for managing your TradeMe listings.

Basic Commands

# Show account status
./cli.py status

# List unsold items
./cli.py list

# List items that can be relisted
./cli.py list --filter ItemsICanRelist

Relisting Items

# Preview what would be relisted (dry-run)
./cli.py relist --dry-run

# Relist all eligible items
./cli.py relist

# Relist with verbose output
./cli.py relist --verbose

Making Offers

# Offer items at their start price
./cli.py offer

# Offer items at 10% discount
./cli.py offer --discount 10

# Offer with 3-day duration
./cli.py offer --duration 3

Auto Mode

Automatically decides whether to relist or make an offer based on watchers:

# Auto relist/offer (dry-run)
./cli.py auto --dry-run

# Auto relist/offer with 15% discount for offers
./cli.py auto --discount 15

Options

Option Description
-c, --credentials Path to credentials file (default: creds.py)
-e, --env API environment: sandbox or production (default: sandbox)
-v, --verbose Enable verbose output
-n, --dry-run Preview actions without making changes
-f, --filter Filter for unsold items (All, Last45Days, ItemsICanRelist, ItemsIHaveOffered)

Examples

# Use production API
./cli.py -e production status

# Use custom credentials file
./cli.py -c /path/to/creds.json list

# Relist with verbose output in production
./cli.py -e production -v relist

Library Usage

Classes

TrademeApiConnection

The API connection object. Takes a URL and credentials as parameters:

from trademe import TrademeApiConnection

creds = {
    'client_key': 'your_consumer_key',
    'client_secret': 'your_consumer_secret',
    'resource_owner_key': 'user_oauth_token',
    'resource_owner_secret': 'user_oauth_token_secret'
}

api = TrademeApiConnection('https://api.tmsandbox.co.nz/v1', creds)

TrademeItem

An item abstraction. Attributes are populated from the TradeMe API response. See: https://developer.trademe.co.nz/api-reference/listing-methods/retrieve-the-details-of-a-single-listing/

Methods:

  • quickRelist(): Relists the item if possible and returns a TrademeItem object for the new listing
  • offer(price, offerDuration, quantity=1): Offers an item for the price and duration specified to all watchers/bidders

MyTradeMe

Access to the authenticated user's TradeMe account.

from trademe import MyTradeMe

trademe = MyTradeMe(api)

# Get unsold items
unsold = trademe.unsoldItems('ItemsICanRelist')

# Get currently selling items
selling = trademe.sellingItems()

# Get sold items
sold = trademe.soldItems()

Available filters for unsoldItems():

  • All
  • Last45Days (default)
  • ItemsICanRelist
  • ItemsIHaveOffered

See: https://developer.trademe.co.nz/api-reference/my-trade-me-methods/retrieve-your-unsold-items/

Example Script

#!/usr/bin/env python3
from trademe import TrademeApiConnection, MyTradeMe

# Setup
creds = {...}  # Your credentials
api = TrademeApiConnection('https://api.tmsandbox.co.nz/v1', creds)
trademe = MyTradeMe(api)

# Get items that can be relisted
for item in trademe.unsoldItems('ItemsICanRelist'):
    if item.BidderAndWatchers > 0:
        # Has watchers - make an offer
        result = item.offer(item.StartPrice * 0.9, 1)  # 10% discount, 1 day
        if result:
            print(f"Offered {item.Title} to {result} watchers")
    else:
        # No watchers - just relist
        new_item = item.quickRelist()
        if new_item:
            print(f"Relisted {item.Title} as {new_item.ListingId}")

Running Tests

# Run all tests
python -m pytest -v

# Run with coverage
python -m pytest --cov=trademe --cov=cli -v

# Run specific test file
python -m pytest test_trademe.py -v
python -m pytest test_cli.py -v

API Environments

Environment Base URL
Sandbox https://api.tmsandbox.co.nz/v1
Production https://api.trademe.co.nz/v1

License

MIT

About

Automatically relist and/or offers Trademe auctions from your list

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages