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


Comment