示例#1
0
def isStrategyExisted(strategy_id):
    strdao = StrategyInfoDao()
    strategy = strdao.getStrategyByID(strategy_id)
    if not strategy or strategy.count() == 0:
        return False
    else:
        return True
示例#2
0
def isStrategyExisted(strategy_id):
    strdao = StrategyInfoDao()
    strategy = strdao.getStrategyByID(strategy_id)
    if not strategy or strategy.count() == 0:
        return False
    else:
        return True
示例#3
0
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
示例#4
0
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
示例#5
0
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
示例#6
0
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)
示例#7
0
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)
示例#8
0
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)
示例#9
0
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)
示例#10
0
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
示例#11
0
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