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
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

I just tried it on a selection that has a space = Inis Oirr and that worked OK
Im not sure what the issue at the mo?
You do not have the required permissions to view the files attached to this post.
LinusP
Posts: 1871
Joined: Mon Jul 02, 2012 10:45 pm

ilovepizza82 wrote:
Thu Dec 29, 2022 4:42 pm
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
The code only looks in the first market returned (selections= line), could that be the issue?

Code: Select all

# search for the selection in ALL markets
for market in response_json[‘result’][‘markets’]:
    for selection in market[‘selections’]:
        # do somin 
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

Thanks Liam

code changed to this :

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.")

# search for the selection in ALL markets
for market in response_json['result']['markets']:
    for selection in market['selections']:
        if selection['name'] == selection_name:
            selection_id = selection['id']
            print(f"Selection ID for {selection_name}: {selection_id}")
            break
    else:
        continue
    break
else:
    print(f"{selection_name}, not found in the list of selections.")
    
and tested a couple of examples..looks OK 'ilovepizza' if you want to give it a try?
Again, it may not be the best example of coding :D


regards
Peter
APIexample.PNG
You do not have the required permissions to view the files attached to this post.
User avatar
ilovepizza82
Posts: 490
Joined: Thu Nov 02, 2017 3:41 pm
Location: Sewers
Contact:

PeterLe wrote:
Fri Dec 30, 2022 10:16 pm
Thanks Liam

code changed to this :

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.")

# search for the selection in ALL markets
for market in response_json['result']['markets']:
    for selection in market['selections']:
        if selection['name'] == selection_name:
            selection_id = selection['id']
            print(f"Selection ID for {selection_name}: {selection_id}")
            break
    else:
        continue
    break
else:
    print(f"{selection_name}, not found in the list of selections.")
    
and tested a couple of examples..looks OK 'ilovepizza' if you want to give it a try?
Again, it may not be the best example of coding :D


regards
Peter
APIexample.PNG
Its alive....ALIVE !
Absolutely sweet ! Thanks Peter and LIam !
Now hopefully @Euler will implement ODDS in the nearest time ! ;)

Ive been trying to find a work-around (and partially failing at the mo) by using BA active spreadsheet with selectoins and odds coz Id thought id already used all known python techniques and i used quite a few tbh LOL but being a beginner I missed some other things so yeah :D
You guys rock !

I modified Peter's code slightly so you dont have to enter the whole name of a runner anymore. ALl you need is at least first part of the name.
HappY New YeaR !

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)

# Initialize an empty list to store the matching selection names and IDs
matching_selections = []

# Search for the selection in ALL markets
for market in response_json['result']['markets']:
    for selection in market['selections']:
        if selection['name'].startswith(selection_name):
            matching_selections.append({'name': selection['name'], 'id': selection['id']})

# Print the name and ID of each matching selection
if matching_selections:
    for selection in matching_selections:
        print(f"Selection name: {selection['name']}, Selection ID: {selection['id']}")
else:
    print(f"No selections found with names starting with {selection_name}.")
Post Reply

Return to “Bet Angel - API”