예제 #1
0
def login_with_pwd():
    phone = request.json.get("phoneNo")
    pwd = request.json.get("password")
    # code = request.json.get("msgCode")
    user_list = db.getUserByPhone(phone)
    if user_list:
        user = user_list.pop()
        if pwd == user.password:
            session.permant = True
            app.permanent_session_lifetime = timedelta(minutes=60)
            session['userId'] = user.user_id
            session['phoneNo'] = user.phone
            data = {'login': '******'}
            result = ResponseModel(data=data,
                                   code='1',
                                   message='login success!')
            response = makeResp(result)
        else:
            data = {'login': '******'}
            result = ResponseModel(
                data=data,
                code='0',
                message='login failed,password and username not match!')
            response = makeResp(result)
    else:
        data = {'login': '******'}
        result = ResponseModel(
            data=data,
            code='0',
            message='login failed,this phone number is not exist!')
        response = makeResp(result)
    return response
예제 #2
0
def sign_up():
    phone = request.json.get("phoneNo")
    pwd = request.json.get("password")
    code = request.json.get("msgCode")
    nick_name = request.json.get("nickName")
    open_id = request.json.get("openId")
    age = request.json.get("age")
    gender = request.json.get("gender")
    avator = request.json.get("avatar")
    levels = request.json.get("levels")
    strategy_amount = request.json.get("strategyAmount")
    history_amount = request.json.get("historyAmount")
    style = request.json.get("style")
    experience = request.json.get("experience")

    user_list = db.getUser(phone)
    if not user_list:
        # user = user_list.pop()
        cache_code = sms.cache.get(phone)
        if code == cache_code:
            db.saveUserItem(phone, pwd, nick_name, open_id, age, gender,
                            avator, levels, strategy_amount, history_amount,
                            style, experience)
            data = {'signUp': 'Successed'}
            result = ResponseModel(data=data, code='1', message='注册成功!')
            response = makeResp(result)
        else:
            data = {'signUp': 'Failed'}
            result = ResponseModel(data=data, code='0', message='注册失败,验证码不匹配!')
            response = makeResp(result)
    else:
        data = {'signUp': 'Failed'}
        result = ResponseModel(data=data, code='0', message='注册失败,该手机号已存在!')
        response = makeResp(result)
    return response
예제 #3
0
def login_with_msg_code():
    phone = request.json.get("phoneNo")
    code = request.json.get("msgCode")
    user_list = db.getUserByPhone(phone)
    if user_list:
        user = user_list.pop()
        cache_code = sms.cache.get(phone)
        if code == cache_code:
            # session.permant = True
            session.permant = True
            app.permanent_session_lifetime = timedelta(minutes=60)
            session['userId'] = user.user_id
            session['phoneNo'] = user.phone
            data = {'login': '******'}
            result = ResponseModel(data=data,
                                   code='1',
                                   message='login success!')
            response = makeResp(result)
        else:
            data = {'login': '******'}
            result = ResponseModel(data=data,
                                   code='0',
                                   message='login failed,msgCode not match!')
            response = makeResp(result)
    else:
        data = {'login': '******'}
        result = ResponseModel(
            data=data,
            code='0',
            message='login failed,this phone number is not exist!')
        response = makeResp(result)
    return response
예제 #4
0
def loginJudger():
    if not session:
        data = {'update': 'Failed'}
        result = ResponseModel(data=data,
                               code='0',
                               message='failed,session is not exist!')
        response = make_response(
            json.dumps({'result': result.__dict__},
                       ensure_ascii=False,
                       cls=JsonExtendEncoder))
        response = make_response(response)
        response.status = "403"
        response.headers["Content-Type"] = "application/json"
    else:
        user_id = session['userId']
        if user_id:
            data = {'loginJudge': 'Successed'}
            result = ResponseModel(data=data, code='1', message='success!')
            response = makeResp(result)

        else:
            data = {'update': 'Failed'}
            result = ResponseModel(data=data,
                                   code='0',
                                   message='failed,userid is not exist!')
            response = make_response(
                json.dumps({'result': result.__dict__},
                           ensure_ascii=False,
                           cls=JsonExtendEncoder))
            response = make_response(response)
            response.status = "403"
            response.headers["Content-Type"] = "application/json"
    return response
