Unable to place a football bet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stranoamedeo
    Junior Member
    • Mar 2016
    • 8

    #1

    Unable to place a football bet

    Hi,

    I am developing in Python and get the following error when trying to place a bet: Oops no service available at https://api.betfair.com/exchange/betting/json-rpc/v1

    Thats the code

    def placeBet(marketId, selectionId):
    if( marketId is not None and selectionId is not None):
    print 'Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId)
    place_order_Req = '{"marketId":"' + marketId + '","instructions":'\
    '[{"selectionId":"' + str(
    selectionId) + '","handicap":"0","side":"BACK","orderType":"LIMIT ","limitOrder":{"size":"3","price":"2.18","persist enceType":"LAPSE"}}],"customerRef":"test12121212121"},"id":1'
    #endPoint = 'https://api.betfair.com/exchange/betting/rest/v1.0/placeOrders/'
    """
    print place_order_Req
    """
    place_order_Response(place_order_Req)
    #place_order_Response = callAping2(endPoint,place_order_Req)
    place_order_load = json.loads(place_order_Response)
    print 'Place order status is ' + place_order_load['status']
    """
    print 'Place order error status is ' + place_order_load['errorCode']
    """

    In my main there is print '## make bet ##'placeBet(soccerMarketID, soccerSID1) where soccerMarketID is my marketid and soccerSID1 is my selection id. Would be great if you can help out
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #2
    In case there isn't a Python person along soon, I'll see what I can do.

    I assume you've logged in and all that, otherwise you probably wouldn't have a marketId, etc.

    I can see you referred to the example Python code in the documentation.

    I looked at your call and it looked as I'd expect.

    You are using the Rescript version of JSON rather than JSON-RPC, but the endpoint you're using isn't the same as in the examples. In the Python/Rescript example it has
    url = 'https://api.betfair.com/rest/v1.0/${operationName}/'

    Does that make any difference?

    Comment

    • jabe
      Senior Member
      • Dec 2014
      • 705

      #3
      Looking at your post again, you used the JSON-RPC endpoint, but then seem to have used the Rescript code example.

      There is a difference - if you use the JSON-RPC code, your coded string has to include more parameters.

      This is the JSON-RPC example from the Python example in the documentation:

      Code:
      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":"0.01","price":"1.50","persistenceType":"LAPSE"}}],"customerRef":"test12121212121"}, "id": 1}'
      This is the Rescript version, which you appear to have used:

      Code:
      place_order_Req = '{"marketId":"' + marketId + '","instructions":'\
      '[{"selectionId":"' + str(selectionId) + '","handicap":"0","side":"BACK","orderType":"LIMIT","limitOrder":{"size":"1.01","price":"1.50","persistenceType":"LAPSE"}}],"customerRef":"test12121212121"}'

      Comment

      • stranoamedeo
        Junior Member
        • Mar 2016
        • 8

        #4
        I am now using JSON-RPC code that I found on this link from Betfair developers:

        https://github.com/betfair/API-NG-sa...DemoJsonRpc.py

        That is now the code I am using:

        http://nopaste.linux-dev.org/?968943

        Unfortunately the problem persists (Oops no service available at https://api.betfair.com/exchange/betting/json-rpc/v1).

        Anybody else can help?

        Comment

        • jabe
          Senior Member
          • Dec 2014
          • 705

          #5
          Originally posted by stranoamedeo View Post
          I am now using JSON-RPC code that I found on this link from Betfair developers:

          https://github.com/betfair/API-NG-sa...DemoJsonRpc.py

          That is now the code I am using:

          http://nopaste.linux-dev.org/?968943

          Unfortunately the problem persists (Oops no service available at https://api.betfair.com/exchange/betting/json-rpc/v1).

          Anybody else can help?
          I'm no further with the service problem.

          However, some of the brackets look wrong in this version.

          These brackets [] denote an array or similar. Your instructions are an array of type PlaceInstruction. As such, each set of instructions should be contained within a pair of these brackets { }, as in your original post.

          Your limitOrder parameters should have {} and now have [].

          You seem to have lost the id=1 parameter.

          There is a JSON tuturial on the w3c site if it helps:
          http://www.w3schools.com/json/

          Comment

          • stranoamedeo
            Junior Member
            • Mar 2016
            • 8

            #6
            Thanks for all Jabe,

            I fixed the code with the correct brackets {} the actual state of the method placeFailingBet is :

            def placeFailingBet(marketId, selectionId):
            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":"3","price":"2.18","persist enceType":"LAPSE"}}],"customerRef":"test12121212121"}, "id": 1}'
            """
            print place_order_Req
            """
            place_order_Response = callAping(place_order_Req)
            place_order_load = json.loads(place_order_Response)
            try:
            place_order_result = place_order_load['result']
            print 'Place order status is ' + place_order_result['status']
            """
            print 'Place order error status is ' + place_order_result['errorCode']
            """
            print 'Reason for Place order failure is ' + place_order_result['instructionReports'][0]['errorCode']
            except:
            print 'Exception from API-NG' + str(place_order_load['error'])
            """
            print place_order_Response
            """


            But still doesn't work! The output is :

            Place order status is FAILURE
            Reason for Place order failure is ERROR_IN_ORDER



            Any solution??

            Thanks in advance..

            Originally posted by jabe View Post
            I'm no further with the service problem.

            However, some of the brackets look wrong in this version.

            These brackets [] denote an array or similar. Your instructions are an array of type PlaceInstruction. As such, each set of instructions should be contained within a pair of these brackets { }, as in your original post.

            Your limitOrder parameters should have {} and now have [].

            You seem to have lost the id=1 parameter.

            There is a JSON tuturial on the w3c site if it helps:
            http://www.w3schools.com/json/

            Comment

            • jabe
              Senior Member
              • Dec 2014
              • 705

              #7
              I've got a test tab on my current program and betting is the next phase I have to code. I should be able to try to place a bet from the test page, but it'll have to be this evening. I'll try to make the JSON code as much like yours as I possibly can, and I'll let you know what happens.

              Comment

              • jabe
                Senior Member
                • Dec 2014
                • 705

                #8
                This might seem daft, but can you check the orderType parameter - you have a space in the "LIMIT " string. Is there one in "persistenceType" too? Can you check those and test again?

                Comment

                • stranoamedeo
                  Junior Member
                  • Mar 2016
                  • 8

                  #9
                  No because if insert a SPACE in orderType in LIMIT after that string or in persistenceType arguments like LAPSE obtain this message :

                  Exception from API-NG{u'message': u'DSC-0018', u'code': -32602}

                  Thanks a lot for the support...


                  Originally posted by jabe View Post
                  This might seem daft, but can you check the orderType parameter - you have a space in the "LIMIT " string. Is there one in "persistenceType" too? Can you check those and test again?

                  Comment

                  • jabe
                    Senior Member
                    • Dec 2014
                    • 705

                    #10
                    Your last post confused me - I didn't want you to insert any spaces, I wanted you to remove spaces.

                    Anyway, I tried placing a bet and I couldn't make it work. I had persistenceType = LAPSE but realised it was an error because the event was in-play, but changing it didn't help.

                    I will try again and let you know if I succeed.

                    Comment

                    • stranoamedeo
                      Junior Member
                      • Mar 2016
                      • 8

                      #11
                      I want to say you that, if i insert the space the script return this exception..but i don't have space in the variable that you previously mentioned

                      Anyway, well and thanks for the help!!!

                      Originally posted by jabe View Post
                      Your last post confused me - I didn't want you to insert any spaces, I wanted you to remove spaces.

                      Anyway, I tried placing a bet and I couldn't make it work. I had persistenceType = LAPSE but realised it was an error because the event was in-play, but changing it didn't help.

                      I will try again and let you know if I succeed.

                      Comment

                      • jabe
                        Senior Member
                        • Dec 2014
                        • 705

                        #12
                        Now I'm confused. I tried placing a bet via the test page of my program and it wouldn't work. I've tried placing one on one of tomorrow's (Friday's) football matches and it worked. I've since tried placing a bet on another current game and it has been accepted.

                        The only difference is that I altered a tiny amount of code in my (VB.NET) program so that a Catch option has an added parameter and is now Catch e as WebException.

                        Hmmm.

                        But that doesn't solve your problem. I'll assume you no longer have the unnecessary space at the end of your "LIMIT " string.

                        Are the events that you wish to place bets on in-play?

                        Have you made any bets on Betfair within the last few months?

                        Comment

                        • jabe
                          Senior Member
                          • Dec 2014
                          • 705

                          #13
                          You say that you don't have a space in there, but if I copy and paste from your first post, there is an extra space:

                          "orderType":"LIMIT "

                          and if I copy and paste from your post of 3:49pm, it is still there

                          "orderType":"LIMIT "

                          between the T and the final " each time.

                          Adding a space to my working version of the call is enough to make it fail.

                          Comment

                          • stranoamedeo
                            Junior Member
                            • Mar 2016
                            • 8

                            #14
                            No, i want place bet on Roma - Palermo (Campionato Primavera)

                            Yes, i made bets everyday...

                            I don't see any extra space char on my code i paste again on this link :

                            http://nopaste.linux-dev.org/?970573

                            Thanks a lot!!!

                            Originally posted by jabe View Post
                            Now I'm confused. I tried placing a bet via the test page of my program and it wouldn't work. I've tried placing one on one of tomorrow's (Friday's) football matches and it worked. I've since tried placing a bet on another current game and it has been accepted.

                            The only difference is that I altered a tiny amount of code in my (VB.NET) program so that a Catch option has an added parameter and is now Catch e as WebException.

                            Hmmm.

                            But that doesn't solve your problem. I'll assume you no longer have the unnecessary space at the end of your "LIMIT " string.

                            Are the events that you wish to place bets on in-play?

                            Have you made any bets on Betfair within the last few months?

                            Comment

                            • jabe
                              Senior Member
                              • Dec 2014
                              • 705

                              #15
                              No, you're right, the string is fine in your actual code. Must have been caused by the pasting. I use a website which mysteriously adds a space into a pasted URL while leaving it usable.

                              I can't see anything wrong with the placeOrders call in your link.

                              I'm very confused because I can't see any difference at all in the JSON code I tried that failed for one match and the code that worked for another.

                              Comment

                              Working...
                              X