Automation With Python

The Bet Angel API makes it easy for you to further enhance your betting and trading by integrating your own code into Bet Angel
Post Reply
Diginet
Posts: 124
Joined: Tue Jul 09, 2013 1:43 pm

Hi

Does anyone have a Python code to automatically add automation rules to Guardian ?

Thanks in advance
User avatar
Euler
Posts: 27015
Joined: Wed Nov 10, 2010 1:39 pm

Check out the Bet Angel API section of the forum.
sniffer66
Posts: 1890
Joined: Thu May 02, 2019 8:37 am

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.

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()
Diginet
Posts: 124
Joined: Tue Jul 09, 2013 1:43 pm

Hi

Thank you for all your help. I have the code to add markets to a Coupon then into Guardian. I was looking to then add my automation rules to those markets added

Cheers
sniffer66
Posts: 1890
Joined: Thu May 02, 2019 8:37 am

So use the apply_rules func I posted then :)
Diginet
Posts: 124
Joined: Tue Jul 09, 2013 1:43 pm

Perfect thank you
Diginet
Posts: 124
Joined: Tue Jul 09, 2013 1:43 pm

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 :D
Post Reply

Return to “Bet Angel - API”