예제 #5
0
def alter_personal_info():
    user_id = session['userId']

    # phone = request.json.get("phoneNo")
    # pwd = request.json.get("password")
    # code = request.json.get("msgCode")
    nick_name = request.json.get("nickName")
    open_id = request.json.get("openId")
    age = request.json.get("age")
    gender = request.json.get("gender")
    avator = request.json.get("avatar")
    style = request.json.get("style")
    experience = request.json.get("experience")

    if user_id:
        db.update_user_info(user_id, nick_name, open_id, age, gender, avator,
                            style, experience)
        data = {'signUp': 'Successed'}
        result = ResponseModel(data=data, code='1', message='修改成功!')
        response = makeResp(result)
    else:
        data = {'update': 'Failed'}
        result = ResponseModel(data=data, code='0', message='修改失败,无访问权限!')
        response = make_response(
            json.dumps({'result': result.__dict__},
                       ensure_ascii=False,
                       cls=JsonExtendEncoder))
        response = make_response(response)
        response.status = "403"
        response.headers["Content-Type"] = "application/json"
    return response
예제 #6
0
def login_with_pwd():
    phone = request.json.get("phoneNo")
    pwd = request.json.get("password")
    # code = request.json.get("msgCode")
    user_list = db.getUser(phone)
    if user_list:
        user = user_list.pop()
        if pwd == user.password:
            # session.permanent  = True
            session['userId'] = user.user_id
            session['phoneNo'] = user.phone
            data = {'login': '******'}
            result = ResponseModel(data=data, code='1', message='登录成功!')
            response = makeResp(result)
        else:
            data = {'login': '******'}
            result = ResponseModel(data=data,
                                   code='0',
                                   message='登录失败,用户密码不匹配!')
            response = makeResp(result)
    else:
        data = {'login': '******'}
        result = ResponseModel(data=data, code='0', message='登录失败,该手机号未注册!')
        response = makeResp(result)
    return response
예제 #7
0
def change_phone_num():
    user_id = session['userId']
    phone = request.json.get("phoneNo")
    code = request.json.get("msgCode")
    cache_code = sms.cache.get(phone)

    if user_id:
        if code == cache_code:
            db.update_user_phone_num(phone, user_id)
            data = {'changePhoneNum': 'Successed'}
            result = ResponseModel(data=data, code='1', message='修改成功!')
            response = makeResp(result)
        else:
            data = {'update': 'Failed'}
            result = ResponseModel(data=data, code='0', message='修改失败,验证码不匹配!')
            response = makeResp(result)
    else:
        data = {'update': 'Failed'}
        result = ResponseModel(data=data, code='0', message='修改失败,无访问权限!')
        response = make_response(
            json.dumps({'result': result.__dict__},
                       ensure_ascii=False,
                       cls=JsonExtendEncoder))
        response = make_response(response)
        response.status = "403"
        response.headers["Content-Type"] = "application/json"
    return response
예제 #8
0
def isExistsStrategyName(strategy_id, strategy_name, userId, strategy_oper):
    if strategy_id == 0 or strategy_oper == "submit":
        strategy_name_exists = DB.checkStrategyName(
            strategy_name=strategy_name, creator=userId)
        result = {
            "strategy_name_exists": strategy_name_exists,
            "strategy_id": strategy_id
        }

        response = ResponseModel(data=result, code='1', message="策略名称重复")
        return response
    elif DB.checkPreviousStrategyName(strategy_id=strategy_id,
                                      strategy_name=strategy_name,
                                      creator=userId) is False:
        strategy_name_exists = DB.checkStrategyName(
            strategy_name=strategy_name, creator=userId)

        result = {
            "strategy_name_exists": strategy_name_exists,
            "strategy_id": strategy_id
        }
        result = ResponseModel(data=result, code='1', message='策略名称重复')
        return result
    else:
        # 若 返回值为true 则说明 此时 策略名称未改变,可以继续完成
        result = {"strategy_name_exists": False, "strategy_id": strategy_id}

        result = ResponseModel(data=result, code='1', message='策略名称未改变')
        return result
