Place my First Orderr

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheLuMi
    Junior Member
    • Feb 2016
    • 4

    #1

    Place my First Orderr

    Hello,

    After looking at several posts, codes, etc...I am trying to place my first order and I run to this error which seems to be easy to resolve but I'm unable. Any help out there?

    To make it simple I fixed the marketid, selectionid in the scipt

    ________
    #!/usr/bin/python
    # coding:UTF-8

    import urllib2
    import json
    import datetime
    import sys
    import requests
    import urllib
    import sqlite3

    def callAping(url, request):
    try:
    req = urllib2.Request(url, request, headers)
    response = urllib2.urlopen(req)
    jsonResponse = response.read()
    return jsonResponse

    except urllib2.URLError:
    print 'Oops there is some issue with the request'
    exit()
    except urllib2.HTTPError:
    print 'Oops there is some issue with the request' + urllib2.HTTPError.getcode()
    exit()

    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":"4.00","price":"1.8","persi stenceType":"LAPSE"}}],"customerRef":"test12121212121"}'
    endPoint = 'https://beta-api.betfair.com/rest/v1.0/placeOrders/'
    """
    print place_order_Req
    """
    place_order_Response = callAping(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']
    """
    print 'Reason for Place order failure is ' + place_order_load['instructionReports'][0]['errorCode']
    """
    print place_order_Response
    """

    placeBet(1.122709508, 47973)

    ________

    the error message:

    ./PlaceOrder.py
    Traceback (most recent call last):
    File "./PlaceOrder.py", line 46, in <module>
    placeBet(1.122709508, 47973)
    File "./PlaceOrder.py", line 27, in placeBet
    print 'Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId)
    TypeError: cannot concatenate 'str' and 'float' objects
  • Franklin1
    Junior Member
    • Mar 2012
    • 91

    #2
    Originally posted by TheLuMi View Post
    print 'Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId)

    the error message:

    ./PlaceOrder.py
    Traceback (most recent call last):
    File "./PlaceOrder.py", line 46, in <module>
    placeBet(1.122709508, 47973)
    File "./PlaceOrder.py", line 27, in placeBet
    print 'Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId)
    TypeError: cannot concatenate 'str' and 'float' objects
    it looks to me like the error here is just to do with your print command which does not like concatenating marketId to your strong.

    try this:
    print 'Calling placeOrder for marketId :' + str(marketId) + ' with selection id :' + str(selectionId)

    Comment

    • TheLuMi
      Junior Member
      • Feb 2016
      • 4

      #3
      Thanks for your answer, indeed this fixed the first error. there is a second error now. are you able to take a look at it, please?

      ./PlaceOrder.py
      Calling placeOrder for marketId :1.122756433 with selection id :47973
      Oops there is some issue with the request

      Comment

      • Franklin1
        Junior Member
        • Mar 2012
        • 91

        #4
        where did you get this code? There could be many bugs between where you get to and making a successful request

        you're getting an urllib2.URLError.

        change your code to this:
        except urllib2.URLError as e:
        print str(e)

        Also please post your place_order_Req string here (your cpde prints it)

        Comment

        • betdynamics
          Junior Member
          • Sep 2010
          • 534

          #5
          This looks like very old code to me.

          You are using the endpoint:

          endPoint = 'https://beta-api.betfair.com/rest/v1.0/placeOrders/'

          I'm not sure that even exists anymore!

          The correct endpoint would be:

          endPoint = 'https://api.betfair.com/exchange/betting/rest/v1.0/placeOrders/'

          Comment

          • TheLuMi
            Junior Member
            • Feb 2016
            • 4

            #6
            Thanks for both of you, I got it to work and I placed my first bet. Interesting, I actually recvd an error message but bet was placed:

            _
            Calling placeOrder for marketId :1.122758606 with selection id :47973
            Place order status is SUCCESS
            Traceback (most recent call last):
            File "./PlaceOrder.py", line 64, in <module>
            placeBet(1.122758606, 47973)
            File "./PlaceOrder.py", line 52, in placeBet
            print 'Reason for Place order failure is ' + place_order_load['instructionReports'][0]['errorCode']
            KeyError: 'errorCode'
            _

            Here is the code again:

            _
            def callAping(url, request):
            try:
            req = urllib2.Request(url, request, headers)
            response = urllib2.urlopen(req)
            jsonResponse = response.read()
            return jsonResponse

            except urllib2.URLError:
            print 'Oops there is some issue with the request'
            exit()
            except urllib2.HTTPError:
            print 'Oops there is some issue with the request' + urllib2.HTTPError.getcode()
            exit()

            def placeBet(marketId, selectionId):
            if( marketId is not None and selectionId is not None):
            print 'Calling placeOrder for marketId :' + str(marketId) + ' with selection id :' + str(selectionId)
            place_order_Req = '{"marketId":"' + str(marketId) + '","instructions":'\
            '[{"selectionId":"' + str(
            selectionId) + '","handicap":"0","side":"BACK","orderType":"LIMIT ","limitOrder":{"size":"4.00","price":"1.8","persi stenceType":"LAPSE"}}],"customerRef":"test12121212121"}'
            endPoint = 'https://api.betfair.com/exchange/betting/rest/v1.0/placeOrders/'
            """
            print place_order_Req
            """
            place_order_Response = callAping(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']
            """
            print 'Reason for Place order failure is ' + place_order_load['instructionReports'][0]['errorCode']
            """
            print place_order_Response
            """

            headers = {'X-Application': appKey, 'X-Authentication': sessionToken, 'content-type': 'application/json',
            'accept': 'application/json'}

            placeBet(1.122758606, 47973)

            _

            is it normal that I have this error?

            Comment

            • TheLuMi
              Junior Member
              • Feb 2016
              • 4

              #7
              I think I got it now, just need help to display the betId ...

              Comment

              Working...
              X