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 ?
Betangel API - "quick bet"
- ilovepizza82
- Posts: 506
- Joined: Thu Nov 02, 2017 3:41 pm
- Location: Sewers
- Contact:
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"
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
- ilovepizza82
- Posts: 506
- Joined: Thu Nov 02, 2017 3:41 pm
- Location: Sewers
- Contact:
Superb ! Thanks sniffer66 !sniffer66 wrote: ↑Fri Dec 23, 2022 9:40 amPopping 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
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.
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 needilovepizza82 wrote: ↑Fri Dec 23, 2022 3:16 pmSuperb ! Thanks sniffer66 !sniffer66 wrote: ↑Fri Dec 23, 2022 9:40 amPopping 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
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...
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.
I've not tried this as yet btw, but in theory it should work, albeit with an inherent delay
- ilovepizza82
- Posts: 506
- 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
Im surprised they didnt do it from the very start tho, one the most important things there
- ilovepizza82
- Posts: 506
- 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.
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.
Try this, Im still learning too, so there maybe a better way?ilovepizza82 wrote: ↑Tue Dec 27, 2022 3:56 pmNot 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.")
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.")
- ilovepizza82
- Posts: 506
- Joined: Thu Nov 02, 2017 3:41 pm
- Location: Sewers
- Contact:
HI PeterLe,PeterLe wrote: ↑Thu Dec 29, 2022 12:34 pmTry this, Im still learning too, so there maybe a better way?ilovepizza82 wrote: ↑Tue Dec 27, 2022 3:56 pmNot 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.")
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.")
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
At least I managed to learn that these are "dictionary" type of data/values LOL
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
Yes ive spent many an hour trying to solve simple things, but its the best way of learning ive found
You do not have the required permissions to view the files attached to this post.
- ilovepizza82
- Posts: 506
- Joined: Thu Nov 02, 2017 3:41 pm
- Location: Sewers
- Contact:
Im using "Spyder" / Anaconda.
Dont know why it doesnt work for me. Very strange.
Thanks Peter!
You do not have the required permissions to view the files attached to this post.
- ilovepizza82
- Posts: 506
- 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
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