예제 #9
0
def mob_get_strategy_account_list(strategy_log_id):
    strategy_account_list = DB.getStrategyAccountList(
        strategyLogId=strategy_log_id)
    if strategy_account_list.__len__() == 0:
        result = ResponseModel(data='无对应的回测记录!', code='0', message='success')
        return result
    s0 = strategy_account_list[0]
    init_price = s0.close

    margin_list = []
    benchmark_list = []
    time_stamp_list = []

    for s in strategy_account_list:
        margin = s.current_total_margin_rate
        margin = margin.quantize(Decimal('0.0000'))
        benchmark = Decimal(str(s.close)) / Decimal(
            str(init_price)) - Decimal('1')
        benchmark = benchmark.quantize(Decimal('0.0000'))
        margin_list.append(margin)
        benchmark_list.append(benchmark)
        time_stamp_list.append(s.t)

    response = {
        "margin_list": margin_list,
        "benchmark_list": benchmark_list,
        "time_stamp_list": time_stamp_list
    }
    result = ResponseModel(data=response, code='1', message='success')
    return result
예제 #10
0
def change_pwd():
    phone = request.json.get("phoneNo")
    pwd = request.json.get("password")
    code = request.json.get("msgCode")
    phoneNo = session['phoneNo']
    if not phoneNo:
        data = {'changePwd': 'Failed'}
        result = ResponseModel(data=data,
                               code='0',
                               message='session is null,permission deny!')
        response = make_response(
            json.dumps({'result': result.__dict__},
                       ensure_ascii=False,
                       cls=JsonExtendEncoder))
        response = make_response(response)
        response.status = "403"
        response.headers["Content-Type"] = "application/json"
    else:
        user_id = session['userId']
        if user_id is None:
            user_id = 1
        user_list = db.getUser(user_id)
        if str(phone) == phoneNo:
            if user_list:
                # user = user_list.pop()
                cache_code = sms.cache.get(phone)
                # userList = db.getUser(phone)
                #         # user = userList.pop()
                #         # user.user_id

                if code == cache_code:
                    db.update_user_pwd(user_id=session['userId'], new_pwd=pwd)
                    data = {'changePwd': 'Successed'}
                    result = ResponseModel(data=data,
                                           code='1',
                                           message='password change success!')
                    response = makeResp(result)
                else:
                    data = {'changePwd': 'Failed'}
                    result = ResponseModel(
                        data=data,
                        code='0',
                        message='password change failed,magCode not match!')
                    response = makeResp(result)
            else:
                data = {'changePwd': 'Failed'}
                result = ResponseModel(
                    data=data,
                    code='0',
                    message='password change failed, inner error')
                response = makeResp(result)
        else:
            data = {'changePwd': 'Failed'}
            result = ResponseModel(
                data=data,
                code='0',
                message='password change failed, phone number is not match!')
            response = makeResp(result)
    return response
예제 #11
0
def send_msg():
    phone = request.json.get("phoneNo")
    if sms.send_sms(phone) != 0:
        data = {'sendMsg': 'Successed'}
        result = ResponseModel(data=data, code='1', message='发送成功!请在1分钟内完成验证。')
        response = makeResp(result)
    else:
        data = {'sendMsg': 'Failed'}
        result = ResponseModel(data=data, code='0', message='发送失败,请稍后再试。')
        response = makeResp(result)

    return response
예제 #12
0
def change_pwd():
    phone = request.json.get("phoneNo")
    pwd = request.json.get("password")
    code = request.json.get("msgCode")
    phoneNo = session['phoneNo']
    if not phoneNo:
        data = {'changePwd': 'Failed'}
        result = ResponseModel(data=data, code='0', message='session为空,无访问权限!')
        response = make_response(
            json.dumps({'result': result.__dict__},
                       ensure_ascii=False,
                       cls=JsonExtendEncoder))
        response = make_response(response)
        response.status = "403"
        response.headers["Content-Type"] = "application/json"
    else:
        user_list = db.getUser(phoneNo)
        if str(phone) == phoneNo:
            if user_list:
                # user = user_list.pop()
                cache_code = sms.cache.get(phone)
                # userList = db.getUser(phone)
                #         # user = userList.pop()
                #         # user.user_id

                if code == cache_code:
                    db.update_user_pwd(user_id=session['userId'], new_pwd=pwd)
                    data = {'changePwd': 'Successed'}
                    result = ResponseModel(data=data,
                                           code='1',
                                           message='密码修改成功!')
                    response = makeResp(result)
                else:
                    data = {'changePwd': 'Failed'}
                    result = ResponseModel(data=data,
                                           code='0',
                                           message='密码修改失败,验证码不匹配!')
                    response = makeResp(result)
            else:
                data = {'changePwd': 'Failed'}
                result = ResponseModel(data=data,
                                       code='0',
                                       message='密码修改失败,内部错误')
                response = makeResp(result)
        else:
            data = {'changePwd': 'Failed'}
            result = ResponseModel(data=data,
                                   code='0',
                                   message='密码修改失败,该手机号与预留手机号不一致!')
            response = makeResp(result)
    return response
