Betangel API - "quick bet"

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
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

Hi

Is it possible to run a code in python that would connect to your brand new feature, BA API that would:
A) go to a certain market
B) to pop up a certain selection in "quick bet" window ?

The markets would have already been loaded up in Guardian before connecting to the API.

If its NOT possible at the mo, then:
How could i connect to the api to get an info about a certain selection and its odds ?
sniffer66
Posts: 1680
Joined: Thu May 02, 2019 8:37 am

Popping up a quick bet window isn't possible as the API stands. However, putting in a Suggestion may mean it would be included in the future. I have a few ideas for moving the API on so will be putting some in myself.

Getting the odds of a selection is slightly convoluted as is but possible. You can only pull SV's for a selection but if you have the current odds saved as an SV via the applied baf it's doable

First you'll need to retrieve the Markets and Selections via an API call, then parse the returned JSON to get the selections ID. Then run another call to the API to return the SV's and values for that selection ID

I use Auto-It, rather than Python, using WINHTTP to retrieve the JSON, but the equivalent is just as easy in Python
Posted my code, which should give you a starter for 10. This would return the list of markets and their ID's in Guardian in "$Result"

Code: Select all


$Result = Post_to_BA("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE"]}')

Func Post_to_BA($sEndpoint, $sRaw_JSON)
    Local $oHttp   = Null, _
          $oComErr = Null

    Local $iHttpStatus = 0

    Local $sResponse = "", _
          $sPostData = ""

    ;Create a HTTP COM object
    $oHttp = ObjCreate("winhttp.winhttprequest.5.1")

    With $oHttp
        ;Open POST request
        .Open("POST", $sEndpoint, False)

        ;Set request headers and options
        .SetRequestHeader("Content-Type", "application/json")

        ;Send request
        .Send($sRaw_JSON)

        ;Get status code and response
        $iHttpStatus = .Status
        $sResponse   = .ResponseText
    EndWith
	Return($sResponse)

EndFunc

User avatar
Euler
Posts: 24813
Joined: Wed Nov 10, 2010 1:39 pm
Location: Bet Angel HQ

We are happy to take suggestions for the API going forward. This first version of the API was just to ensure we get the based level in place before expanding it.
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

sniffer66 wrote:
Fri Dec 23, 2022 9:40 am
Popping up a quick bet window isn't possible as the API stands. However, putting in a Suggestion may mean it would be included in the future. I have a few ideas for moving the API on so will be putting some in myself.

Getting the odds of a selection is slightly convoluted as is but possible. You can only pull SV's for a selection but if you have the current odds saved as an SV via the applied baf it's doable

First you'll need to retrieve the Markets and Selections via an API call, then parse the returned JSON to get the selections ID. Then run another call to the API to return the SV's and values for that selection ID

I use Auto-It, rather than Python, using WINHTTP to retrieve the JSON, but the equivalent is just as easy in Python
Posted my code, which should give you a starter for 10. This would return the list of markets and their ID's in Guardian in "$Result"

Code: Select all


$Result = Post_to_BA("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE"]}')

Func Post_to_BA($sEndpoint, $sRaw_JSON)
    Local $oHttp   = Null, _
          $oComErr = Null

    Local $iHttpStatus = 0

    Local $sResponse = "", _
          $sPostData = ""

    ;Create a HTTP COM object
    $oHttp = ObjCreate("winhttp.winhttprequest.5.1")

    With $oHttp
        ;Open POST request
        .Open("POST", $sEndpoint, False)

        ;Set request headers and options
        .SetRequestHeader("Content-Type", "application/json")

        ;Send request
        .Send($sRaw_JSON)

        ;Get status code and response
        $iHttpStatus = .Status
        $sResponse   = .ResponseText
    EndWith
	Return($sResponse)

EndFunc

Superb ! Thanks sniffer66 !
Im new to Python but i did manage to convert your code.
This is what i get:

{"status":"OK","result":{"markets":[{"id":"1.207933312","name":"Monmore 23rd Dec - 15:11 A1 480m","marketType":"WIN","eventId":"31982905_15:11","eventTypeId":"4339","startTime":"2022-12-23T15:11:00+00:00"}]}}

I had only 1 market loaded up in guardian however I dont receive "selection names" for some reason...


PS:Disregard the one about selection names. Just noticed i didnt request it hence no selection name.
So now i need a ba bot that will scan each and every market and selections ?
Once i got that how to read the odds of a needed selection in python ?
Last edited by ilovepizza82 on Fri Dec 23, 2022 3:23 pm, edited 1 time in total.
sniffer66
Posts: 1680
Joined: Thu May 02, 2019 8:37 am

ilovepizza82 wrote:
Fri Dec 23, 2022 3:16 pm
sniffer66 wrote:
Fri Dec 23, 2022 9:40 am
Popping up a quick bet window isn't possible as the API stands. However, putting in a Suggestion may mean it would be included in the future. I have a few ideas for moving the API on so will be putting some in myself.

