示例#1
0
    def get(self, user: User, invreq_id: str):
        args = daily_transaction_parser.parse_args()
        # tran_id = args['tranId']
        record_list = RestDao().getAllStockTransactionRecord(invreq_id)
        # print(len(recordList))
        record_time_list = []
        for r in record_list:
            record_time_list.append(str(r.time).split(" ")[0])
        time_set = list((set(record_time_list)))
        ret_array = []
        for t in time_set:

            record_time_array = []
            for r in record_list:

                if str(r.time).split(" ")[0] == t:
                    temp_dict = {
                        "time": str(r.time).split(' ')[1].split('.')[0],
                        "type": EnumTrans.trans_mode(r.type),
                        "quotaId": r.quota_id,
                        "quotaName": r.quota_name,
                        "buyOrSale": EnumTrans.get_sell_method(r.buy_or_sale),
                        "quantity": r.quantity,
                        "price": r.price,
                        "totalPrice": r.quantity * r.price,
                        "matching": r.matching,
                        "lastMatching": r.lastMatching,
                    }
                    # 需要跟前端说明一下,这里有的数据是不能要的
                    # tranList.append(temp_dict)
                    record_time_array.append(temp_dict)  # 这一步存疑
            record_dist = {"time": str(t), "children": record_time_array}
            ret_array.append(record_dist)
        return ret_array, 200
        pass
示例#2
0
 def post(self, user: User, invreq_id: str):
     # 都拿invreq id 来拿,废弃掉tran id
     # args = transaction_parser.parse_args()
     # tran_id = args["tranId"]
     RestDao().generateRecordsAndChange(invreq_id)
     return '交易确认', 201
     pass
示例#3
0
 def get(self, user: User, invreq_id: str):
     account = RestDao().getInvestRequirementByKey(invreq_id)
     dict_return = {"accuRevenue": account.accu_revenue, "predRorYear": account.pred_revenue_year*100,
                    "todayRevenue": account.today_revenue, "startDate": str(account.start_date).split(' ')[0],
                    "startVolume": account.amount}
     return dict_return, 200
     pass
示例#4
0
    def delete(self, user: User, invreq_id: str):
        from utils.CitiApiUtil import createRedeemTransfer
        from model.Enumeration import Mode
        from bl.allocation.stock.StockBl import StockBl

        import config
        account = RestDao().getInvestRequirementByKey(invreq_id)
        position = investDao.get_position(invreq_id)
        expense = 0.0
        total_amount = 0.0
        for p in position:
            if p.type == Mode.STOCK:
                t = p.quantity * stockDao.get_stock_price(p.code)
                e = StockBl().cal_expense(p.code, -p.quantity, p.quantity * stockDao.get_stock_price(p.code))
                total_amount += t
                expense += e
            elif p.type == Mode.BOND:
                t = p.quantity * bondsDao.get_price_by_code(p.code)
                total_amount += t
            elif p.type == Mode.GOODS:
                t = p.quantity * goodsDao.get_price_by_code(p.code)
                total_amount += t
        amount = total_amount - expense
        createRedeemTransfer(amount, config.system_payee_id)
        print('redeem amount: ' + str(amount))
        investDao.delete(account)  # 直接在数据库中删除对应的资产账户
        return 200
        pass
示例#5
0
 def get(self, user: User, invreq_id: str):
     account = RestDao().getInvestRequirementByKey(invreq_id);
     distReturn = {'planTranTime': account.plan_tran_time, 'planRemindTime': account.plan_remind_time,
                   'minConfirmedPrice': account.min_confirmed_price, 'confirmTime': account.confirm_time,
                   'defaultConfirm': account.defaultConfirm}
     return distReturn, 200
     pass
示例#6
0
def update_allocation():
    timer = Timer(24 * 60 * 60, update_allocation)
    timer.start()

    session = db.session()
    all_invest = session.query(InvestRequirement).all()

    for invest in all_invest:
        # 生成方案
        allocation = globalAllocationBl.get_allocation(invest.profit,
                                                       invest.risk,
                                                       invest.amount,
                                                       invest.year, False)
        invest_id = invest.id
        # 先把原来的交易建议删了,然后写入新的
        investDao.delete_advice(invest_id)
        # 写入交易建议
        advices = allocation[2]
        for advice in advices:
            advice.request_id = invest_id
            investDao.insert(advice)

        if not invest.defaultConfirm:
            investDao.insert(
                Notice('尊敬的用户:您的资产配置方案已产生变更,请尽快确认交易', invest.username,
                       'Others'))
        else:
            RestDao().generateRecordsAndChange(invest_id)

        pass
示例#7
0
 def get(self, user: User, invreq_id: str):
     # 这个方法需要调用整体的计算配比的方法,不是直接访问数据库的方法
     match = RestDao().getInvestRequirementMatchining(invreq_id)
     sum = float(match.stock + match.bonds + match.goods) + 0.000001  # 防止除零错误
     dist_return = {"stockMatching": round(100 * match.stock / sum, 2),
                    "bondMatching": round(100 * match.bonds / sum, 2),
                    "productionMatching": round(100 * match.goods / sum, 2)}
     return dist_return, 200
示例#8
0
    def get(self, user: User, invreq_id: str):
        account = RestDao().getInvestRequirementByKey(invreq_id)

        if account.is_bought == State.CONSIDERATION:
            ret = {"invreqId": invreq_id, "bought": False}
        else:
            ret = {"invreqId": invreq_id, "bought": True}
        return ret, 200