예제 #13
0
def checkStrategyName(strategy_name, creator, strategy_id):
    is_strategy_name_exist = DB.checkStrategyName(strategy_name, creator)
    if is_strategy_name_exist is True:
        strategy_name_exist = {'exist': is_strategy_name_exist}
        response = ResponseModel(data=strategy_name_exist,
                                 code='1',
                                 message='策略名称已存在')
        return response
    else:
        strategy_name_exist = {'exist': is_strategy_name_exist}
        response = ResponseModel(data=strategy_name_exist,
                                 code='1',
                                 message='策略名称未存')
        return response
예제 #14
0
def deleteStrategyById(strategy_id, userId):
    DB.deleteStrategyById(strategy_id, userId)

    response = ResponseModel(data='',
                             code='1',
                             message='delete Strategy  Operation  success')
    return response
예제 #15
0
def executeStrategy(userId, strategy_id):
    # 查询策略基本配置
    strategy_base_info = DB.getStrategyDetail(creator=userId,
                                              strategy_id=strategy_id)

    # 执行poc
    print("strategy_poc: strategy_id ||", strategy_id)
    regression_result = strategyTool.strategy_poc(
        strategy_id, strategy_base_info.start_time,
        strategy_base_info.end_time, strategy_base_info.init_balance)

    # 记录插入 strategy_log  返回最新 strategy_log_id
    strategy_log_id = DB.insertStrategyLog(
        strategy_id=strategy_id,
        start_time=strategy_base_info.start_time,
        end_time=strategy_base_info.end_time,
        userId=userId,
        coin_category=strategy_base_info.coin_category,
        init_balance=strategy_base_info.init_balance)

    response = {
        "strategy_base_info": strategy_base_info.__dict__,
        "regression_result": regression_result.__dict__,
        "strategy_log_id": strategy_log_id
    }
    result = ResponseModel(data=response, code='1', message='success')
    return result
예제 #16
0
def saveStrategyName(strategy_id, strategy_name, creator):
    save_strategy_name = DB.saveStrategyName(strategy_id, strategy_name,
                                             creator)
    response = ResponseModel(data=save_strategy_name,
                             code='1',
                             message='success')
    return response
예제 #17
0
def get_all_strategy_name(creator):
    strategy_name_list = DB.get_all_strategy_name(creator=creator)
    print(len(strategy_name_list))
    response = ResponseModel(data=strategy_name_list,
                             code="1",
                             message="success")
    return response
예제 #18
0
def send_msg():
    phone = request.json.get("phoneNo")
    if sms.send_sms(phone) != 0:
        data = {'sendMsg': 'Successed'}
        result = ResponseModel(data=data,
                               code='1',
                               message='Sent successfully')
        response = makeResp(result)
    else:
        data = {'sendMsg': 'Failed'}
        result = ResponseModel(data=data,
                               code='0',
                               message='send failed,please try later')
        response = makeResp(result)

    return response
