def betsInMarket(betfairClient, marketId, timeId): global Betstore exchangeId = collectData.Datastore[marketId]['exchange'] initsBetstore(betfairClient, marketId, timeId) initsBetstoreMarket(betfairClient, marketId, timeId) for selectionId in collectData.Datastore[marketId]['selectedRunnerIds']: initsBetstoreSelection(betfairClient, marketId, selectionId, timeId) Betstore[marketId][selectionId]['Records'] = {} try: MUBets = qwertybet.getMUBets(betfairClient, exchangeId, marketId) except Exception, e: stratlogger.exception('Error getting matched, unmatched bets.') raise e
def CurrentLiability(betfairClient, marketId): Liability = 0 Potential = 0 if 'unsettledMarkets' in strategy.Betstore.keys(): for marketId in strategy.Betstore['unsettledMarkets'].keys(): Standing = {} Liability = 0 Potential = 0 exchangeId = strategy.Betstore['unsettledMarkets'][marketId] try: MUBets = qwertybet.getMUBets(betfairClient, exchangeId, marketId) #returns MUBets except Exception, e: settledlogger.exception('Error getting matched, unmatched bets.') raise e if len(MUBets.bets) == 0: del strategy.Betstore['unsettledMarkets'][marketId] continue for bet in MUBets.bets: if bet.selectionId not in Standing.keys(): Standing[bet.selectionId] = {} Standing[bet.selectionId]['totalLayPrice'] = 0 Standing[bet.selectionId]['totalLayVolume'] = 0 Standing[bet.selectionId]['totalBetPrice'] = 0 Standing[bet.selectionId]['totalBetVolume'] = 0 Standing[bet.selectionId]['Liability'] = 0 Standing[bet.selectionId]['Potential'] = 0 if bet.betType == 'L': if bet.betStatus == 'M': #Sum all Matched Lays <=================== Standing[bet.selectionId]['totalLayPrice'] = ((Standing[bet.selectionId]['totalLayPrice'] * Standing[bet.selectionId]['totalLayVolume'] + bet.price * bet.size ) / (Standing[bet.selectionId]['totalLayVolume'] + bet.size)) Standing[bet.selectionId]['totalLayVolume'] = Standing[bet.selectionId]['totalLayVolume'] + bet.size if bet.betType == 'B': if bet.betStatus == 'M': #Sum all Matched Bets <=================== Standing[bet.selectionId]['totalBetPrice'] = ((Standing[bet.selectionId]['totalBetPrice'] * Standing[bet.selectionId]['totalBetVolume'] + bet.price * bet.size ) / (Standing[bet.selectionId]['totalBetVolume'] + bet.size)) Standing[bet.selectionId]['totalBetVolume'] = Standing[bet.selectionId]['totalBetVolume'] + bet.size for selectionId in Standing.keys(): if len(Standing.keys()) > 1: for nextId in Standing.keys(): if nextId == selectionId: continue else: Standing[nextId]['Liability'] = (Standing[nextId]['Liability'] + Standing[selectionId]['totalBetVolume'] - Standing[selectionId]['totalLayVolume']) Standing[nextId]['Potential'] = (Standing[nextId]['Potential'] + Standing[selectionId]['totalLayVolume'] - Standing[selectionId]['totalBetVolume']) Standing[selectionId]['Liability'] = (Standing[selectionId]['Liability'] + Standing[selectionId]['totalLayVolume'] * (Standing[selectionId]['totalLayPrice'] - 1) - Standing[selectionId]['totalBetVolume'] * (Standing[selectionId]['totalBetPrice'] - 1)) Standing[selectionId]['Potential'] = (Standing[selectionId]['Potential'] + Standing[selectionId]['totalBetVolume'] * (Standing[selectionId]['totalBetPrice'] - 1) - Standing[selectionId]['totalLayVolume'] * (Standing[selectionId]['totalLayPrice'] - 1)) else: Standing[selectionId]['Liability'] = max((Standing[selectionId]['totalBetVolume'] - Standing[selectionId]['totalLayVolume']), (Standing[selectionId]['totalLayVolume'] * (Standing[selectionId]['totalLayPrice'] - 1) - Standing[selectionId]['totalBetVolume'] * (Standing[selectionId]['totalBetPrice'] - 1))) Standing[selectionId]['Potential'] = max((Standing[selectionId]['totalLayVolume'] - Standing[selectionId]['totalBetVolume']), (Standing[selectionId]['totalBetVolume'] * (Standing[selectionId]['totalBetPrice'] - 1) - Standing[selectionId]['totalLayVolume'] * (Standing[selectionId]['totalLayPrice'] - 1))) * 0.96 for selectionId in Standing.keys(): Liability = max( Liability , Standing[selectionId]['Liability'] ) Potential = max( Potential, Standing[selectionId]['Potential'] )