示例#9
0
 def get(self, user: User):
     accounts = RestDao().getAllAccountByUsername(user.username)
     ret = []
     for account in accounts:
         b = True
         if account.is_bought != State.BUY:
             b = False
         dict_temp = {'invreqId': account.id, 'bought': b}
         ret.append(dict_temp)
     ret[0]['recommended'] = True
     return ret, 200
示例#10
0
    def delete(self, user: User, invreq_id: str):
        # args = transaction_parser.parse_args()
        # tran_id = args["tranId"]
        advice_arr = RestDao().getAdivceById(invreq_id)
        for adv in advice_arr:
            investDao.delete(adv)
            adv.is_done = True
            investDao.insert(adv)
        return "取消交易成功", 200

        pass
示例#11
0
 def get(self, user: User, invreq_id: str):
     records = RestDao().getAllReallowcationRecord(invreq_id)
     ret = []
     for r in records:
         sum_before = float(r.stock_before + r.bonds_before + r.goods_before) + 0.000001  # 防止除零
         sum_after = float(r.stock_after + r.bonds_after + r.goods_after) + 0.000001
         a1 = 100 * float(r.stock_before) / sum_before
         b1 = 100 * float(r.bonds_before) / sum_before
         c1 = 100 * float(r.goods_before) / sum_before
         a2 = 100 * float(r.stock_after) / sum_after
         b2 = 100 * float(r.bonds_after) / sum_after
         c2 = 100 * float(r.goods_after) / sum_after
         ret.append(
             {'tranDate': str(r.time).split(' ')[0], 'perOfStock': round(a2, 2), 'changeOfStock': round(a2 - a1, 2),
              'perOfBond': round(b2, 2), 'changeOfBond': round(b2 - b1, 2), 'perOfProduct': round(c2, 2),
              'changeOfProduct': round(c2 - c1, 2)})
     return ret, 200
     pass
示例#12
0
 def get(self, user: User):
     # print(user)
     noticeArr = RestDao().getAllNotice(user.username)
     ret = []
     for r in noticeArr:
         if r.content == "":
             ret.append({
                 "id": r.id,
                 "type": r.type,
                 "dateTime": str(r.time)
             })
         else:
             ret.append({
                 "id": r.id,
                 "type": r.type,
                 "dateTime": str(r.time),
                 "content": r.content
             })
     return ret, 200
     pass
示例#13
0
    def get(self, user: User, invreq_id: str):
        record_list = RestDao().getAllStockTransactionRecord(invreq_id)

        ret_array = []
        for r in record_list:
            temp_dict = {
                "time": str(r.time).split('.')[0],
                "type": EnumTrans.trans_mode(r.type),
                "quotaId": r.quota_id,
                "quotaName": r.quota_name,
                "buyOrSale": EnumTrans.get_sell_method(r.buy_or_sale),
                "quantity": r.quantity,
                "price": r.price,
                "totalPrice": r.quantity * r.price,
                "matching": r.matching,
                "lastMatching": r.lastMatching,
            }
            # 需要跟前端说明一下,这里有的数据是不能要
            ret_array.append(temp_dict)

        return ret_array, 200
        pass
示例#14
0
    def get(self, user: User, invreq_id: str):
        # 根据ID 获取所有满足条件的Advice
        records = RestDao().generateTransactionRecord(invreq_id)

        sum = 0.0
        date = ""
        if len(records) > 0:
            date = records[0].time

        for r in records:
            sum = sum + r.price * r.quantity

        id = invreq_id + str(date)

        tran_list = []
        for i in records:
            print(str(i.type))
            print(str(i.buy_or_sale))
            temp_dict = {
                "time": str(i.time),
                "type": str(i.type).split('.')[1],
                "quotaId": i.quota_id,
                "quotaName": i.quota_name,
                "buyOrSale": str(i.buy_or_sale).split('.')[1],
                "quantity": round(i.quantity, 2),
                "price": i.price,
                "totalPrice": round(i.quantity * i.price, 2),
                "matching": i.matching,
                "lastMatching": i.lastMatching,
            }
            # 需要跟前端说明一下,这里有的数据是不能要的
            tran_list.append(temp_dict)
            # print(temp_dict)

        ret = {'tranId': id, 'tranVolume': sum, "tranDate": str(date).split('.')[0], 'tranList': tran_list}
        return ret, 200

        pass
示例#15
0
    def get(self, user: User, invreq_id: str):
        position = investDao.get_position(invreq_id)
        match = RestDao().getInvestRequirementMatchining(invreq_id)
        result = []
        for p in position:
            percentage = 0.0
            if p.type == Mode.STOCK:
                percentage = round(p.price * p.quantity / (match.stock + 0.000000001) * 100, 2)
            elif p.type == Mode.BOND:
                percentage = round(p.price * p.quantity / (match.bonds + 0.000000001) * 100, 2)
            else:
                percentage = round(p.price * p.quantity / (match.goods + 0.000000001) * 100, 2)
            matching_d = {
                "quotaId": p.code,
                "quotaName": p.name,
                "totalValue": p.price * p.quantity,
                "percentage": percentage,
                "type": EnumTrans.trans_mode(p.type),
            }
            result.append(matching_d)

        return result, 200
        pass
示例#16
0
 def delete(self, user: User):
     notification_id = request.args['id']
     RestDao().deleteNoticeByID(notification_id)
     return 200
     pass
示例#17
0
 def get(self, user: User, invreq_id: str, date: str):
     record = RestDao().getReallowcationRecordByDate(invreq_id, date)
     return record, 200
     pass