EDIT: Some of the information here is now out of date. See here for the changes.
Recently TradeMe released their API. This is pretty great, if only because it means I can finally give up maintaining the increasingly-complicated set of scraper scripts that I’d used to do TradeMe stuff up to this point. After converting the basics of metatrade.co.nz over to the API, I was looking for a new TM-related project, and I happened to stumble across this old comic from XKCD:
Google didn’t reveal anyone doing this already, and after asking a few people, the general opinion was that doing this was a terrible idea that would inevitably end badly. So obviously I had to do it.
I initially ran into a couple small problems with the API, but as of this afternoon, the system is working! It’s on Twitter at @trademe_xkcd576, so everyone can see what it does. The first thing it automatically bought:
I’ve had a bunch of people ask me how the script works. So here’s some info about the inner workings:
- It’s using Python and python-oauth2. For anyone looking to do TM stuff with python, the code examples on that page basically just worked.
- It runs every day at 8pm (although it was earlier today because I was testing it)
- It gains $1 every day, and has a 1 in 3 chance of buying an item on any particular day. This means that it will save up money to buy some (slightly) more expensive items.
The method it uses to select items:
- It has a bunch of top-level categories it looks in.
- For each of these categories, it searches for the term “Free shipping”, specifying both pay-now and buy-now, sorting by newest listings, with a maximum of 100 items returned per category.
- For each of these items, it filters on buy-now price. It tries to spend at least 50% of its savings.
- For each of the surviving items, it looks up the individual auction details to find its shipping information so it can filter on free shipping. Despite searching for the term ‘free shipping’ to start, only a small number of items have this.
- At this point I have a list of items that match the price requirements, and can be bought with a credit card buy-now.
- I then sort this list by ‘rarity’ – doing a search for the item title, and finding the item that returns the least results. As the objective here is to buy strange and esoteric things, rarity is preferred.
- Finally I buy the rarest item and subtract its cost from the bots savings.
There’s a bunch of improvements that could be made here, but I figure it’s good enough for the moment. I’ll keep an eye on it and see what happens.
Hopefully in a week or so I can post a “here is my collection of random stuff that’s turned up in the post” photo