How to get the starting price of a market's selection on in-play football markets?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gamblr
    Junior Member
    • May 2020
    • 5

    #1

    How to get the starting price of a market's selection on in-play football markets?

    My apologies if this has already been answered but I couldn't find anything conclusive searching the forum. Given any football market that's in-play (e.g., OVER_UNDER_05), I'd like to be able to check the starting odds for a particular selection within that market, is this possible at all? I tried using the SP_XXX price projections on listMarketBook/listRunnerBook but I don't seem to get the SP information on the response (tried with the API-NG Demo tool as well). Any help would be appreciated. Thanks
  • sabrina23
    Junior Member
    • Sep 2024
    • 1

    #2
    I recommend using the Betfair API's listMarketBook or listRunnerBook methods.
    Code:
    import requests
    
    # Replace with your Betfair API credentials
    app_key = "your_app_key"
    session_token = "your_session_token"
    
    # Market ID of the in-play football market
    market_id = "1.1234567890"
    
    headers = {
        "X-Application": app_key,
        "X-Authentication": session_token,
    }
    
    params = {
        "marketIds": [market_id],
    }
    
    response = requests.post("https://api.betfair.com/exchange/rest/v2/listMarketBook", headers=headers, json=params)
    
    if response.status_code == 200:
        market_book = response.json()["result"][0]
        runners = market_book["runners"]
    
        for runner in runners:
            if runner["status"] == "ACTIVE" or runner["status"] == "SUSPENDED":
                selection_id = runner["selectionId"]
                starting_price = runner["startingPrice"]
                print(f"Selection ID: {selection_id}, Starting Price: {starting_price}")
    else:
        print("Error fetching market book:", response.text)​
    This code will retrieve the starting price for all active or suspended runners in the specified in-play football market. You can adjust the `market_id` and other parameters to match your specific needs.

    Comment

    Working...
    X