Hi
Does anyone have a Python code to automatically add automation rules to Guardian ?
Thanks in advance
Automation With Python
You want to add a new rule or apply an existing rule to a number of markets ?
If it's the latter, these 2 funcs will get you started.
If it's the latter, these 2 funcs will get you started.
Code: Select all
def apply_rules(self, market_ids):
url = f"{self.base_url}guardian/v1.0/applyRules"
payload = {
"rulesFileName": "Log Winner",
"marketsFilter": {"filter": "SPECIFIED_IDS", "ids": market_ids},
"guardianRulesColumn": 1
}
try:
r = requests.post(url, headers=self.headers, json=payload)
r.raise_for_status()
logger.info(f"Rules applied: {r.json()}")
except requests.RequestException as e:
logger.error(f"Error applying rules: {e}")
-
def get_markets(self, data_required: Optional[List[str]] = None) -> Dict[str, Any]:
if data_required is None:
data_required = [
"ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID", # Ensure EVENT_ID is requested
"MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES","SELECTIONS","START_TIME"
]
url = f"{self.base_url}markets/v1.0/getMarkets"
r = requests.post(url, headers=self.headers, json={"dataRequired": data_required}, timeout=20)
r.raise_for_status()
return r.json()