Getting back stake taken for the starting price using python horse racing

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

    #1

    Getting back stake taken for the starting price using python horse racing

    I am trying to get the total amount of back bets matched at the actual Betfair Starting Price and the same for the lay bets. I am using the following code:

    def full_function(market_ID):

    global marketId, selectionId, size, df, total_liability

    getMarketBookBestOffers(marketId = market_ID)
    market_book_result[0]['runners'][0]['selectionId']
    runner_ID_list = []

    for i in market_book_result[0]['runners']:

    if i['status'] == 'ACTIVE':
    ID = i['selectionId']
    runner_ID_list.append(ID)

    near_price_list = []

    for i in market_book_result[0]['runners']:
    if i['status'] == 'ACTIVE':
    backStakeTaken = i['sp']['backStakeTaken']
    backStakeTaken.append(backStakeTaken)

    data = {'selectionId': runner_ID_list,
    'backStakeTaken': backStakeTaken}

    print(data)


    From this I an output where the BackStakeTaken is an empty list which looks like such:

    Calling listMarketBook to read prices for the Market with ID :1.163700443 {'selectionId': [10050919, 21652963, 13064814, 14386722, 11412690, 18328826, 23760347, 20548487, 13285071, 19123620, 22749575, 16704295, 10065383, 18518540], 'backStakeTaken': [[...]]}
    backStakeTaken was taken from the api documentation so I assume it should work. Am I doing something wrong?

    If someone could enlighten me that would be great.

    All the best,
    Sandy

  • Sandy
    Junior Member
    • Mar 2019
    • 26

    #2
    When I check the market_book_result the backStakeTaken contains [[...]]. Therefore has this been removed from market_book_result. Does this mean it is no longer possible to see this? Is this a problem that will be fixed or has the backstaketaken been removed?

    Comment

    • LiamP
      Junior Member
      • Oct 2015
      • 284

      #3
      Are you sure you are asking for sp data in the request, can’t see in this code.

      If you are using python:

      https://github.com/liampauling/betfair

      Comment

      • Sandy
        Junior Member
        • Mar 2019
        • 26

        #4
        Thanks for getting back to me Paul.

        Do you mean in the market_book_result?

        When I look at the market_book_result I get the following:

        [{'betDelay': 0, 'bspReconciled': False, 'complete': True, 'crossMatching': True, 'inplay': False, 'isMarketDataDelayed': False, 'lastMatchTime': '2019-10-16T17:02:17.457Z', 'marketId': '1.163700273', 'numberOfActiveRunners': 8, 'numberOfRunners': 8, 'numberOfWinners': 3, 'runners': [{'adjustmentFactor': 31.642, 'handicap': 0.0, 'lastPriceTraded': 1.75, 'selectionId': 25867636, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.7626364161173806, 'layLiabilityTaken': [], 'nearPrice': 1.76}, 'status': 'ACTIVE', 'totalMatched': 2515.89}, {'adjustmentFactor': 28.147, 'handicap': 0.0, 'lastPriceTraded': 1.94, 'selectionId': 24720971, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.0, 'layLiabilityTaken': [], 'nearPrice': 1.9185333333333254}, 'status': 'ACTIVE', 'totalMatched': 2323.69}, {'adjustmentFactor': 22.885, 'handicap': 0.0, 'lastPriceTraded': 2.14, 'selectionId': 24681464, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.0, 'layLiabilityTaken': [], 'nearPrice': 2.09699574138598}, 'status': 'ACTIVE', 'totalMatched': 1149.71}, {'adjustmentFactor': 22.533, 'handicap': 0.0, 'lastPriceTraded': 2.62, 'selectionId': 24989000, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.0, 'layLiabilityTaken': [], 'nearPrice': 2.2167669787314663}, 'status': 'ACTIVE', 'totalMatched': 1084.18}, {'adjustmentFactor': 20.315, 'handicap': 0.0, 'lastPriceTraded': 2.62, 'selectionId': 13924, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.3614675582866438, 'layLiabilityTaken': [], 'nearPrice': 2.6344219588637143}, 'status': 'ACTIVE', 'totalMatched': 1944.29}, {'adjustmentFactor': 15.03, 'handicap': 0.0, 'lastPriceTraded': 3.9, 'selectionId': 24232232, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.4545454545454546, 'layLiabilityTaken': [], 'nearPrice': 3.898947541}, 'status': 'ACTIVE', 'totalMatched': 796.78}, {'adjustmentFactor': 12.877, 'handicap': 0.0, 'lastPriceTraded': 4.0, 'selectionId': 24258419, 'sp': {'backStakeTaken': [[...]], 'farPrice': 1.1630434782608696, 'layLiabilityTaken': [], 'nearPrice': 3.971573832}, 'status': 'ACTIVE', 'totalMatched': 19179.85}, {'adjustmentFactor': 9.616, 'handicap': 0.0, 'lastPriceTraded': 5.2, 'selectionId': 13523, 'sp': {'backStakeTaken': [[...]], 'farPrice': 3.6315789473684212, 'layLiabilityTaken': [], 'nearPrice': 5.2}, 'status': 'ACTIVE', 'totalMatched': 822.0}], 'runnersVoidable': False, 'status': 'OPEN', 'totalAvailable': 30690.23, 'totalMatched': 29816.43, 'version': 2990854117}]
        When I look at the back liability taken line it says 'sp': {'backStakeTaken': [[...]].

        Is there a different market book results specific to starting price where I can get the traded amount of back stake taken?

        Cheers for getting back to me LiamP.

        Sandy


        Comment

        • LiamP
          Junior Member
          • Oct 2015
          • 284

          #5
          That is the response, what does your request look like? No idea what […] means?

          Comment

          • Sandy
            Junior Member
            • Mar 2019
            • 26

            #6
            My request is this if im not mistaken:

            market_book_req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listMarketBook", "params": {"marketIds":["' + marketId + '"],"priceProjection":{"priceData":["SP_AVAILABLE"]}}, "id": 1}'

            I tried changing SP_AVAILABLE to SP_TRADED and get the following response:

            [{'betDelay': 0, 'bspReconciled': False, 'complete': False, 'crossMatching': False, 'inplay': False, 'isMarketDataDelayed': False, 'lastMatchTime': '2019-10-16T21:03:34.599Z', 'marketId': '1.163746895', 'numberOfActiveRunners': 8, 'numberOfRunners': 8, 'numberOfWinners': 3, 'runners': [{'adjustmentFactor': 32.714, 'handicap': 0.0, 'selectionId': 15487774, 'status': 'ACTIVE', 'totalMatched': 0.0}, {'adjustmentFactor': 20.607, 'handicap': 0.0, 'selectionId': 21835915, 'status': 'ACTIVE', 'totalMatched': 0.0}, {'adjustmentFactor': 28.58, 'handicap': 0.0, 'selectionId': 21534805, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 54.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 0.0}, {'adjustmentFactor': 17.646, 'handicap': 0.0, 'selectionId': 21470082, 'status': 'ACTIVE', 'totalMatched': 0.0}, {'adjustmentFactor': 20.607, 'handicap': 0.0, 'selectionId': 15914199, 'status': 'ACTIVE', 'totalMatched': 0.0}, {'adjustmentFactor': 17.646, 'handicap': 0.0, 'lastPriceTraded': 3.6, 'selectionId': 17675572, 'status': 'ACTIVE', 'totalMatched': 4.12}, {'adjustmentFactor': 14.536, 'handicap': 0.0, 'selectionId': 12896540, 'status': 'ACTIVE', 'totalMatched': 0.0}, {'adjustmentFactor': 10.309, 'handicap': 0.0, 'selectionId': 9237146, 'status': 'ACTIVE', 'totalMatched': 0.0}], 'runnersVoidable': False, 'status': 'OPEN', 'totalAvailable': 6903.17, 'totalMatched': 4.12, 'version': 2990972455}]


            I can see the line 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 54.0}] which looks like the back stake taken at size 54.0. I would like to see the back stake and lay liability taken for each runner which does not seem to be in this response.

            Comment

            • LiamP
              Junior Member
              • Oct 2015
              • 284

              #7
              Delayed key?

              Comment

              • Sandy
                Junior Member
                • Mar 2019
                • 26

                #8
                No its the live key.

                I have now repeated the my request using SP_Traded and now have the following response:

                [{'betDelay': 0, 'bspReconciled': False, 'complete': False, 'crossMatching': False, 'inplay': False, 'isMarketDataDelayed': False, 'lastMatchTime': '2019-10-17T09:50:56.617Z', 'marketId': '1.163746895', 'numberOfActiveRunners': 7, 'numberOfRunners': 8, 'numberOfWinners': 3, 'runners': [{'adjustmentFactor': 20.63, 'handicap': 0.0, 'lastPriceTraded': 1.61, 'selectionId': 21470082, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 77.51}, {'price': 1.5, 'size': 25.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 785.44}, {'adjustmentFactor': 36.432, 'handicap': 0.0, 'lastPriceTraded': 1.63, 'selectionId': 15487774, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 20.0}, {'price': 1.5, 'size': 25.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 260.81}, {'adjustmentFactor': 32.319, 'handicap': 0.0, 'lastPriceTraded': 2.02, 'selectionId': 21534805, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 54.0}, {'price': 1.5, 'size': 25.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 702.81}, {'adjustmentFactor': 23.908, 'handicap': 0.0, 'lastPriceTraded': 2.08, 'selectionId': 15914199, 'status': 'ACTIVE', 'totalMatched': 321.28}, {'adjustmentFactor': 20.63, 'handicap': 0.0, 'lastPriceTraded': 2.54, 'selectionId': 17675572, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 50.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 842.67}, {'adjustmentFactor': 23.908, 'handicap': 0.0, 'lastPriceTraded': 3.55, 'selectionId': 21835915, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 7.0}, {'price': 1.5, 'size': 25.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 535.3}, {'adjustmentFactor': 17.113, 'handicap': 0.0, 'lastPriceTraded': 7.4, 'selectionId': 12896540, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 15.0}], 'layLiabilityTaken': []}, 'status': 'ACTIVE', 'totalMatched': 89.57}, {'adjustmentFactor': 9.159, 'handicap': 0.0, 'removalDate': '2019-10-17T07:02:29.000Z', 'selectionId': 9237146, 'status': 'REMOVED'}], 'runnersVoidable': False, 'status': 'OPEN', 'totalAvailable': 21036.96, 'totalMatched': 3537.92, 'version': 2991529532}]

                If look at the runner now I can see that there is a size for each of the runners backstake. If we take one as example:

                'selectionId': 21470082, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 77.51}, {'price': 1.5, 'size': 25.0}], 'layLiabilityTaken': []},

                Looking at it looks like it has a back stake taken at size 77.51. Though when I look at the lay liability taken it is still empty. It could be possible that no lay SP bets have been placed. So I will check again closer to start of the race to see if this changes.

                Also what is the size 25.0? Could this be the lay bet placed?

                Comment

                • Sandy
                  Junior Member
                  • Mar 2019
                  • 26

                  #9
                  If I look at it now the response has changed again to this:

                  'selectionId': 21470082, 'sp': {'backStakeTaken': [{'price': 1.01, 'size': 77.51}, {'price': 1.5, 'size': 25.0}, {'price': 2.0, 'size': 2.0}], 'layLiabilityTaken': [{'price': 1000.0, 'size': 40.0}]}, 'status': 'ACTIVE', 'totalMatched': 1362.72},
                  Some of the runners still have an empty lay liability though.

                  I am not sure how the above response show me the volume who have backed and the volume who have laid. I assume the totalMatched is the total volume on the sp market but I would like to see how much have backed and how much have laid separately.

                  Cheers,
                  Sandy

                  Comment

                  Working...
                  X