Example #1
0
    def __call__(self, instance, *args, **kwargs):
        '''
        Returns getActiveEventTypes and getEvents in a single call.
        The events returned by getActiveEventTypes are aliased to look like
        an answer from getEvents

        @param instance: object whose method is being called
        @type instance: object (a L{BfApi} subclass)

        @returns: Betfair API answer
        @rtype: parsed answer
        '''
        callArgs = self.kwargs.copy()
        callArgs.update(**kwargs)
        eventParentId = callArgs.get('eventParentId')

        if eventParentId == bfglobals.eventRootId:
            response = instance.getActiveEventTypes()
            # Alias the .id and .name attributes to those of an event
            for event in response.eventTypeItems:
                event.eventTypeId = event.id
                event.eventId = event.id
                del event.id
                event.eventName = event.name
                del event.name

            # Create the eventItems and marketItems alias
            response.eventItems = response.eventTypeItems
            del response.eventTypeItems
            response.marketItems = list()

            return response

        return BfApi.getEvents(instance, eventParentId=eventParentId)
Example #2
0
    def __call__(self, instance, *args, **kwargs):
        '''
        if the parameter nonIPRePlace is passed to the call with a True
        value, bets not placed due to an "INVALID_PERSISTENCE" error
        will be returned

        @param instance: object whose method is being called
        @type instance: object (a L{BfApi} subclass)
        @param args: unnamed args
        @type args: tuple

        @returns: Betfair API answer
        @rtype: parsed answer
        '''
        placeBetsArgs = self.kwargs.copy()
        placeBetsArgs.update(**kwargs)
        nonIPRePlace = placeBetsArgs.pop('_nonIPRePlace')

        response = BfApi.placeBets(instance, *args, **placeBetsArgs)

        if response.betResults and nonIPRePlace:
            placeBets = placeBetsArgs.get('bets')
            toRePlaceBets = list()
            for i, betResult in enumerate(response.betResults[:]):
                placeBet = placeBets[i]
                if betResult.resultCode == 'INVALID_PERSISTENCE' and placeBet.betPersistenceType == 'IP':
                    # This can be a simple copy because placeBet is made of Simple types
                    # newPlaceBet = deepcopy(placeBet)
                    newPlaceBet = copy(placeBet)
                    newPlaceBet.betPersistenceType = 'NONE'
                    toRePlaceBets.append(newPlaceBet)
                    response.betResults.pop(i)

            if toRePlaceBets:
                placeBetsArgs['bets'] = toRePlaceBets
                rePlaceResponse = BfApi.placeBets(instance, *args, **placeBetsArgs)
                response.betResults.extend(rePlaceResponse.betResults)

        return response
Example #3
0
    def __call__(self, instance, *args, **kwargs):
        '''
        Method implementation to allow MU (default also in the call) to be returned

        @param instance: object whose method is being called
        @type instance: object (a L{BfApi} subclass)
        @param args: unnamed args
        @type args: tuple
        @param kwargs: named args
        @type kwargs: dict

        @returns: Betfair API answer
        @rtype: parsed answer
        '''
        currentBetsArgs = self.kwargs.copy()
        currentBetsArgs.update(**kwargs)

        if currentBetsArgs['betStatus'] != 'MU':
            return BfApi.getCurrentBets(instance, *args, **currentBetsArgs)

        currentBetsArgs['betStatus'] = 'M'
        mResponse = BfApi.getCurrentBets(instance, *args, **currentBetsArgs)
        currentBetsArgs['betStatus'] = 'U'
        uResponse = BfApi.getCurrentBets(instance, *args, **currentBetsArgs)

        mResponse.totalRecordCount += uResponse.totalRecordCount
        mResponse.bets.extend(uResponse.bets)

        orderBy = kwargs.get('orderBy', 'NONE')

        if orderBy == 'PLACED_DATE':
            mResponse.bets.sort(key=attrgetter('placedDate', 'betStatus'))
        else:
            # According to the docs the only other combination for M and U is 'NONE'
            # so do a sensible ordering on betId and betStatus
            mResponse.bets.sort(key=attrgetter('betId', 'betStatus'))

        return mResponse
Example #4
0
 def __init__(self, **kwargs):
     BfApi.__init__(self, **kwargs)