def getportfolio(chatid): portfolio = list() for call in Calls.select().where((Calls.chatid == chatid) & (Calls.type == PORTFOLIO_TYPE) & (Calls.qty > 0)): portfolio.append(call) return portfolio
def getwatchlist(chatid): watchlist = list() for call in Calls.select().where((Calls.chatid == chatid) & (Calls.type == WATCH_TYPE) & (Calls.sym.is_null(False))): watchlist.append(call) return watchlist
def lastupdatedportfolio(chatid): try: call=Calls.select()\ .where((Calls.chatid==chatid) & (Calls.type==PORTFOLIO_TYPE) & (Calls.misc==str(PORTFOLIO_STATE_PENDING)))\ .order_by(Calls.time.desc()).get() except DoesNotExist as de: return None return call
def getcalls(chatid, symbol=None): clauses = [(Calls.chatid == chatid), (Calls.type.not_in([WATCH_TYPE, PORTFOLIO_TYPE]))] if symbol: clauses.append((Calls.sym == symbol)) callstxt = '' for call in Calls.select().where(reduce(operator.and_, clauses)): callstxt += call.user + " : " + call.type + " " + call.sym + "@" + call.callrange + \ " " +(call.desc if call.desc else " ")+ \ " on <i>" + call.time.strftime('%b %d %H:%M') + "</i>\n" return callstxt
def deleteoldwatchlist(): calls = Calls.select(Calls.time).where(Calls.type == WATCH_TYPE).order_by( Calls.time.desc()).limit(LIMIT) Calls.delete().where((Calls.type == WATCH_TYPE) & (Calls.time.not_in(calls))).execute()
def deleteoldcalls(): calls = Calls.select(Calls.time).where( (Calls.type.not_in([WATCH_TYPE, PORTFOLIO_TYPE ]))).order_by(Calls.time.desc()).limit(LIMIT) Calls.delete().where((Calls.type.not_in([WATCH_TYPE, PORTFOLIO_TYPE])) & (Calls.time.not_in(calls))).execute()