Getting the odds of a selection is slightly convoluted as is but possible. You can only pull SV's for a selection but if you have the current odds saved as an SV via the applied baf it's doable

First you'll need to retrieve the Markets and Selections via an API call, then parse the returned JSON to get the selections ID. Then run another call to the API to return the SV's and values for that selection ID

I use Auto-It, rather than Python, using WINHTTP to retrieve the JSON, but the equivalent is just as easy in Python
Posted my code, which should give you a starter for 10. This would return the list of markets and their ID's in Guardian in "$Result"

Code: Select all


$Result = Post_to_BA("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE"]}')

Func Post_to_BA($sEndpoint, $sRaw_JSON)
    Local $oHttp   = Null, _
          $oComErr = Null

    Local $iHttpStatus = 0

    Local $sResponse = "", _
          $sPostData = ""

    ;Create a HTTP COM object
    $oHttp = ObjCreate("winhttp.winhttprequest.5.1")

    With $oHttp
        ;Open POST request
        .Open("POST", $sEndpoint, False)

        ;Set request headers and options
        .SetRequestHeader("Content-Type", "application/json")

        ;Send request
        .Send($sRaw_JSON)

        ;Get status code and response
        $iHttpStatus = .Status
        $sResponse   = .ResponseText
    EndWith
	Return($sResponse)

EndFunc

Superb ! Thanks sniffer66 !
Im new to Python but i did manage to convert your code.
This is what i get:

{"status":"OK","result":{"markets":[{"id":"1.207933312","name":"Monmore 23rd Dec - 15:11 A1 480m","marketType":"WIN","eventId":"31982905_15:11","eventTypeId":"4339","startTime":"2022-12-23T15:11:00+00:00"}]}}

I had only 1 market loaded up in guardian however I dont receive "selection names" for some reason...
Ah sorry, I just showed Markets only as a test. if you go to the API test page from BA settings. use the API test drop down to select Markets AND Selections, sub the endpoint and JSON in as provided below and edit your code to suit. The test page will show you all the endpoints and JOSDN strings you need

Once you had the selection ID, use the test page to get the corresponding endpoint/JSON to return SV's for the selection ID you require
Last edited by sniffer66 on Fri Dec 23, 2022 3:27 pm, edited 1 time in total.
sniffer66
Posts: 1680
Joined: Thu May 02, 2019 8:37 am

Then set up a BAF to apply to all your markets that saves current price as an SV every refresh cycle, for each runner. Then query that Selection ID(s) for its SV's. That will return the current price
sniffer66
Posts: 1680
Joined: Thu May 02, 2019 8:37 am

sniffer66 wrote:
Fri Dec 23, 2022 3:26 pm
Then set up a BAF to apply to all your markets that saves current price as an SV every refresh cycle, for each runner. Then query that Selection ID(s) for its SV's. That will return the current price
I've not tried this as yet btw, but in theory it should work, albeit with an inherent delay
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

Thanks. Im struggling a bit so I guess Ill wait till they implement ODDS.
Im surprised they didnt do it from the very start tho, one the most important things there :)
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

Not sure whats wrong with this code.
If anyone could help...Python newbie here.
Basically what i want is, once entered a name of a selection id like to see its ID.

Code: Select all

import json
import requests

def post_to_ba(endpoint, raw_json):
    headers = {'Content-Type': 'application/json'}
    response = requests.post(endpoint, data=raw_json, headers=headers)
    return response.text

# Prompt the user for the data to search for
data = input("Enter the data to search for: ")

# Make the request and store the response in a variable
response_text = post_to_ba("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES"]}')

# Parse the response text as JSON
response_json = json.loads(response_text)

# Search for the data in the response JSON object
if data in response_json:
    print(f"ID for {data}: {response_json[data]}")
else:
    print(f"{data} not found in the response JSON.")
You do not have the required permissions to view the files attached to this post.
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

ilovepizza82 wrote:
Tue Dec 27, 2022 3:56 pm
Not sure whats wrong with this code.
If anyone could help...Python newbie here.
Basically what i want is, once entered a name of a selection id like to see its ID.

Code: Select all

import json
import requests

def post_to_ba(endpoint, raw_json):
    headers = {'Content-Type': 'application/json'}
    response = requests.post(endpoint, data=raw_json, headers=headers)
    return response.text

# Prompt the user for the data to search for
data = input("Enter the data to search for: ")

# Make the request and store the response in a variable
response_text = post_to_ba("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES"]}')

# Parse the response text as JSON
response_json = json.loads(response_text)

# Search for the data in the response JSON object
if data in response_json:
    print(f"ID for {data}: {response_json[data]}")