예제 #19
0
def mob_executeStrategy(userId, strategy_id, start_time, end_time, create_time,
                        coin_category, init_balance):
    # 更新策略
    DB.mob_updateStrategy(userId=userId,
                          strategy_id=strategy_id,
                          start_time=start_time,
                          end_time=end_time,
                          coin_category=coin_category,
                          init_balance=init_balance)

    # 执行策略
    print("strategy_poc: strategy_id ||", strategy_id)
    result = strategyTool.strategy_poc(strategy_id=strategy_id,
                                       start_time=start_time,
                                       end_time=end_time,
                                       create_time=create_time,
                                       init_balance=init_balance,
                                       creator=userId)

    if result is False:
        print(result)
        response = ResponseModel(data=result, code='0', message='success')
        print(response)
        return response

    else:
        # 策略基本信息
        # 这里如果没有该策略?
        strategy_base_info = DB.getStrategyDetail(creator=userId,
                                                  strategy_id=strategy_id)

        # 策略没有配置相应 买卖条件; buy_signal and sell_signal

        # 返回策略 trade_history 历史数据
        # strategy_trade_history = DB.mob_trade_history(strategy_log_id=strategy_log_id)
        result = result.__dict__
        data = {
            'regression_result': result,
            'strategy_base_info': strategy_base_info.__dict__,
            # 'strategy_log_id': strategy_log_id,
            # 'strategy_trade_history': strategy_trade_history.__dict__
        }

        print(result)
        response = ResponseModel(data=data, code='1', message='success')
        print(response)
        return response
예제 #20
0
def mob_get_strategy_log_list(strategy_id, user_id):
    result_list = []
    strategy_list = DB.mob_get_strategy_log_list(strategy_id=strategy_id,
                                                 creator=user_id)
    for s in strategy_list:
        result_list.append(s.__dict__)
    response = ResponseModel(data=result_list, code="1", message="success")
    return response
예제 #21
0
def mob_my_strategy_list(userId):
    my_strategy_list = []
    strategy_list = DB.mob_my_strategy_list(creator=userId)
    for s in strategy_list:
        my_strategy_list.append(s.__dict__)
    response = ResponseModel(data=my_strategy_list,
                             code="1",
                             message="success")
    return response
예제 #22
0
def saveStrategy(strategy_id, strategy_name, userId, coin_category,
                 init_balance, start_time, end_time, strategyConfItemlist,
                 strategy_oper):
    # 新增策略 以及保存相应条件
    result = isExistsStrategyName(strategy_id=strategy_id,
                                  strategy_name=strategy_name,
                                  userId=userId,
                                  strategy_oper=strategy_oper).__dict__
    if result['data']['strategy_name_exists'] is not True:
        strategyId = DB.saveStrategy(strategy_name, userId, coin_category,
                                     init_balance, start_time, end_time)
        for item in strategyConfItemlist:
            DB.saveStrategyConfItem(strategyId, item['index_label'],
                                    item['formular'], item['price'],
                                    item['direction'])

        response = ResponseModel(data=strategyId, code="1", message="success")
        return response  # 更新策略 =》 更新已存在策略; 首先先判断当前策略名 是否更改;
    else:
        response = ResponseModel(data=result, code="1", message="success")
        return response
예제 #23
0
def updateStrategy(strategy_name, userId, strategy_id, coin_category,
                   init_balance, start_time, end_time, strategy_oper):
    result = isExistsStrategyName(strategy_id=strategy_id,
                                  strategy_name=strategy_name,
                                  userId=userId,
                                  strategy_oper=strategy_oper).__dict__
    print(result)
    if result['data']['strategy_name_exists'] is not True:
        strategy_id = DB.updateStrategy(strategy_id, strategy_name, userId,
                                        coin_category, init_balance,
                                        start_time, end_time)
        # strategy_id, strategy_name, creator, coin_category, init_balance, start_time, end_time

        # strategy_name, coin_category, init_balance, start_time, end_time, strategy_id, creator

        response = ResponseModel(data=strategy_id, code='1', message='success')
        return response
    else:
        # 执行更新策略逻辑
        response = ResponseModel(data=result, code='1', message='success')
        return response
예제 #24
0
def mob_strategy_trade_history(strategy_log_id):
    trade_history_list = []

    trade_historys = DB.mob_trade_history(strategy_log_id=strategy_log_id)

    for trade_history in trade_historys:
        trade_history_list.append(trade_history.__dict__)

    response = ResponseModel(data=trade_history_list,
                             code="1",
                             message="success")

    return response
