A Python library and CLI tool to automatically relist unsold items and make offers on TradeMe.
pip install -r requirements.txtFor development (includes testing tools):
pip install -r requirements-dev.txt- Copy
creds.py.disttocreds.py - Fill in your TradeMe OAuth credentials:
client_key: Your TradeMe consumer keyclient_secret: Your TradeMe consumer secretresource_owner_key: User OAuth tokenresource_owner_secret: User OAuth token secret
You need to register your application at https://developer.trademe.co.nz to get these credentials.
The CLI tool (cli.py) provides several commands for managing your TradeMe listings.
# Show account status
./cli.py status
# List unsold items
./cli.py list
# List items that can be relisted
./cli.py list --filter ItemsICanRelist# 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# 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 3Automatically 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| 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) |
# 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 relistThe 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)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 listingoffer(price, offerDuration, quantity=1): Offers an item for the price and duration specified to all watchers/bidders
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():
AllLast45Days(default)ItemsICanRelistItemsIHaveOffered
See: https://developer.trademe.co.nz/api-reference/my-trade-me-methods/retrieve-your-unsold-items/
#!/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}")# 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| Environment | Base URL |
|---|---|
| Sandbox | https://api.tmsandbox.co.nz/v1 |
| Production | https://api.trademe.co.nz/v1 |
MIT