Selection ID to Selection Name for golf

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rbbor
    Junior Member
    • Feb 2019
    • 2

    #1

    Selection ID to Selection Name for golf

    Hi there,

    Im new to the api and have been playing around with golf markets.

    I want to return a dataframe that contains the players name in the first column and the last price traded in the second.

    Currently running this python code which returns a dataframe of selection ID in the first column and last price traded in the second.

    How to I add an additional column that contains the players name? Or how to I convert the selection ID to the name of the player? Either will work.

    Code below, thanks in advance


    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:
    :return:
    '''

    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]

    df = pd.DataFrame({
    'Selection ID': selection_ids,
    'Last Price Traded': last_prices_traded
    })
    return df


    # Create a price filter. Get all traded and offer data
    price_filter = betfairlightweight.filters.price_projection(
    price_data=['EX_BEST_OFFERS']
    )

    # Request market books
    market_books = trading.betting.list_market_book(
    market_ids=['1.154770414'],
    price_projection=price_filter
    )

    # 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)

    runners_df
  • newbie99
    Junior Member
    • Dec 2018
    • 62

    #2
    Originally posted by rbbor View Post
    Hi there,

    Im new to the api and have been playing around with golf markets.

    I want to return a dataframe that contains the players name in the first column and the last price traded in the second.

    Currently running this python code which returns a dataframe of selection ID in the first column and last price traded in the second.

    How to I add an additional column that contains the players name? Or how to I convert the selection ID to the name of the player? Either will work.

    Code below, thanks in advance


    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:
    :return:
    '''

    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]

    df = pd.DataFrame({
    'Selection ID': selection_ids,
    'Last Price Traded': last_prices_traded
    })
    return df


    # Create a price filter. Get all traded and offer data
    price_filter = betfairlightweight.filters.price_projection(
    price_data=['EX_BEST_OFFERS']
    )

    # Request market books
    market_books = trading.betting.list_market_book(
    market_ids=['1.154770414'],
    price_projection=price_filter
    )

    # 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)

    runners_df
    Not quite the ideal answer, but I think (if I'm understanding correctly), then the following works in PHP, you may be able to translate to Python (ignoring the json_decode, json_encode bit thats a quick fix, rather than best practice of course):

    Code:
    $market_id = $market_ids;
    $request_type = 'betting';
    $request_name = 'listMarketCatalogue';
    $paramaters ='{"filter":{"marketIds":["'.$market_id.'"]},"marketProjection":["RUNNER_DESCRIPTION"],"maxResults": "200"}';
    $market_data= json_decode(json_encode(betfair_request($app_key, $session_token, $request_type, $request_name, $paramaters)), true);
    $runners = filter_array($market_data[0]['runners'],$i['selectionId'],'selectionId');
    The simple answer btw is that there isn't a tidy way to do this, one way or another you have to call listMarketCatalogue and then match the runners by filtering out or selecting based on selection id for that particular row.
    Last edited by newbie99; 16-02-2019, 05:42 PM.

    Comment

    • rbbor
      Junior Member
      • Feb 2019
      • 2

      #3
      Thanks, I can merge the data easy enough.

      I suppose my question is then how do I call listMarketCatalogue using python and return a dictionary of all selection_ids : players in a market?

      Or else a dataframe containing two columns one with the selection ids and one with the corresponding player names?

      Comment

      • newbie99
        Junior Member
        • Dec 2018
        • 62

        #4
        Originally posted by rbbor View Post
        Thanks, I can merge the data easy enough.

        I suppose my question is then how do I call listMarketCatalogue using python and return a dictionary of all selection_ids : players in a market?

        Or else a dataframe containing two columns one with the selection ids and one with the corresponding player names?
        Just a thought, but as you're working in Python, have you considered the Betfairlightweight wrapper?

        There is quite a lot out there on this (I'm completely new to Python myself, but have been learning with the assistance of a few very helpful people on the related Slack group).

        This may be a useful starting point:

        https://github.com/liampauling/betfa...aster/examples

        Comment

        • Sammy
          Junior Member
          • May 2019
          • 2

          #5
          Did anyone ever find a neat python solution to this?

          I will take a look at the code given above and see if i can translate it over but it does seem like a pretty fundamental feature to lack for the API

          Comment

          Working...
          X