Ejemplo n.º 1
0
    def get(self, user: User, invreq_id: str):
        all_position = investDao.get_position(invreq_id)
        bonds_position = []

        for one in all_position:
            if one.type == Mode.BOND:
                bonds_position.append(one)

        classify = []
        if len(bonds_position) == 0:
            return None, 200
        else:
            for i in range(2):
                bonds_code = bonds_position[i].code
                classname = bondsDao.get_class(bonds_code)
                classify.append({'code': bonds_code, 'classname': classname})

            target_code = ''
            for d in classify:
                if d['classname'] == '国债':
                    target_code = d['code']

            predict_value_result = bondsDao.get_interest_quarter_data(Level.SIMPLE, target_code)
            duration_result = bondsDao.get_interest_quarter_data(Level.HARD, target_code)

            return {'predictValue': predict_value_result,
                    'duration': duration_result}, 200
Ejemplo n.º 2
0
    def get(self, user: User, invreq_id: str):
        from model.Enumeration import Mode
        result = []
        position = investDao.get_position(invreq_id)
        for posi in position:
            type = posi.type
            code = posi.code
            name = posi.name
            quantity = posi.quantity
            price = posi.price

            if type == Mode.BOND:
                current_price = bondsDao.get_price_by_code(code)
            else:
                current_price = stockDao.get_stock_price(code)

            expense = 0.0
            if type == Mode.STOCK:
                expense = StockBl().cal_expense(code, quantity, price * quantity)
            elif type == Mode.GOODS:
                pass  # TODO
            elif type == Mode.BOND:
                pass  # TODO
            result.append({'quotaId': code,
                           'quotaName': name,
                           'currentValue': price,
                           'quantity': quantity,
                           'totalValue': price * quantity,
                           'profitAndLoss': current_price * quantity - price * quantity,
                           'serviceCharge': expense})

        return result, 200
        pass
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def get(self, user: User, invreq_id: str):
        rate_bonds = bondsDao.get_interest_bonds()
        rate_bonds_names = [rows[0] for rows in rate_bonds]
        credit_bonds = bondsDao.get_credit_debt()
        credit_bonds_names = [rows[0] for rows in credit_bonds]

        all_position = investDao.get_position(invreq_id)
        invest = investDao.get_one_invest(invreq_id)
        start_date = str(invest.start_date).split(' ')[0]
        amount = invest.amount

        bonds_position = []

        for one in all_position:
            if one.type == Mode.BOND:
                bonds_position.append(one)

        if len(bonds_position) == 0:
            return None, 200
        else:
            model = []
            for i in range(2):
                quantity = bonds_position[i].quantity
                price = bonds_position[i].price
                name = bonds_position[i].name
                code = bonds_position[i].code
                total_price = bondsDao.get_price_by_code(code) * quantity
                profit = total_price - price * quantity

                model.append({'startDate': start_date,
                              'currentVolume': total_price,
                              'currentRatio': round(price * quantity / amount * 100, 0),
                              'profit': profit,
                              # 'duration': 0,  # todo
                              'name': name,
                              'quotationId': code,
                              'quantity': quantity,
                              'price': price})
            if bondsDao.get_class(bonds_position[0].code) == '国债':
                index_rate = rate_bonds_names.index(model[0].get('quotationId', ''))
                model[0]['duration'] = rate_bonds[index_rate][5]

                index_credit = credit_bonds_names.index(model[1].get('quotationId', ''))
                model[1]['duration'] = credit_bonds[index_credit][8]

                return {"creditOverview": model[1],
                        "rateOverview": model[0]}, 200
            else:
                index_rate = rate_bonds_names.index(model[1].get('quotationId', ''))
                model[1]['duration'] = rate_bonds[index_rate][5]

                index_credit = credit_bonds_names.index(model[0].get('quotationId', ''))
                model[0]['duration'] = credit_bonds[index_credit][8]

                return {"creditOverview": model[0],
                        "rateOverview": model[1]}, 200
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def getPositionById(self, invreq_id):
     # return [position] 根据ID 返回该账户下的Position 数组
     return investDao.get_position(invreq_id)
     pass