Пример #1
0
    def test_YW_RZMR_SZSJ_060(self):
        title = '五档即成转撤销买——数量溢出(100亿)'
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、部成、全成、部撤已报、部撤、已报待撤、已撤、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动

        case_goal = {
            '期望状态': '废单',
            'errorID': 11000107,
            'errorMSG': queryOrderErrorMsg(11000107),
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        # 定义委托参数信息------------------------------------------
        # 参数:证券代码、市场、证券类型、证券状态、交易状态、买卖方向(B买S卖)、期望状态、Api
        stkparm = QueryStkPriceQty('999999', '2', '0', '2', '0', 'B',
                                   case_goal['期望状态'], Api)
        # 如果下单参数获取失败,则用例失败
        if stkparm['返回结果'] is False:
            rs = {
                '用例测试结果': stkparm['返回结果'],
                '测试错误原因': '获取下单参数失败,' + stkparm['错误原因'],
            }
            self.assertEqual(rs['用例测试结果'], True)
        else:
            wt_reqs = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_MARGIN'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SZ_A'],
                'ticker':
                stkparm['证券代码'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_MARGIN_TRADE'],
                'position_effect':
                Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                stkparm['涨停价'],
                'quantity':
                10000000000
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            CaseParmInsertMysql(case_goal, wt_reqs)
            rs = serviceTest(Api, case_goal, wt_reqs)
            if rs['用例测试结果']:
                logger.warning('执行结果为{0}'.format(str(rs['用例测试结果'])))
            else:
                logger.warning('执行结果为{0},{1},{2}'.format(
                    str(rs['用例测试结果']), str(rs['用例错误源']),
                    json.dumps(rs['用例错误原因'],
                               encoding='UTF-8',
                               ensure_ascii=False)))
            self.assertEqual(rs['用例测试结果'], True)  # 0
Пример #2
0
    def test_YW_CETFSS_SHSH_074(self):
        # -----------ETF赎回-------------
        title = ('上海ETF赎回--错误的数量(数量=0)')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '废单',
            'errorID': 11000107,
            'errorMSG': queryOrderErrorMsg(11000107),
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530620',  # etf代码
            'etf_unit': 0.0  # etf赎回单位数
        }

        # -----------查询ETF赎回前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf赎回数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
            2,
            'market':
            Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
            unit_info['ticker'],
            'side':
            Api.const.XTP_SIDE_TYPE['XTP_SIDE_REDEMPTION'],
            'price_type':
            Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
            quantity,
            'position_effect':
            Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(
            Api,
            case_goal,
            wt_reqs,
            component_stk_info,
        )
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)
Пример #3
0
    def test_YW_CETFSS_SHSG_079(self):
        # -----------ETF申购-------------
        title = (
            '上海ETF申购真实ETF-资金<必须替代所需的资金,申购所需的成分股充足,且禁止现金替代的成分股充足,必须现金替代的成分股也足够多)'
        )
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '废单',
            'errorID': 11010120,
            'errorMSG': queryOrderErrorMsg(11010120),
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '540160',  # etf代码
            'optional_unit': 0.0,  # 买入允许现金替代成分股份数
            'forbidden_unit': 0.0,  # 买入禁止现金替代成分股份数
            'etf_unit': 1.0  # etf申购单位数
        }

        # -----------T日买入成分股-------------
        cetf_basket_add_real(
            Api,
            1.0,
            unit_info,
        )
        time.sleep(10)

        # -----------查询ETF申购前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf申购数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id': 2,
            'market': Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker': unit_info['ticker'],
            'side': Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type': Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity': quantity
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)
Пример #4
0
 def test_YW_RZMR_SZSJ_147(self):
     title = '对方最优转限价买——不存在的证券代码'
     #定义当前测试用例的期待值
     #期望状态:初始、未成交、部成、全成、部撤已报、部撤、已报待撤、已撤、废单、撤废、内部撤单
     #xtp_ID和cancel_xtpID默认为0,不需要变动
     case_goal = {
         '期望状态': '废单',
         'errorID': 11000902,
         'errorMSG': queryOrderErrorMsg(11000902),
         '是否生成报单': '是',
         '是否是撤废': '否',
         'xtp_ID': 0,
         'cancel_xtpID': 0,
     }
     logger.warning(title)
     # 定义委托参数信息------------------------------------------
     wt_reqs = {
         'business_type':
         Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_MARGIN'],
         'order_client_id':
         2,
         'market':
         Api.const.XTP_MARKET_TYPE['XTP_MKT_SZ_A'],
         'ticker':
         '000000',
         'side':
         Api.const.XTP_SIDE_TYPE['XTP_SIDE_MARGIN_TRADE'],
         'position_effect':
         Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT'],
         'price_type':
         Api.const.XTP_PRICE_TYPE['XTP_PRICE_REVERSE_BEST_LIMIT'],
         'price':
         10,
         'quantity':
         200
     }
     ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
     rs = serviceTest(Api, case_goal, wt_reqs)
     if rs['用例测试结果']:
         logger.warning('执行结果为{0}'.format(str(rs['用例测试结果'])))
     else:
         logger.warning('执行结果为{0},{1},{2}'.format(
             str(rs['用例测试结果']), str(rs['用例错误源']),
             json.dumps(rs['用例错误原因'], encoding='UTF-8',
                        ensure_ascii=False)))
     self.assertEqual(rs['用例测试结果'], True)  # 2
