I have been digging deeper into the Betfair api and it is possible to get the Near price which is the price if the race was to start at that very moment. The code required is:
def getMarketBookBestOffers(marketId):
global market_book_result, market_ID
print ('Calling listMarketBook to read prices for the Market with ID :' + marketId)
market_book_req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listMarketBook", "params": {"marketIds":["' + marketId + '"],"priceProjection":{"priceData":["SP_TRADED"]}}, "id": 1}'
"""
print(market_book_req)
"""
market_book_response = callAping(market_book_req)
"""
print(market_book_response)
"""
market_book_loads = json.loads(market_book_response)
try:
market_book_result = market_book_loads['result']
return market_book_result
except:
print ('Exception from API-NG' + str(market_book_result['error']))
exit()
The thing that changes for the market_book_req string is "SP_TRADED".
The closer this code is run to the start of the race the better estimate of the BSP price.
Lay price for equivalent Betfair starting price
If you are using python you should use my library, much easieru18sc11 wrote: ↑Fri Apr 12, 2019 12:04 pmI have been digging deeper into the Betfair api and it is possible to get the Near price which is the price if the race was to start at that very moment. The code required is:
def getMarketBookBestOffers(marketId):
global market_book_result, market_ID
print ('Calling listMarketBook to read prices for the Market with ID :' + marketId)
market_book_req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listMarketBook", "params": {"marketIds":["' + marketId + '"],"priceProjection":{"priceData":["SP_TRADED"]}}, "id": 1}'
"""
print(market_book_req)
"""
market_book_response = callAping(market_book_req)
"""
print(market_book_response)
"""
market_book_loads = json.loads(market_book_response)
try:
market_book_result = market_book_loads['result']
return market_book_result
except:
print ('Exception from API-NG' + str(market_book_result['error']))
exit()
The thing that changes for the market_book_req string is "SP_TRADED".
The closer this code is run to the start of the race the better estimate of the BSP price.
https://github.com/liampauling/betfair