Размещение нескольких заказов с помощью API Betfair - PullRequest
0 голосов
/ 16 марта 2019

Я использую API Betfair и хотел бы сделать несколько ставок на идентификатор выбора и ставки с размером, который хранится в фрейме данных.

Вот пример типа фрейма данных, который я использую:

import pandas as pd

data = {'selectionId': [8567238,7450487,12787737,9541421,10162696,7208966,8826166,7256678],

 'Price': [4.1,4.6,5.5,7.2,7.8,17.0,32.0,34.0],

 'Win_Percentage': [0.245870,0.212396,0.178922,0.145448,0.111974,0.078501,0.045027,0.011553],

  'Fit':[0.245870,0.212396,0.178922,0.145448,0.111974,0.078501,0.045027,0.011553],

   'size':[2.708701,2.373962,2.039223,1.704484,1.369744,1.035005,0.700266,0.365527]}

df = pd.DataFrame(data, columns=['selectionId', 'Price', 'Win_Percentage','Fit','size'])

Я хочу передать столбец selectionId и size следующей функции:

def placeFailingBet(marketId, selectionId, size):
    if( marketId is not None and selectionId is not None):
        print ('Calling placeOrder for marketId :' + marketId + ' with selection id :' + str(selectionId))
        place_order_Req = '{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/placeOrders", "params": {"marketId":"' + marketId + '","instructions":'\
                                                                                                                              '[{"selectionId":"' + str(
            selectionId) + '","handicap":"0","side":"BACK","orderType":"LIMIT","limitOrder":{"size":' \
                      + str(size) + ',"price":"1.50","persistenceType":"LAPSE"}}],"customerRef":"test12121212121"}, "id": 1}'
        """
print(place_order_Req)
"""
        place_order_Response = callAping(place_order_Req)
        place_order_load = json.loads(place_order_Response)
        try:
            place_order_result = place_order_load['result']
            print ('Place order status is ' + place_order_result['status'])
            """
print('Place order error status is ' + place_order_result['errorCode'])
"""
            print ('Reason for Place order failure is ' + place_order_result['instructionReports'][0]['errorCode'])
        except:
            print ('Exception from API-NG' + str(place_order_result['error']))
        """
print(place_order_Response)
"""


url = "https://api.betfair.com/exchange/betting/json-rpc/v1"

"""
headers = { 'X-Application' : 'xxxxxx', 'X-Authentication' : 'xxxxx' ,'content-type' : 'application/json' }
"""

args = len(sys.argv)

if ( args < 3):
    print ('Please provide Application key and session token')
    appKey = input('Enter your application key :')
    sessionToken = input('Enter your session Token/SSOID :')
    print ('Thanks for the input provided')
else:
    appKey = sys.argv[1]
    sessionToken = sys.argv[2]

headers = {'X-Application': appKey, 'X-Authentication': sessionToken, 'content-type': 'application/json'}

eventTypesResult = getEventTypes()
horseRacingEventTypeID = getEventTypeIDForEventTypeName(eventTypesResult, 'Horse Racing')

print ('Eventype Id for Horse Racing is :' + str(horseRacingEventTypeID))

marketCatalogueResult = getMarketCatalogueForNextGBWin(horseRacingEventTypeID)
marketid = getMarketId(marketCatalogueResult)
runnerId = getSelectionId(marketCatalogueResult)
"""
print(marketid)
print(runnerId)
"""
market_book_result = getMarketBookBestOffers(marketid)

Для этого я вызываю функцию следующим образом:

marketId = 1.156196455
size = df['size'].astype(str)
size = '"' + size + '"'
size = size

for i, j in itertools.product(size, selectionId):

    placeFailingBet(marketId = marketId, selectionId = j, size = i)

Это работает для первой строки, но все остальные строки по какой-то причине не работают.

...