...
Code Block | ||
---|---|---|
| ||
URL = url = "https://beta-api.betfair.com/json-rpc"
jsonrpc_req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEventTypes", "params": {"filter":{ }}, "id": 1}'
headers = {'X-Application': appKey, 'X-Authentication': sessionToken, 'content-type': 'application/json'}
def callAping(jsonrpc_req):
try:
req = urllib2.Request(url, jsonrpc_req, headers)
response = urllib2.urlopen(req)
jsonResponse = response.read()
return jsonResponse
except urllib2.URLError:
print 'Oops no service available at ' + str(url)
exit()
except urllib2.HTTPError:
print 'Oops not a valid operation from the service ' + str(url)
exit() |
...
Code Block | ||
---|---|---|
| ||
url = 'https://beta-api.betfair.com/rest/v1.0/${operationName}/'
headers = {'X-Application': appKey, 'X-Authentication': sessionToken, 'content-type': 'application/json', 'accept': 'application/json'}
request = '{"filter":{"eventTypeIds":["7"],"marketCountries":["GB"],"marketStartTime":{"from":"2013-05-21T00:00:00Z"}},"sort":"FIRST_TO_START","maxResults":"1","marketProjection":["RUNNER_METADATA"]}'
def callAping(url, request):
try:
req = urllib2.Request(url, request, headers)
response = urllib2.urlopen(req)
jsonResponse = response.read()
return jsonResponse
except urllib2.URLError:
print 'Oops there is some issue with the request'
exit()
except urllib2.HTTPError:
print 'Oops there is some issue with the request' + urllib2.HTTPError.getcode()
exit() |
...
Code Block | ||
---|---|---|
| ||
def getMarketCatalouge(eventTypeID):
if(eventTypeID is not None):
print 'Calling listMarketCatalouge Operation to get MarketID and selectionId'
endPoint = 'https://beta-api.betfair.com/rest/v1.0/listMarketCatalogue/'
now = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
market_catalouge_req = '{"filter":{"eventTypeIds":["' + eventTypeID + '"],"marketCountries":["GB"],"marketStartTime":{"from":"' + now + '"}},"sort":"FIRST_TO_START","maxResults":"1","marketProjection":["RUNNER_METADATA"]}'
market_catalouge_response = callAping(endPoint, market_catalouge_req)
market_catalouge_loads = json.loads(market_catalouge_response)
return market_catalouge_loads
def getMarketId(marketCatalougeResult):
if(marketCatalougeResult is not None):
for market in marketCatalougeResult:
return market['marketId']
def getSelectionId(marketCatalougeResult):
if(marketCatalougeResult is not None):
for market in marketCatalougeResult:
return market['runners'][0]['selectionId']
marketCatalougeResult = getMarketCatalouge(horseRacingEventTypeID)
marketid = getMarketId(marketCatalougeResult)
runnerId = getSelectionId(marketCatalougeResult) |
...
Code Block | ||
---|---|---|
| ||
def getMarketBook(marketId):
if( marketId is not None):
print 'Calling listMarketBook to read prices for the Market with ID :' + marketId
market_book_req = '{"marketIds":["' + marketId + '"],"priceProjection":{"priceData":["EX_BEST_OFFERS"]}}'
endPoint = 'https://beta-api.betfair.com/rest/v1.0/listMarketBook/'
market_book_response = callAping(endPoint, market_book_req)
market_book_loads = json.loads(market_book_response)
return market_book_loads
def printPriceInfo(market_book_result):
print 'Please find Best three available prices for the runners'
for marketBook in market_book_result:
try:
runners = marketBook['runners']
for runner in runners:
print 'Selection id is ' + str(runner['selectionId'])
if (runner['status'] == 'ACTIVE'):
print 'Available to back price :' + str(runner['ex']['availableToBack'])
print 'Available to lay price :' + str(runner['ex']['availableToLay'])
else:
print 'This runner is not active'
except:
print 'No runners available for this market'
market_book_result = getMarketBook(marketid)
printPriceInfo(market_book_result) |
...