Пример #5
0
    def test_YW_CETFSS_SHSH_021(self):
        # -----------ETF赎回-------------
        title = ('上海ETF赎回--允许现金替代:T日ETF拥股量1unit→T日赎回ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530330',  # etf代码
            'etf_unit_buy': 1.0,  # etf买入单位数
            'etf_unit': 1.0,  # etf赎回单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
            'component_unit_sell': 1.0  # 成分股卖出单位数
        }

        # -----------T日买入etf-------------
        cetf_add(Api, Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                 unit_info['ticker'], unit_info['etf_unit_buy'])

        # -----------查询ETF赎回前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf赎回数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id': 2,
            'market': Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker': unit_info['ticker'],
            'side': Api.const.XTP_SIDE_TYPE['XTP_SIDE_REDEMPTION'],
            'price_type': Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity': quantity
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 二级市场卖出的etf数量
        quantity = int(unit_info['etf_unit_sell'] * unit_number)
        quantity_list = split_etf_quantity(quantity)
        # 查询涨停价
        limitup_px = getUpPrice(unit_info['ticker'])
        rs2 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                unit_info['ticker'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                limitup_px,
                'quantity':
                etf_quantity
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs2 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs2['用例测试结果'] is False:
                etf_sell_log(case_goal, rs2)
                self.assertEqual(rs2['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs2)

        # ------------二级市场卖出成份股-----------
        case_goal['期望状态'] = '全成'
        case_goal['errorID'] = 0
        case_goal['errorMSG'] = ''
        # 查询etf成分股代码和数量
        etf_components = query_cetf_component_share(unit_info['ticker'])
        rs3 = {}
        for stk_code in etf_components:
            # 赎回用例1-25会有上海和深圳的成分股各一支,深圳成分股为'008000',只卖上海的
            if stk_code != '008000':
                components_share = etf_components[stk_code]
                quantity = (int(unit_info['component_unit_sell'])
                            if unit_info['component_unit_sell'] >= 100 else
                            int(components_share *
                                unit_info['component_unit_sell']))
                limitup_px = getUpPrice(stk_code)
                wt_reqs = {
                    'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                    'order_client_id':
                    2,
                    'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                    'ticker':
                    stk_code,
                    'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                    'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                    'price':
                    limitup_px,
                    'quantity':
                    quantity
                }
                ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
                rs3 = serviceTest(Api, case_goal, wt_reqs)
                if rs3['用例测试结果'] is False:
                    etf_components_sell_log(case_goal, rs3)
                    self.assertEqual(rs3['用例测试结果'], True)
        etf_components_sell_log(case_goal, rs3)
        self.assertEqual(rs3['用例测试结果'], True)
Пример #6
0
    def test_YW_CETFSS_SHSG_073(self):
        # -----------ETF申购-------------
        title = (
            '设置ETF申购费用上海ETF申购--深市必须全部现金替代:T日有成分股可申购1unitETF&可用资金足额→T日申购ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '550910',  # etf代码
            'component_unit_buy': 1.0,  # 成分股买入单位数
            'etf_unit': 1.0,  # etf申购单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
            'component_unit_sell': 1.0  # 成分股卖出单位数
        }

        # -----------T日买入成分股-------------
        cetf_basket_add(Api, Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                        unit_info['ticker'], unit_info['component_unit_buy'])

        # -----------查询ETF申购前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf申购数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id': 2,
            'market': Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker': unit_info['ticker'],
            'side': Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type': Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity': quantity
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        case_goal['期望状态'] = '全成'
        case_goal['errorID'] = 0
        case_goal['errorMSG'] = ''
        # 二级市场卖出的etf数量
        quantity = int(unit_info['etf_unit_sell'] * unit_number)
        quantity_list = split_etf_quantity(quantity)
        # 查询涨停价
        limitup_px = getUpPrice(unit_info['ticker'])
        rs2 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                unit_info['ticker'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                limitup_px,
                'quantity':
                etf_quantity
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs2 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs2['用例测试结果'] is False:
                etf_sell_log(case_goal, rs2)
                self.assertEqual(rs2['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs2)

        # ------------二级市场卖出成份股-----------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 查询etf成分股代码和数量
        etf_components = query_cetf_component_share(unit_info['ticker'])
        rs3 = {}
        for stk_code in etf_components:
            # 申购用例1-43会有上海和深圳的成分股各一支,深圳成分股为'008000',只卖上海的
            if stk_code != '008000':
                components_share = etf_components[stk_code]
                components_total = (int(unit_info['component_unit_sell'])
                                    if unit_info['component_unit_sell'] >= 100
                                    else int(components_share *
                                             unit_info['component_unit_sell']))
                # 如果买入成分股包含半份,买入时数量取整了,卖出成分股是也要取整
                if str(unit_info['component_unit_buy'])[-1] == '5':
                    quantity = get_valid_amount(components_total)
                else:
                    quantity = components_total
                limitup_px = getUpPrice(stk_code)
                wt_reqs = {
                    'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                    'order_client_id':
                    2,
                    'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SZ_A'],
                    'ticker':
                    stk_code,
                    'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                    'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                    'price':
                    limitup_px,
                    'quantity':
                    quantity
                }
                ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
                rs3 = serviceTest(Api, case_goal, wt_reqs)
                if rs3['用例测试结果'] is False:
                    etf_components_sell_log(case_goal, rs3)
                    self.assertEqual(rs3['用例测试结果'], True)
        etf_components_sell_log(case_goal, rs3)
        self.assertEqual(rs3['用例测试结果'], True)
Пример #7
0
    def test_YW_CETFSS_SHSG_044(self):
        # -----------ETF申购-------------
        title = '上海ETF申购--可深市股票退补现金替代:T-1日无成分股&资金足额&计算现金比例>最大现金比例→T日申购ETF'
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '550580',  # etf代码
            'etf_unit': 1.0,  # etf申购单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
            'component_unit_sell': 1.0  # 成分股卖出单位数
        }

        # -----------查询ETF申购前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf申购数量
        quantity = int(unit_info['etf_unit'] * unit_number)
        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
            2,
            'market':
            Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
            unit_info['ticker'],
            'side':
            Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type':
            Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
            quantity,
            'position_effect':
            Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        case_goal['期望状态'] = '全成'
        case_goal['errorID'] = 0
        case_goal['errorMSG'] = ''
        # 二级市场卖出的etf数量
        quantity = int(unit_info['etf_unit_sell'] * unit_number)
        quantity_list = split_etf_quantity(quantity)
        # 查询涨停价
        limitup_px = getUpPrice(unit_info['ticker'])
        rs2 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                unit_info['ticker'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                limitup_px,
                'quantity':
                etf_quantity,
                'position_effect':
                Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs2 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs2['用例测试结果'] is False:
                etf_sell_log(case_goal, rs2)
                self.assertEqual(rs2['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs2)

        # ------------二级市场卖出成份股-----------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 查询etf成分股代码和数量
        etf_components = query_cetf_component_share(unit_info['ticker'])
        # 如果卖出单位大于100,表示卖出数量;小于100,表示卖出份数
        rs3 = {}
        for stk_code in etf_components:
            # 申购用例1-43会有上海和深圳的成分股各一支,深圳成分股为'008000',只卖上海的
            if stk_code != '008000':
                components_share = etf_components[stk_code]
                quantity = (int(unit_info['component_unit_sell'])
                            if unit_info['component_unit_sell'] >= 100 else
                            int(components_share *
                                unit_info['component_unit_sell']))
                limitup_px = getUpPrice(stk_code)
                wt_reqs = {
                    'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                    'order_client_id':
                    2,
                    'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SZ_A'],
                    'ticker':
                    stk_code,
                    'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                    'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                    'price':
                    limitup_px,
                    'quantity':
                    quantity,
                    'position_effect':
                    Api.const.
                    XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
                }
                ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
                rs3 = serviceTest(Api, case_goal, wt_reqs)
                if rs3['用例测试结果'] is False:
                    etf_components_sell_log(case_goal, rs3)
                    self.assertEqual(rs3['用例测试结果'], True)
        etf_components_sell_log(case_goal, rs3)
        self.assertEqual(rs3['用例测试结果'], True)
Пример #8
0
    def test_YW_CETFSS_SHSH_065(self):
        # -----------ETF赎回-------------
        title = ('T-1日申购ETF-T日赎回ETF-用T日赎回得到的成分股申购ETF-卖T日赎回的ETF成分股')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530670',  # etf代码
            'etf_unit': 1.0,  # etf申赎单位数
            'component_unit_sell': 1.0  # 成分股卖出单位数
        }

        # 查询ETF赎回前成分股持仓
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf申赎数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
            2,
            'market':
            Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
            unit_info['ticker'],
            'side':
            Api.const.XTP_SIDE_TYPE['XTP_SIDE_REDEMPTION'],
            'price_type':
            Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
            quantity,
            'position_effect':
            Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(
            Api,
            case_goal,
            wt_reqs,
            component_stk_info,
        )
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # -----------ETF申购-------------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 查询ETF申购前成分股持仓
        component_stk_info2 = cetf_get_all_component_stk(
            Api, unit_info['ticker'])
        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
            2,
            'market':
            Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
            unit_info['ticker'],
            'side':
            Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type':
            Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
            quantity,
            'position_effect':
            Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs2 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info2)
        etf_creation_log(case_goal, rs2)
        self.assertEqual(rs2['用例测试结果'], True)

        # ------------二级市场卖出成份股-----------
        case_goal['期望状态'] = '全成'
        case_goal['errorID'] = 0
        case_goal['errorMSG'] = ''
        # 查询etf成分股代码、数量、现金替代标志等
        etf_components = query_cetf_components_info(unit_info['ticker'], 1)
        # 如果卖出单位大于100,表示卖出数量;小于100,表示卖出份数
        rs3 = {}
        for component_info in etf_components:
            substitute_flag = component_info[1]
            if substitute_flag in (0, 1):
                stk_code = component_info[0]
                components_share = component_info[2]
                quantity = (int(unit_info['component_unit_sell'])
                            if unit_info['component_unit_sell'] >= 100 else
                            int(components_share *
                                unit_info['component_unit_sell']))
                limitup_px = getUpPrice(stk_code)
                wt_reqs = {
                    'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                    'order_client_id':
                    2,
                    'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                    'ticker':
                    stk_code,
                    'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                    'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                    'price':
                    limitup_px,
                    'quantity':
                    quantity,
                    'position_effect':
                    Api.const.
                    XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
                }
                ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
                rs3 = serviceTest(Api, case_goal, wt_reqs)
                if rs3['用例测试结果'] is False:
                    etf_components_sell_log(case_goal, rs3)
                    self.assertEqual(rs3['用例测试结果'], True)
        etf_components_sell_log(case_goal, rs3)
        self.assertEqual(rs3['用例测试结果'], True)
Пример #9
0
    def test_YW_CETFSS_SHSG_012(self):
        # -----------ETF申购-------------
        title = ('上海ETF申购--必须全部现金替代:' +
                 'T-1日无成分股&可用资金恰好→T日申购ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '550230',  # etf代码
            'etf_unit': 1,  # etf申购单位数
            'component_unit_sell': 1  # 成分股卖出单位数
        }

        # -----------查询ETF申购前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(Api,unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
                2,
            'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
                unit_info['ticker'],
            'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
                int(unit_info['etf_unit'] * unit_number)
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs,component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        quantity = int(unit_info['etf_unit'] * unit_number) # 二级市场卖出etf数量
        quantity_list = split_etf_quantity(quantity)
        limitup_px = getUpPrice(unit_info['ticker'])  # 查询涨停价
        rs2 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                    2,
                'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                    unit_info['ticker'],
                'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                    limitup_px,
                'quantity':
                    etf_quantity
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs2 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs2['用例测试结果'] is False:
                etf_sell_log(case_goal, rs2)
                self.assertEqual(rs2['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs2)

        # ------------二级市场卖出成份股-----------
        # 查询etf成分股代码和数量
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        etf_components = query_cetf_component_share(unit_info['ticker'])
        rs3 = {}
        for stk_code in etf_components:
            components_share = etf_components[stk_code]
            quantity = int(components_share *
                                   unit_info['component_unit_sell'])
            limitup_px = getUpPrice(stk_code)
            wt_reqs = {
                'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                    2,
                'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                    stk_code,
                'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                    limitup_px,
                'quantity':
                    quantity
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs3 = serviceTest(Api, case_goal, wt_reqs)
            if rs3['用例测试结果'] is False:
                etf_components_sell_log(case_goal, rs3)
                self.assertEqual(rs3['用例测试结果'], True)
        etf_components_sell_log(case_goal, rs3)
        self.assertEqual(rs3['用例测试结果'], True)
Пример #10
0
    def test_YW_CETFSS_SHSH_002(self):
        # -----------ETF赎回-------------
        title = ('上海ETF赎回--OMS初始化—可选权限—Fundinfo表,资金账号无跨市场ETF申赎权限')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        updateAllFundRightHasNoP()
        clear_data_and_restart_all()
        Api.trade.Logout()
        Api.trade.Login()
        case_goal = {
            '期望状态': '废单',
            'errorID': 11000555,
            'errorMSG': queryOrderErrorMsg(11000555),
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530150',  # etf代码
            'etf_unit_buy': 1.0,  # etf买入单位数
            'etf_unit': 1.0,  # etf赎回单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
            'component_unit_sell': 1.0  # 成分股卖出单位数
        }

        # -----------T日买入etf-------------
        cetf_add(Api, Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                 unit_info['ticker'], unit_info['etf_unit_buy'])

        # -----------查询ETF赎回前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf赎回数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
            2,
            'market':
            Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
            unit_info['ticker'],
            'side':
            Api.const.XTP_SIDE_TYPE['XTP_SIDE_REDEMPTION'],
            'price_type':
            Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
            quantity,
            'position_effect':
            Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 二级市场卖出的etf数量
        quantity = int(unit_info['etf_unit_sell'] * unit_number)
        quantity_list = split_etf_quantity(quantity)
        # 查询涨停价
        limitup_px = getUpPrice(unit_info['ticker'])
        rs2 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                unit_info['ticker'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                limitup_px,
                'quantity':
                etf_quantity,
                'position_effect':
                Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs2 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs2['用例测试结果'] is False:
                etf_sell_log(case_goal, rs2)
                self.assertEqual(rs2['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs2)
Пример #11
0
    def test_YW_CETFSS_SHSG_003(self):
        # -----------ETF申购-------------
        title = ('上海ETF申购--禁止现金替代:T-1日无成分股→T日买入成分股可以申购1unitETF→T日申购ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        updateFundRightHasP()
        clear_data_and_restart_all()
        Api.trade.Logout()
        Api.trade.Login()
        case_goal = {
            '期望状态': '废单',
            'errorID': 11000555,
            'errorMSG': queryOrderErrorMsg(11000555),
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '550160',  # etf代码
            'component_unit_buy': 1.0,  # 成分股买入单位数
            'etf_unit': 1.0,  # etf申购单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
            'component_unit_sell': 1.0  # 成分股卖出单位数
        }

        # -----------T日买入成分股-------------
        cetf_basket_add(Api, Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                        unit_info['ticker'], unit_info['component_unit_buy'])

        # -----------查询ETF申购前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf申购数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id':
            2,
            'market':
            Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker':
            unit_info['ticker'],
            'side':
            Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type':
            Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity':
            quantity,
            'position_effect':
            Api.const.XTP_POSITION_EFFECT_TYPE['XTP_POSITION_EFFECT_INIT']
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)
Пример #12
0
    def test_YW_CETFSS_SHSH_044(self):
        # -----------ETF赎回-------------
        title = '赎回真实的ETF-可赎回的证券数足量,资金足额,预估现金差额>0'
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530580',  # etf代码
            'etf_unit': 10.0,  # etf赎回单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
            'component_unit_sell': 10.0  # 成分股卖出单位数
        }

        # -----------查询ETF赎回前成分股持仓-------------
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf赎回数量
        quantity = int(unit_info['etf_unit'] * unit_number)
        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id': 2,
            'market': Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker': unit_info['ticker'],
            'side': Api.const.XTP_SIDE_TYPE['XTP_SIDE_REDEMPTION'],
            'price_type': Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity': quantity
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info)
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 二级市场卖出的etf数量
        quantity = int(unit_info['etf_unit_sell'] * unit_number)
        quantity_list = split_etf_quantity(quantity)
        # 查询涨停价
        limitup_px = getUpPrice(unit_info['ticker'])
        rs2 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                unit_info['ticker'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                limitup_px,
                'quantity':
                etf_quantity
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs2 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs2['用例测试结果'] is False:
                etf_sell_log(case_goal, rs2)
                self.assertEqual(rs2['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs2)

        # ------------二级市场卖出成份股-----------
        case_goal['期望状态'] = '全成'
        case_goal['errorID'] = 0
        case_goal['errorMSG'] = ''
        # 查询etf成分股代码、数量、现金替代标志等
        etf_components = query_cetf_components_info(unit_info['ticker'], 1)
        # 如果卖出单位大于100,表示卖出数量;小于100,表示卖出份数
        rs3 = {}
        for component_info in etf_components:
            substitute_flag = component_info[1]
            if substitute_flag in (0, 1):
                stk_code = component_info[0]
                components_share = component_info[2]
                quantity = (int(unit_info['component_unit_sell'])
                            if unit_info['component_unit_sell'] >= 100 else
                            int(components_share *
                                unit_info['component_unit_sell']))
                limitup_px = getUpPrice(stk_code)
                wt_reqs = {
                    'business_type':
                    Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                    'order_client_id':
                    2,
                    'market':
                    Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                    'ticker':
                    stk_code,
                    'side':
                    Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                    'price_type':
                    Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                    'price':
                    limitup_px,
                    'quantity':
                    quantity
                }
                ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
                rs3 = serviceTest(Api, case_goal, wt_reqs)
                if rs3['用例测试结果'] is False:
                    etf_components_sell_log(case_goal, rs3)
                    self.assertEqual(rs3['用例测试结果'], True)
        etf_components_sell_log(case_goal, rs3)
        self.assertEqual(rs3['用例测试结果'], True)
Пример #13
0
    def test_YW_CETFSS_SHSH_067(self):
        # -----------ETF申购-------------
        title = ('T日申购ETF-T日赎回当天申购的ETF-T日卖出T日的ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530690',  # etf代码
            'etf_unit': 1.0,  # etf申赎单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
        }

        # 查询ETF申购前成分股持仓
        component_stk_info = cetf_get_all_component_stk(
            Api, unit_info['ticker'])

        # 查询etf最小申赎数量
        unit_number = query_creation_redem_unit(unit_info['ticker'])
        # etf申赎数量
        quantity = int(unit_info['etf_unit'] * unit_number)

        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id': 2,
            'market': Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker': unit_info['ticker'],
            'side': Api.const.XTP_SIDE_TYPE['XTP_SIDE_PURCHASE'],
            'price_type': Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity': quantity
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs1 = cetf_service_test(
            Api,
            case_goal,
            wt_reqs,
            component_stk_info,
        )
        etf_creation_log(case_goal, rs1)
        self.assertEqual(rs1['用例测试结果'], True)

        # -----------ETF赎回-------------
        case_goal['期望状态'] = '废单'
        case_goal['errorID'] = 11010121
        case_goal['errorMSG'] = queryOrderErrorMsg(11010121)
        # 查询ETF赎回前成分股持仓
        component_stk_info2 = cetf_get_all_component_stk(
            Api, unit_info['ticker'])
        # 定义委托参数信息------------------------------------------
        wt_reqs = {
            'business_type':
            Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_ETF'],
            'order_client_id': 2,
            'market': Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
            'ticker': unit_info['ticker'],
            'side': Api.const.XTP_SIDE_TYPE['XTP_SIDE_REDEMPTION'],
            'price_type': Api.const.XTP_PRICE_TYPE['XTP_PRICE_LIMIT'],
            'quantity': quantity
        }
        g_func.cetf_parm_init(case_goal['期望状态'])
        rs2 = cetf_service_test(Api, case_goal, wt_reqs, component_stk_info2)
        etf_creation_log(case_goal, rs2)
        self.assertEqual(rs2['用例测试结果'], True)

        # --------二级市场,卖出etf-----------
        case_goal['期望状态'] = '全成'
        case_goal['errorID'] = 0
        case_goal['errorMSG'] = ''
        # 二级市场卖出的etf数量
        quantity = int(unit_info['etf_unit_sell'] * unit_number)
        quantity_list = split_etf_quantity(quantity)
        # 查询涨停价
        limitup_px = getUpPrice(unit_info['ticker'])
        rs3 = {}
        for etf_quantity in quantity_list:
            wt_reqs_etf = {
                'business_type':
                Api.const.XTP_BUSINESS_TYPE['XTP_BUSINESS_TYPE_CASH'],
                'order_client_id':
                2,
                'market':
                Api.const.XTP_MARKET_TYPE['XTP_MKT_SH_A'],
                'ticker':
                unit_info['ticker'],
                'side':
                Api.const.XTP_SIDE_TYPE['XTP_SIDE_SELL'],
                'price_type':
                Api.const.XTP_PRICE_TYPE['XTP_PRICE_BEST5_OR_CANCEL'],
                'price':
                limitup_px,
                'quantity':
                etf_quantity
            }
            ParmIni(Api, case_goal['期望状态'], wt_reqs['price_type'])
            rs3 = serviceTest(Api, case_goal, wt_reqs_etf)
            if rs3['用例测试结果'] is False:
                etf_sell_log(case_goal, rs3)
                self.assertEqual(rs3['用例测试结果'], True)
                return
        etf_sell_log(case_goal, rs3)