首页 > 解决方案 > Market IDs for events cannot be found through their event IDs - Betfair

问题描述

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.

标签: python-3.xbetfair

解决方案


尝试设置max_results=nlist_market_catalogue().

文档(https://developers.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/listMarketCatalogue)说 maxResults 整数是必需的listMarketCatalogue()。相反,API Sports 演示工具 ( https://docs.developer.betfair.com/visualisers/api-ng-sports-operations/ ) 默认的 Max Results 值为 1。顶部结果是“ Premiers 2019 ”,而其余被忽略。

[我的 Python 有点生锈,所以我还要问是否[0]应该在右括号之后出现?]

目前我可以看到的每场 AFL 比赛都有 14 个可用的市场,所以如果你想将结果仅限于主要获胜球队的市场,你需要将其包含MATCH_ODDSmarket_types_codes过滤器中。


推荐阅读