In this session we shall see how we can make a bet using the API

The subroutine we need to add to the MyAPILib fle has the following heading

def doWager(marketId, horseId, backOrLay, stake, price, persistence, appKey, sessionToken):
## returns betResult access status of bet through betResult[‘status’]

From this we can see that when we make a call to this subroutine to make a wager we need to pass it 8 parameters. Some need a little explanation.

The BackOrLay parameter needs to be the word BACK or LAY depending on whether we intend to back or lay the horse.

persistence will indicate what we want to happen to the bet should it not be matched and the market go’s in play. In the sample code we shall see shortly we will specify LAPSE. Using the old API we simply specify SP if we want the bet to go SP in running. Betfair in their wisdom have decided that to specify SP using NG you need to state MARKET_ON_CLOSE

The other parameters are self explanatory and in our sample call we will get our code to LAY the last horse in the last race its detects when outputing the race and horse Id’s. We shall lay it for £2 at 1.01 thus giving us ample time to manually cancel it off.

The doWager code can be copied and pasted into your MyAPILib file from the following link doWager

The call to doWager and the examination of the return code can be copied and pasted from testlib

One other useful parameter which I have not used in the above, is a customer reference which you can allocate to a bet. This can be useful when later on you need to identify bets perhaps by the different bots you have or by strategy name. The amendment to the call in doWager is shown below. Of course an extra string parameter needs to be passed into the subroutine as well

NOTE- Do not copy and paste the following I have not edited to undo wordpress mangling of quote marks

bet_place_req = ‘{“jsonrpc”: “2.0”, “method”: “SportsAPING/v1.0/placeOrders”, “params”: {“marketId”: “‘ +marketId+ ‘”,”instructions”: [{“selectionId”: “‘ +horseId+ ‘”, “handicap”: “0”, “side”: “‘ +backOrLay+ ‘”, “orderType”: “LIMIT”, “limitOrder”: { “size”: “‘ +stake+ ‘”, “price”: “‘ +price+ ‘”, “persistenceType”: “‘ +persistence+ ‘” } } ], “customerRef”:”‘ +cRef+ ‘”}, “id”: 1 }’

The subroutine header would like the following

def doWager(marketId, horseId, backOrLay, stake, price, persistence, cRef, appKey, sessionToken):

Advertisements