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
Hi,sniffer66 wrote: ↑Wed Mar 25, 2026 11:34 amI 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
Yes, multiple sports with multiple bafs. Will the script just apply the different rules and markets in the same Guardian window or does in need separate ones. As a random example Rules for :-
- Horse Racing
Tennis
Footbal
Assuming one baf per sport for simplicity. It will be one Guardian window, using 3 configured coupons - one for each sport. use the code I gave you before to load each coupon in turn, then apply the rules, again using the same code in turn, specifying the EventType id to apply to:Diginet wrote: ↑Wed Mar 25, 2026 12:49 pmHi,sniffer66 wrote: ↑Wed Mar 25, 2026 11:34 amI 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
Yes, multiple sports with multiple bafs. Will the script just apply the different rules and markets in the same Guardian window or does in need separate ones. As a random example Rules for :-
- Horse Racing
Tennis
Footbal
EventType: 468328 / EventName: Handball
EventType: 1 / EventName: Soccer
EventType: 2 / EventName: Tennis
EventType: 3 / EventName: Golf
EventType: 4 / EventName: Cricket
EventType: 5 / EventName: Rugby Union
EventType: 6 / EventName: Boxing
EventType: 8 / EventName: Motor Sport
EventType: 7524 / EventName: Ice Hockey
EventType: 10 / EventName: Special Bets
EventType: 451485 / EventName: Winter Sports
EventType: 11 / EventName: Cycling
EventType: 136332 / EventName: Chess
EventType: 7522 / EventName: Basketball
EventType: 1477 / EventName: Rugby League
EventType: 4339 / EventName: Greyhound Racing
EventType: 6231 / EventName: Financial Bets
EventType: 2378961 / EventName: Politics
EventType: 998917 / EventName: Volleyball
EventType: 998918 / EventName: Bowls
EventType: 26420387 / EventName: Mixed Martial Arts
EventType: 3503 / EventName: Darts
EventType: 72382 / EventName: Pool
EventType: 2152880 / EventName: Gaelic Games
EventType: 6422 / EventName: Snooker
EventType: 6423 / EventName: American Football
EventType: 315220 / EventName: Poker
EventType: 7511 / EventName: Baseball
(It's not listed here but 7 is Horses)
For the first application of rules you want to set "Clear Guardian and Watch List" and apply to Watch List 1. For further sports, obviously don't clear Guardian but apply to watch list numbers in sequence. You will end up with a single Guardian Window with all your sports and corresponding rules applied, and a separate Watch List per sport
I've assumed you won't have so many markets that you have issues with streaming (1000 limit), otherwise you'll need multiple BA instances. But I went for simple to start with
