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()C:\Users\holt1\Desktop\V4 Database Python Code>Gauto.py
2026-03-24 22:49:26,004 [INFO] Starting apply_coupon_and_rules.py (DRY_RUN=False)
2026-03-24 22:49:26,005 [INFO] Applying coupon 'Todays_Horses'...
2026-03-24 22:49:26,315 [INFO] Coupon apply succeeded (or dry-run).
2026-03-24 22:49:26,316 [INFO] Waiting 20 seconds for Guardian to populate markets...
2026-03-24 22:49:46,331 [INFO] Attempting apply-to-all for 'V6 Last Traded Price' -> guardianRulesColumn=1
2026-03-24 22:49:46,346 [INFO] Apply-to-all succeeded for 'V6 Last Traded Price' column 1.
2026-03-24 22:49:46,347 [INFO] Attempting apply-to-all for 'V3 Back Hcap Flat Lay Hrd' -> guardianRulesColumn=2
2026-03-24 22:49:46,364 [INFO] Apply-to-all succeeded for 'V3 Back Hcap Flat Lay Hrd' column 2.
2026-03-24 22:49:46,366 [INFO] Finished apply_coupon_and_rules.py
Success thanks guys
2026-03-24 22:49:26,004 [INFO] Starting apply_coupon_and_rules.py (DRY_RUN=False)
2026-03-24 22:49:26,005 [INFO] Applying coupon 'Todays_Horses'...
2026-03-24 22:49:26,315 [INFO] Coupon apply succeeded (or dry-run).
2026-03-24 22:49:26,316 [INFO] Waiting 20 seconds for Guardian to populate markets...
2026-03-24 22:49:46,331 [INFO] Attempting apply-to-all for 'V6 Last Traded Price' -> guardianRulesColumn=1
2026-03-24 22:49:46,346 [INFO] Apply-to-all succeeded for 'V6 Last Traded Price' column 1.
2026-03-24 22:49:46,347 [INFO] Attempting apply-to-all for 'V3 Back Hcap Flat Lay Hrd' -> guardianRulesColumn=2
2026-03-24 22:49:46,364 [INFO] Apply-to-all succeeded for 'V3 Back Hcap Flat Lay Hrd' column 2.
2026-03-24 22:49:46,366 [INFO] Finished apply_coupon_and_rules.py
Success thanks guys
I can do that if Peter doesn't chip in.
The answer will depend on what you are trying to achieve. Are you looking at multiple sports with multiple baf's to apply ? It's easy enough to achieve on the same device, using MARKET_TYPE to separate out by sport. Just run each script in it's own console\cmd window.
if you get clever with it you can even green 2 different entries in the same market and keep your strategies independent