예제 #25
0
def login_with_msg_code():
    phone = request.json.get("phoneNo")
    code = request.json.get("msgCode")
    user_list = db.getUser(phone)
    if user_list:
        user = user_list.pop()
        cache_code = sms.cache.get(phone)
        if code == cache_code:
            # session.permant = True
            session['userId'] = user.user_id
            session['phoneNo'] = user.phone
            data = {'login': '******'}
            result = ResponseModel(data=data, code='1', message='登录成功!')
            response = makeResp(result)
        else:
            data = {'login': '******'}
            result = ResponseModel(data=data, code='0', message='登录失败,验证码不匹配!')
            response = makeResp(result)
    else:
        data = {'login': '******'}
        result = ResponseModel(data=data, code='0', message='登录失败,该手机号未注册!')
        response = makeResp(result)
    return response
예제 #26
0
def getStrategy(creator, strategyId):
    strategy_conf_list = []

    result = DB.getStrategy(creator, strategyId)
    strategy_confs = result.__dict__

    # result 此时是个字典, 所以就这个来讲, 字典调用方式是 ['']
    for strategy_conf in strategy_confs['strategy_conf_items']:
        strategy_conf_list.append(strategy_conf.__dict__)

    strategy_confs['strategy_conf_items'] = strategy_conf_list

    response = ResponseModel(data=strategy_confs, code='1', message='success')
    return response
예제 #27
0
def saveStrategyAndRun(strategy_id, strategy_name, userId, coin_category,
                       init_balance, start_time, end_time,
                       strategyConfItemlist, strategy_oper):
    result = isExistsStrategyName(strategy_id=strategy_id,
                                  strategy_name=strategy_name,
                                  userId=userId,
                                  strategy_oper=strategy_oper).__dict__
    print(result)

    if result['data']['strategy_name_exists'] is not True:
        response = strategyOperation(strategy_id, strategy_name, userId,
                                     coin_category, init_balance, start_time,
                                     end_time, strategyConfItemlist,
                                     strategy_oper)
        return response
    else:
        response = ResponseModel(data=result, code='1', message="success")
        return response
예제 #28
0
def strategyOperation(strategy_id, strategy_name, userId, coin_category,
                      init_balance, start_time, end_time, strategyConfItemlist,
                      strategy_oper):
    if strategy_oper == "save":
        # update 并且更新
        print("strategyOperation: update Strategy")
        result = updateStrategy(strategy_id=strategy_id,
                                strategy_name=strategy_name,
                                userId=userId,
                                coin_category=coin_category,
                                init_balance=init_balance,
                                start_time=start_time,
                                end_time=end_time,
                                strategy_oper=strategy_oper)
        strategy_id = result.data

    elif strategy_oper == "submit":
        print("strategyOperation: Save Strategy")
        # strategy_id, strategy_name, userId, coin_category, init_balance, start_time, end_time,
        # strategyConfItemlist, strategy_oper
        result = saveStrategy(strategy_id=strategy_id,
                              strategy_name=strategy_name,
                              userId=userId,
                              coin_category=coin_category,
                              init_balance=init_balance,
                              start_time=start_time,
                              end_time=end_time,
                              strategyConfItemlist=strategyConfItemlist,
                              strategy_oper=strategy_oper)
        strategy_id = result.data
    if isinstance(strategy_id, (dict)):
        strategy_id = strategy_id.get('strategy_id')
    strategy_base_info = DB.getStrategyDetail(userId, strategy_id)

    response = {"strategy_base_info": strategy_base_info.__dict__}

    response = ResponseModel(data=response, code="1", message="success")

    print(response)
    return response
예제 #29
0
def set_default_strategy_name(creator):
    strategy_name_list = DB.get_all_strategy_name(creator=creator)
    default_name = 'My Strategy'
    strategy_name_no = 0
    strategy_name_mark = ''

    # 默认策略命名规则是: My Strategy (1), My Strategy (2), My Strategy (3), My Strategy (4)

    for strategy_name in strategy_name_list:
        default_strategy_name = default_name + strategy_name_mark
        print(default_strategy_name)

        if default_strategy_name in strategy_name_list:
            print(True)
            strategy_name_no += 1
            strategy_name_mark = '(' + str(strategy_name_no) + ')'
        else:
            continue

    default_name = default_name + strategy_name_mark
    response = ResponseModel(data=default_name, code="1", message="success")
    return response
예제 #30
0
def deleteStrategyLogById(strategy_log_id):
    DB.deleteStrategyLogById(strategy_log_id)
    response = ResponseModel(data='', code='1', message='success')
    return response