Refactor: main.py is more legible
This commit is contained in:
11
logic.py
11
logic.py
@@ -1,6 +1,7 @@
|
|||||||
from typing import Iterable, Generator
|
from typing import Iterable, Generator
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
@@ -92,3 +93,13 @@ def process_data(matches: Iterable, include_started_matches: bool = True) -> Gen
|
|||||||
"best_outcome_odds": best_odd_per_outcome,
|
"best_outcome_odds": best_odd_per_outcome,
|
||||||
"total_implied_odds": total_implied_odds,
|
"total_implied_odds": total_implied_odds,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_arbitrage_opportunities(key: str, region: str, cutoff: float):
|
||||||
|
sports = get_sports(key)
|
||||||
|
data = chain.from_iterable(get_data(key, sport, region=region) for sport in sports)
|
||||||
|
data = filter(lambda x: x != "message", data)
|
||||||
|
results = process_data(data)
|
||||||
|
arbitrage_opportunities = filter(lambda x: 0 < x["total_implied_odds"] < 1-cutoff, results)
|
||||||
|
|
||||||
|
return arbitrage_opportunities
|
||||||
10
main.py
10
main.py
@@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
The tool fetches the odds from The Odds API (https://the-odds-api.com/) and compares the odds at different
|
The tool fetches the odds from The Odds API (https://the-odds-api.com/) and compares the odds at different
|
||||||
bookmakers to each other in order to determine whether there are profitable and risk-free bets available."""
|
bookmakers to each other in order to determine whether there are profitable and risk-free bets available."""
|
||||||
from logic import *
|
from logic import get_arbitrage_opportunities
|
||||||
import os
|
import os
|
||||||
from itertools import chain
|
|
||||||
import argparse
|
import argparse
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from rich import print
|
from rich import print
|
||||||
@@ -46,12 +45,7 @@ def main():
|
|||||||
print_unformatted = args.unformatted
|
print_unformatted = args.unformatted
|
||||||
cutoff = args.cutoff/100
|
cutoff = args.cutoff/100
|
||||||
|
|
||||||
# logic
|
arbitrage_opportunities = get_arbitrage_opportunities(key, region, cutoff)
|
||||||
sports = get_sports(key)
|
|
||||||
data = chain.from_iterable(get_data(key, sport, region=region) for sport in sports)
|
|
||||||
data = filter(lambda x: x != "message", data)
|
|
||||||
results = process_data(data)
|
|
||||||
arbitrage_opportunities = filter(lambda x: 0 < x["total_implied_odds"] < 1-cutoff, results)
|
|
||||||
|
|
||||||
if print_unformatted:
|
if print_unformatted:
|
||||||
print(list(arbitrage_opportunities))
|
print(list(arbitrage_opportunities))
|
||||||
|
|||||||
Reference in New Issue
Block a user