else:
    print(f"{data} not found in the response JSON.")
Try this, Im still learning too, so there maybe a better way?

Code: Select all

import json
import requests

def post_to_ba(endpoint, raw_json):
    headers = {'Content-Type': 'application/json'}
    response = requests.post(endpoint, data=raw_json, headers=headers)
    return response.text

# Prompt the user for the selection name
selection_name = input("Enter the selection name you require the ID for: ")

# Make the request and store the response in a variable
response = post_to_ba("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES"]}')

# Parse the response text as JSON
response_json = json.loads(response)
print(response_json)

selections = response_json['result']['markets'][0]['selections']

# Search for the selection
for selection in selections:
    if selection['name'] == selection_name:
        selection_id = selection['id']
        print(f"Selection ID for {selection_name}: {selection_id}")
        break
else:
    print(f"{selection_name}, not found in the list of selections.")
   
  
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

PeterLe wrote:
Thu Dec 29, 2022 12:34 pm
ilovepizza82 wrote:
Tue Dec 27, 2022 3:56 pm
Not sure whats wrong with this code.
If anyone could help...Python newbie here.
Basically what i want is, once entered a name of a selection id like to see its ID.

Code: Select all

import json
import requests

def post_to_ba(endpoint, raw_json):
    headers = {'Content-Type': 'application/json'}
    response = requests.post(endpoint, data=raw_json, headers=headers)
    return response.text

# Prompt the user for the data to search for
data = input("Enter the data to search for: ")

# Make the request and store the response in a variable
response_text = post_to_ba("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES"]}')

# Parse the response text as JSON
response_json = json.loads(response_text)

# Search for the data in the response JSON object
if data in response_json:
    print(f"ID for {data}: {response_json[data]}")
else:
    print(f"{data} not found in the response JSON.")
Try this, Im still learning too, so there maybe a better way?

Code: Select all

import json
import requests

def post_to_ba(endpoint, raw_json):
    headers = {'Content-Type': 'application/json'}
    response = requests.post(endpoint, data=raw_json, headers=headers)
    return response.text

# Prompt the user for the selection name
selection_name = input("Enter the selection name you require the ID for: ")

# Make the request and store the response in a variable
response = post_to_ba("http://localhost:9000/api/markets/v1.0/getMarkets", '{"dataRequired":["ID","NAME","MARKET_START_TIME","EVENT_ID","EVENT_TYPE_ID","MARKET_TYPE","SELECTION_IDS","SELECTION_NAMES"]}')

# Parse the response text as JSON
response_json = json.loads(response)
print(response_json)

selections = response_json['result']['markets'][0]['selections']

# Search for the selection
for selection in selections:
    if selection['name'] == selection_name:
        selection_id = selection['id']
        print(f"Selection ID for {selection_name}: {selection_id}")
        break
else:
    print(f"{selection_name}, not found in the list of selections.")
   
  
HI PeterLe,

Ive just tried that and whatever you enter there it says "..not found in the list of selections." while at the same time it lists all of the races, all of the results found in guardian it seems
Ive literally spent 4-5 days working on this trying all different kind of things and I just cant figure it out, for real :D
At least I managed to learn that these are "dictionary" type of data/values LOL
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

This is what it looks like from Pycharm...using Thunderosa as a selection example
Yes ive spent many an hour trying to solve simple things, but its the best way of learning ive found :D
You do not have the required permissions to view the files attached to this post.
User avatar
Euler
Posts: 24813
Joined: Wed Nov 10, 2010 1:39 pm
Location: Bet Angel HQ

I've added a dedicated forum area for people to share and discuss code for the API.

I'll expand as necessary going forward.
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

PeterLe wrote:
Thu Dec 29, 2022 1:16 pm
This is what it looks like from Pycharm...using Thunderosa as a selection example
Yes ive spent many an hour trying to solve simple things, but its the best way of learning ive found :D
Im using "Spyder" / Anaconda.
Dont know why it doesnt work for me. Very strange.
Euler wrote:
Thu Dec 29, 2022 1:28 pm
I've added a dedicated forum area for people to share and discuss code for the API.

I'll expand as necessary going forward.
Thanks Peter!
You do not have the required permissions to view the files attached to this post.
User avatar
ilovepizza82
Posts: 494
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

Ok so I ve just tried it again for a runner called "Hiatus" and it worked,
HOWEVER
when i enter "Hiya Hiya" it can't find it 4 some reason.
Could you try it too PeterLe ?
Maybe the problem is if there is "space".

PS: Ive tried it also in Pycharm and its the same problem.
PS2: Tried a runner "Pysanka" and it didn't work. lol very strange but it does work when entering "Hiatus". lol
PS3: Its not "space" char problem. Worked when entered "Direct Hit" for race at 17:00
Post Reply

Return to “Bet Angel - API”