No announcement yet.

Can't Return Runner Name - Python

  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't Return Runner Name - Python

    The code below works perfectly in giving me everything I want in a dataframe but I can't get Runner Name returned which is frustrating. I have tried for hours but can't figure this out. below is an excerpt from the documentation.

    Any help is greatly appreciated
    selectionId long The unique id of the runner (selection). Please note - the same selectionId and runnerName pairs are used accross all Betfair markets which contain them.

    def process_runner_books(runner_books):
    This function processes the runner books and returns a DataFrame with the best back/lay prices + vol for each runner
    aram runner_books:
    selection_ids = [runner_book.selection_id for runner_book in runner_books]
    last_prices_traded = [runner_book.last_price_traded for runner_book in runner_books]
    total_matched = [runner_book.total_matched for runner_book in runner_books]
    statuses = [runner_book.status for runner_book in runner_books]
    scratching_datetimes = [runner_book.removal_date for runner_book in runner_books]
    adjustment_factors = [runner_book.adjustment_factor for runner_book in runner_books]

    df = pd.DataFrame({
    'Selection ID': selection_ids,
    'Last Price Traded': last_prices_traded,
    'Total Matched': total_matched,
    'Status': statuses,
    'Removal Date': scratching_datetimes,
    'Adjustment Factor': adjustment_factors
    return df

    # Create a price filter. Get all traded and offer data
    price_filter = betfairlightweight.filters.price_projection(

    # Request market books
    market_books = trading.betting.list_market_book(

    # Grab the first market book from the returned list as we only requested one market
    market_book = market_books[0]

    runners_df = process_runner_books(market_book.runners)


  • #2
    Hi DB2702,

    Runner name is available from listMarketCatalogue only and you must map any selection names to the selectionId's and names returned via the response to the listMarketCatalgue request.

    You can see an example via http://

    Kind Regards

    Last edited by BetfairDeveloperProgram; 30-03-2022, 10:38 AM.


    • #3
      Appreciate the feedback above.

      Under CODE 1 below, this operates exactly how I want it to, RETURN 1 returns 5 matches and all their selection IDs and team names

      Under, CODE 2, however, it only returns one game with odds for each selection as you can see in RETURN 2, I want it to return a complete list like it does for RETURN 1

      QUESTION: how can I ensure all 5 matches show in RETURN 2 by changing CODE 2?

      CODE 1

      # list all football competition market catalogues I care about
      market_catalogues = trading.betting.list_market_catalogue(
      competition_ids =[10932509,7129730, 35, 37, 105, 107, 109,111,59,61,117,12204313,81,12199689, 55,57,89979, 9404054, 99, 194215, 67],
      market_type_codes= ['MATCH_ODDS'],
      max_results = 5

      for market_catalogue in market_catalogues:

      for runner in market_catalogue.runners:
      # prints runner id, runner name
      print(runner.selection_id, runner.runner_name)

      RETURN 1

      70385 Hull 78984 Huddersfield 58805 The Draw 13734279 Kfco Beerschot Wilrijk 10762 Club Brugge 58805 The Draw 968185 Girona 13360 Malaga 58805 The Draw 48799 Braga 48783 Benfica 58805 The Draw 1341524 Giresunspor 508773 Sivasspor 58805 The Draw

      CODE 2

      # market book request
      market_books = trading.betting.list_market_book(

      for market_book in market_books:

      for runner in market_book.runners:
      # prints selection id, status and total matched
      runner.selection_id, runner.status, runner.last_price_traded

      RETURN 2

      1341524 ACTIVE 2.6 508773 ACTIVE 3.2 58805 ACTIVE 3.3

      Thank you


      • #4
        Hi DB2702

        In this case, you can request up to 40 marketId's in the listMarketBook request, so for example:

        [{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listMarketBook", "params": {"marketIds":["1.184539135","1.184101449","1.185352214","1.18535 2396","1.185352415"],"priceProjection":{"priceData":["EX_ALL_OFFERS"],"virtualise":"true"}}, "id": 1}]

        You can then print out the market_Id, runner.selection_id, runner.status, runner.last_price_traded from the response.

        Kind Regards



        • #5
          perfect, thank you so much