Python place bets using for loop with size and selection ID in pandas dataframe.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sandy
    Junior Member
    • Mar 2019
    • 26

    #1

    Python place bets using for loop with size and selection ID in pandas dataframe.

    Hello,

    I have started looking at the API. I am looking at the UK to win horse racing market. I have created a method, got my live API and able to place individual bets.

    I have the bets and the selection ID in a dataframe. I want to pass these to a function which will place these bets on the selection ID using a for loop. This looks like this:

    def placeFailingBet(marketId, selectionId, size):
    if( marketId is not None and selectionId is not None):
    print ('Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId))
    place_order_Req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/placeOrders", "params": {"marketId":"' + marketId + '","instructions":'\
    '[{"selectionId":"' + str(
    selectionId) + '","handicap":"0","side":"BACK","orderType":"LIMIT ","limitOrder":{"size":' \
    + str(size) + ',"price":"1.50","persistenceType":"LAPSE"}}],"customerRef":"test12121212121"}, "id": 1}'
    """
    print(place_order_Req)
    """
    place_order_Response = callAping(place_order_Req)
    place_order_load = json.loads(place_order_Response)




    I then call the function like so:





    size = df['size'].astype(str)
    size = '"' + size + '"'
    size = size

    for i, j in zip(size, selectionId):



    placeFailingBet(marketId = marketId, selectionId = j, size = i)





    This will place a bet but only for the first row. I want it to place a bet for all the rows in the dataframe.


    Any help would be great cheers,
    Sandy
    Last edited by Sandy; 16-03-2019, 11:13 PM. Reason: Simplifying code to make easier to read
  • Sandy
    Junior Member
    • Mar 2019
    • 26

    #2
    EDIT

    I don't seem to have rights to edit posts so I would like to show my edit which hopefully makes the code a bit easier to read and a link with an associated python file:

    Hello,

    I have started looking at the API. I am looking at the UK to win horse racing market. I have created a method, got my live API and able to place individual bets.

    I have the bets and the selection ID in a dataframe. I want to pass these to a function which will place these bets on the selection ID using a for loop. This looks like this:

    def placeFailingBet(marketId, selectionId, size):
    if( marketId is not None and selectionId is not None):
    print ('Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId))
    place_order_Req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/placeOrders", "params": {"marketId":"' + marketId + '","instructions":'\
    '[{"selectionId":"' + str(
    selectionId) + '","handicap":"0","side":"BACK","orderType":"LIMIT ","limitOrder":{"size":' \
    + str(size) + ',"price":"1.50","persistenceType":"LAPSE"}}],"customerRef":"test12121212121"}, "id": 1}'
    """
    print(place_order_Req)
    """
    place_order_Response = callAping(place_order_Req)
    place_order_load = json.loads(place_order_Response)




    I then call the function like so:





    size = df['size'].astype(str)
    size = '"' + size + '"'
    size = size

    for i, j in zip(size, selectionId):



    placeFailingBet(marketId = marketId, selectionId = j, size = i)





    This will place a bet but only for the first row. I want it to place a bet for all the rows in the dataframe.

    I have made a python file available at the following link which will give you a better idea of my approach: https://drive.google.com/file/d/1m8n...ew?usp=sharing

    Any help would be great cheers,
    Sandy

    Comment

    • Sandy
      Junior Member
      • Mar 2019
      • 26

      #3
      Ok, I have just gone through my code again and have now found out that there is a duplicate customer reference error. Therefore I assume I will need to generate a new customer reference for every order made.

      Comment

      • LiamP
        Junior Member
        • Oct 2015
        • 284

        #4
        Have you tried using betfairlightweight? It will allow you to focus on what you want to do rather than dealing with the requests.

        https://github.com/liampauling/betfair

        Comment

        • Sandy
          Junior Member
          • Mar 2019
          • 26

          #5
          LiamP I've not seen this github page. Thanks for the heads up.

          I've got it working now though. I think I'm to eager to get it working and rushing my work.

          Comment

          Working...
          X