Market IDs for events cannot be found through their event IDs - Betfair

853 views Asked by At

I have events (matches i.e. Richmond vs Collingwood) and their respective IDs for a given competition, in my case AFL, however when trying to get the market IDs associated with these events, the API only gives the competition market ID as a response. How do I change my request so that this information is also given?

The Python library I am using is: https://github.com/liampauling/betfair

The following is the code I'm using to 1. get the competition ID for afl, 2. get the event IDs and names for all of the matches in that competition, and 3. get the market IDs for the events.

In [1]:

competition_id = client.betting.list_competitions(filter=filters.market_filter(event_ids=event_ids))[-1].competition.id

Out [1]: 11897406

In [2]:

events = client.betting.list_events(
    filter=filters.market_filter(
        competition_ids=[competition_id]))

for event_result in events:
    print(event_result.event.name, event_result.event.id)

Out[2]:

AFL 28159788
Brownlow Medal 2019 28927640
Hawthorn v Western Bulldogs 29182265
North Melbourne v Brisbane 29182264
Gold Coast v Fremantle 29182266
Port Adelaide v Carlton 29182261
Favourites To Win 29203764
Geelong v Melbourne 29182263
West Coast v GWS 29182262
Sydney v Adelaide 29182257
Women's AFL 28113600
Essendon v St Kilda 29182258
AFL Round 2 Multis 29195364
Adelaide (W) v Carlton (W) 29199747

In [3]:

AFL_market_catalogue = client.betting.list_market_catalogue(filter=filters.market_filter(event_ids=event_ids),
                                                           market_projection=['EVENT', 'COMPETITION'])[0]

Out [3]:

{"marketId":"1.148783689","marketName":"Premiers 2019","totalMatched":293415.056733,"competition":{"id":"11897406","name":"AFL"},"event":{"id":"28159788","name":"AFL","countryCode":"AU","timezone":"GMT","openDate":"2099-01-01T00:00:00.000Z"}}

As shown in the output of 3, the only marketID returned is that of the premiers 2019 - when I need Hawthorn v Western Bulldogs, North Melbourne v Brisbane and so on.

1

There are 1 answers

0
Cosmittus On

Try setting max_results=n as a parameter of list_market_catalogue().

The documentation (https://developers.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/listMarketCatalogue) says that a maxResults integer is required for listMarketCatalogue(). Conversely, the API Sports demo tool (https://docs.developer.betfair.com/visualisers/api-ng-sports-operations/) defaults to a Max Results value of 1. The top result is 'Premiers 2019' and the rest are ignored.

[My Python is a little rusty so I'm also going to ask if that [0] is supposed to be there after the closing parenthesis?]

There are currently 14 markets available for each of the AFL games I can see at the moment, so if you want to limit the results only to the main winning team market you'll need to include MATCH_ODDS in the market_types_codes of the filter.