Friday 3 February 2012

Time to flex my (intellectual) muscles

Working, as I do, in the retail motor industry means that a lot of potentially very profitable trades are unavailable to me due to the fact that I am unavailable on Saturday afternoons. Frustrating as this is there is no way round it unless a way can be found to automate the process.

I distinctly remember as a spotty teenager playing around with programming a Sinclair Spectrum SX in a language called 'BASIC'. I managed to draw something that sort of resembled a tank and was able to animate this thing across the screen of the television the computer was hooked up to. It introduced me to some basic (no pun intended) programming principles such as loops and if.... then... else constructs. Why I didn't pursue a career down this road I've no idea; obviously I saw no future in it :-(

Over the years I've dabbled with programming as a hobbyist and I think it is now time to see if I can get my two main pastimes working in tandem with each other. My favoured trade, as regular readers will know, is the so called 'Scatter Gun' trade which can be worked very mechanically ... i.e. if this condition exists then do this or else do that. I'm sure this can be worked into a programme, or 'bot' to take care of things whilst I'm off enjoying selling cars.

Although I'm self taught with the help of various books and the internet I'll state up front that most of the specialised code needed to access Betfair programmatically has been learnt by studying a very useful thread by a chap named Mumbles on the Betfair developer's forum, so credit for any success where it's due. I'll take the blame for any failure right on the chin!

I'm sure a professional developer would start armed with a piece of paper or two and sketch out the main structure of his bot before firing up the relevant software. I'm not a pro, and planning on paper is not one of my strong suites so it's straight in at the deep end with Visual Basic .net 10 for me!

Fairly obviously this isn't set to win any 'User Interface' awards, and this is the unstarted finished product! So there's a few hoops to jump through along the way.

There are a few issues that I've yet to confront properly (and probably loads of 'Gotchas' round every corner) - for example how to keep track of the current score. I know from bitter experience that Flashscores and the like cannot be 100% trusted so it seems to me at the moment that the only sure fire way of establishing the current score is to loop through all possible Correct Scores looking for odds of 1000 to back.

As I start getting this mock up wired for action it might be that I appeal to cleverer readers than I to assist with the gotchas. Hopefully someone will come to my aid. I expect progress on this to be slow, as my patience when things like this aren't doing what I would like them to is akin to that of a toddler playing with Lego. So, please bear with me!

7 comments:

  1. Hey Dave,
    I can't help you with the programming despite being the owner of a ZX81 sometime during the 80's:-) But what I will say is that if it gets off the ground and you're flogging it you can put me down for one.

    Now I've got the nags sorted I've started to focus more on football and your Scatter Gun is the trade which I come back to again and again.

    I reckon Eddie at Trader's Path has some bots maybe he will be able to help.

    Will be interested to see how this pans out.

    ReplyDelete
  2. Only advice I would give is to make the application keep a complete log of everything it does. You cannot possibly plan for every outcome with the API so having a log of each action your program has made (and the reason for that action if applicable) will be a godsend. Imagine leaving your app running only to come back and find it has crashed - why? without a log you cannot even begin to work out what happened and then you cannot be confident in letting it run unattended again which defies the whole point of the Bot! Trust me, keeping a full log of actions is a must!

    ReplyDelete
  3. Thanks for the vote of confidence, Pete, but it's not my intention to sell it - to be honest it's a bit of a 'prove I can do it' exercise as much as anything.

    F1 - thanks for the suggestion. I was going to build in a simple routine to record all trades to a log file, but I think your advice is aimed at something a little more complex than that?

    ReplyDelete
  4. Good luck with this, Dave! Give me a shout when you get stuck - happy to help out with anything.

    Best way to start is to map out the process, rules and trigger conditions on paper (simple flowchart) - you'll find it will save a load of time re-writing stuff.

    Make it an MDI app (multiple document interface = you can have several windows open and therefore matches trading, as long as you stay within the BF throttling rules).

    Cheers, mate

    Ken

    ReplyDelete
  5. Appreciate that, Ken. I'll try to build it so that the main action takes place in class modules - so that if / when I get it working I can expand it along the MDI approach you suggest.

    I think asynchronous calls to the API will be a bit easier for a person at my level rather than a fully fledged threaded programme - would be interested in your take on that.

    Cheers,

    Dave

    ReplyDelete
  6. Gun,

    programming is my day do day work.
    I've been studying how the BetFair API works.

    In case you need any help, just let me now...
    btw, i think i'm going to make myself a SG Bot too... that was an excellent idea ;)

    Keep it green,
    fraz from TF

    ReplyDelete
  7. Fraz - you and Boro! What a gifted community we have at TF! Will almost certainly take you both up on your offers but will try to muddle through on my own first.

    ReplyDelete