def isStrategyExisted(strategy_id): strdao = StrategyInfoDao() strategy = strdao.getStrategyByID(strategy_id) if not strategy or strategy.count() == 0: return False else: return True
def addStrategy(request): strdao = StrategyInfoDao() oStrategyInfo = StrategyInfo(request) StrategyInfoDict = oStrategyInfo.getStrategyInfoDict() strategy_id = request.REQUEST.get('strategy_id','') if not isStrategyExisted(strategy_id): strdao.addStrategy(StrategyInfoDict) else: strdao.updateStrategy(strategy_id, StrategyInfoDict) return strategy_id
def deleteStrategy(request): strategyid = request.REQUEST.get('strategy_id', '') if strategyid == '': return 0 strdao = StrategyInfoDao() if isStrategyExisted(strategyid): strdao.deleteStrategyID(strategyid) remove_task(strategyid) rlist = [] rlist.append(strategyid) return rlist
def deleteStrategy(request): strategyid = request.REQUEST.get('strategy_id','') if strategyid == '': return 0 strdao = StrategyInfoDao() if isStrategyExisted(strategyid): strdao.deleteStrategyID(strategyid) remove_task(strategyid) rlist = [] rlist.append(strategyid) return rlist
def queryAllStrategy(request): strdao = StrategyInfoDao() result = strdao.getAllStrategy() rlist = [] for item in result: rdict = item rdict.pop('_id') #ISOTIMEFORMAT=u'%Y-%m-%d %X' #rdict['date'] = time.strftime(ISOTIMEFORMAT, time.localtime() ) try: rdict['status'] = get_task_status(rdict["strategy_id"]) except Exception, e: print e rlist.append(rdict)
def queryStrategy(request): strategy_id = request.REQUEST.get('strategy_id', '') if strategy_id == '': return 0 strdao = StrategyInfoDao() result = strdao.getStrategyByID(strategy_id) rlist = [] for str in result: rdict = str rdict.pop('_id') try: rdict['status'] = get_task_status(strategy_id) except Exception, e: pass rlist.append(rdict)
def queryStrategy(request): strategy_id = request.REQUEST.get('strategy_id','') if strategy_id == '': return 0 strdao = StrategyInfoDao() result = strdao.getStrategyByID(strategy_id) rlist = [] for str in result: rdict = str rdict.pop('_id') try: rdict['status'] = get_task_status(strategy_id) except Exception, e: pass rlist.append(rdict)
def addStrategy(request): strdao = StrategyInfoDao() oStrategyInfo = StrategyInfo(request) StrategyInfoDict = oStrategyInfo.getStrategyInfoDict() strategy_id = request.REQUEST.get('strategy_id', '') if not isStrategyExisted(strategy_id): strdao.addStrategy(StrategyInfoDict) else: strdao.updateStrategy(strategy_id, StrategyInfoDict) return strategy_id
def addStrategy(request): strdao = StrategyInfoDao() oStrategyInfo = StrategyInfo(request) StrategyInfoDict = oStrategyInfo.getStrategyInfoDict() strategy_id = request.REQUEST.get('strategy_id', '') if not isStrategyExisted(strategy_id): strdao.addStrategy(StrategyInfoDict) else: strdao.updateStrategy(strategy_id, StrategyInfoDict) print "--==Running the strategy==--" ticker = request.REQUEST.get('ticker', '') account_id = request.REQUEST.get('account_id', '') algo_fname = request.REQUEST.get('filename', '') args = request.REQUEST.get('args', '') task = runAlgo.delay(ticker, account_id, algo_fname, args) add_task(strategy_id, task.id) print 'Task is running' return strategy_id