-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazuro_executor.py
More file actions
66 lines (61 loc) · 2.76 KB
/
Copy pathazuro_executor.py
File metadata and controls
66 lines (61 loc) · 2.76 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Azuro executor: place bets for entries that have _azuro_outcome set.
Uses azuro_relayer.place_bet; stake = unit_dollars * unit_map[colour].
"""
from __future__ import annotations
import logging
from typing import Any
import azuro_relayer
logger = logging.getLogger(__name__)
def execute_small_for_entries(
entries: list[dict],
colours: list[str],
unit_dollars: float,
unit_map: dict[str, float],
dry_run: bool = False,
) -> tuple[bool, str | None]:
"""
For each entry with _azuro_outcome, place one ordinar bet.
colours[i] = "GREEN"|"YELLOW"|"RED" for entries[i].
stake = unit_dollars * unit_map[colour]; default unit_map e.g. {"GREEN": 3.0, "YELLOW": 2.0, "RED": 0.5}.
Returns (placed: bool, order_id: str | None). order_id is the last placed order ID if any.
"""
if not entries or not colours:
return (False, None)
placed = False
order_id: str | None = None
for i, entry in enumerate(entries):
outcome = entry.get("_azuro_outcome")
if not outcome:
continue
colour = colours[i] if i < len(colours) else "GREEN"
coef = unit_map.get(colour) if isinstance(unit_map, dict) else 1.0
if coef is None or coef <= 0:
coef = 1.0
stake = unit_dollars * float(coef)
try:
condition_id = getattr(outcome, "market_id", None) or (outcome.get("market_id") if isinstance(outcome, dict) else None)
outcome_id = getattr(outcome, "outcome_id", None) or (outcome.get("outcome_id") if isinstance(outcome, dict) else None)
odds_decimal = getattr(outcome, "odds", None) or (outcome.get("odds") if isinstance(outcome, dict) else None)
if not condition_id or outcome_id is None or odds_decimal is None:
logger.warning("Executor: entry missing market_id/outcome_id/odds")
continue
result = azuro_relayer.place_bet(
condition_id=str(condition_id),
outcome_id=int(outcome_id),
odds_decimal=float(odds_decimal),
amount_usd=stake,
dry_run=dry_run,
)
if result is not None:
placed = True
order_id = result.get("order_id")
if dry_run:
logger.info("Executor: dry run would place %s USDT on %s / %s", stake, condition_id, outcome_id)
else:
logger.info("Executor: placed %s USDT on %s / %s -> %s", stake, condition_id, outcome_id, result.get("order_id"))
else:
logger.warning("Executor: place_bet returned None for entry %s", i)
except Exception as e:
logger.exception("Executor: error placing bet for entry %s: %s", i, e)
return (placed, order_id)