Пример #1
0
    def test_YW_CETFSS_SHSH_083(self):
        # -----------ETF赎回-------------
        title = ('上海:当日买入的基金份额,当日可以赎回并检查持仓')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530780',  # etf代码
            'etf_unit_buy': 1.0,  # etf买入单位数
            'etf_unit': 1.0   # etf赎回单位数
        }

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

        # -----------查询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)
Пример #2
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)
Пример #3
0
    def test_YW_CETFSS_SHSH_086(self):
        # -----------ETF赎回-------------
        title = ('上海:折价套利(当ETF二级市场实际交易价格小于ETF份额参考净值大时,产生折价套利)')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530820',  # etf代码
            'etf_unit_buy': 1.0,  # etf买入单位数
            'etf_unit': 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'])
        time.sleep(1)

        # 查询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)

        # ------------二级市场卖出成份股-----------
        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)
Пример #4
0
    def test_YW_CETFSS_SHSH_084(self):
        # -----------ETF赎回-------------
        title = ('上海:ETF赎回优先使用当天买入的ETF,其次使用昨日持仓的ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            'xtp_ID': 0,
            'cancel_xtpID': 0,
        }
        logger.warning(title)
        unit_info = {
            'ticker': '530790',  # etf代码
            'etf_unit_buy': 1.0,  # etf买入单位数
            'etf_unit': 1.0,   # etf赎回单位数
            'etf_unit_sell': 1.0,  # etf卖出单位数
        }

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

        # -----------查询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'] = 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)
Пример #5
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)
Пример #6
0
    def test_YW_CETFSS_SHSH_004(self):
        # -----------ETF赎回-------------
        title = ('上海ETF赎回--禁止现金替代:T日ETF拥股量1unit→T日赎回ETF')
        # 定义当前测试用例的期待值
        # 期望状态:初始、未成交、全成、废单、撤废、内部撤单
        # xtp_ID和cancel_xtpID默认为0,不需要变动
        updateXtpFundRightHasP()
        clear_data_and_restart_all()
        Api.trade.Logout()
        Api.trade.Login()
        case_goal = {
            '期望状态': '全成',
            'errorID': 0,
            'errorMSG': '',
            '是否生成报单': '是',
            '是否是撤废': '否',
            '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)