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
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]
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(
price_data=['EX_BEST_OFFERS']
)
# Request market books
market_books = trading.betting.list_market_book(
market_ids=['1.196159616'],
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
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::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]
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(
price_data=['EX_BEST_OFFERS']
)
# Request market books
market_books = trading.betting.list_market_book(
market_ids=['1.196159616'],
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