Repository navigation
Expand file tree
/
Copy pathsettle_bets.py
More file actions
49 lines (36 loc) · 1.43 KB
/
Copy pathsettle_bets.py
File metadata and controls
49 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Bet settlement example.
Guide: https://odds-api.io/blog/bet-grading-api
Grades the stored bets in data/bets.json, 50 per request, and keeps the ones
whose result is not final yet so they can be sent again later.
"""
import json
import os
from pathlib import Path
from odds_api import OddsAPIClient
# Settlement needs a paid plan: https://odds-api.io/pricing
API_KEY = os.getenv("ODDS_API_KEY", "your_api_key_here")
BETS_FILE = Path(__file__).parent / "data" / "bets.json"
def main():
bets = json.loads(BETS_FILE.read_text())
open_bets = []
with OddsAPIClient(api_key=API_KEY) as client:
for start in range(0, len(bets), 50):
chunk = bets[start:start + 50]
grades = client.grade_bets(chunk)["grades"]
for bet, grade in zip(chunk, grades):
basis = grade.get("basis") or {}
score = (
f'{basis["home"]}-{basis["away"]} {basis["scope"]}'
if "home" in basis else ""
)
print(
f'{grade["ref"]:<16} {grade["result"]:<12} '
f'{grade["reason"] or "":<20} '
f'final={str(grade["final"]).lower():<6} {score}'
)
if not grade["final"]:
open_bets.append(bet)
print(f"{len(bets) - len(open_bets)} settled, {len(open_bets)} to check again later")
if __name__ == "__main__":
main()