python-3.x - 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.
解决方案
尝试设置max_results=n
为list_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_ODDS
在market_types_codes
过滤器中。
推荐阅读
- javascript - for循环内的回调
- automapper - 具有干净架构和 AutoMapper 的 asp.net 核心 - 将 DTO 通过服务层传递到控制器
- vb.net - 如何在不同计算机之间为 VS 应用程序提供固定的图像尺寸
- unit-testing - JEST 不会触发模拟函数 Vue js
- kubernetes - 如何使用多个命令运行 pod 并在之后使用 kubectl 保持交互式 shell?
- scala - 有效地搜索序列序列以进行单个首次匹配
- visual-studio - 在 Visual C++ 中设置植物
- xml - XSLT。复制节点并修改名称匹配变量值的子节点
- javascript - 使用反引号,在多行中编写代码,但仍然在同一行打印字符串
- symfony - 与现有实体的多对一关系