예제 #1
0
    def test_01(self):
        """
        多单持仓中,部分市价平仓,无对应委托成交,自动撤单,验证用户余额、委托状态
        """
        logger.info("用例编号:62-1---多单持仓中,部分市价平仓,无对应委托成交,自动撤单,验证用户余额、委托状态")
        range_num = 10
        price = 20*100000000
        buy_num = 5*100000000

        before_buy_account_dict = account_info(user=self.buyer, session=self.session, sda_id=sda_id)
        before_buy_account_balance = before_buy_account_dict["balance"]

        # 市价平多单
        buy_resp = self.session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id, order_type=平多, order_price_type=市价, order_price=price, order_num=buy_num
        ))
        sync_id = JMESPathExtractor().extract(query="syncLockKey", body=buy_resp.text)
        logger.info("接口:{0}----返回信息:{1}".format(sda_order_create_url, buy_resp.json()))
        # time.sleep(2)
        after_buy_account_dict = account_info_sync(sync_id=sync_id, user=self.buyer, session=self.session,
                                                   sda_id=sda_id)
        after_buy_account_balance = after_buy_account_dict["balance"]

        flag = assert_one(int(before_buy_account_balance), int(after_buy_account_balance))
        self.assertTrue(flag)
예제 #2
0
    def test_01(self):
        """
        下限价多单单,下单数量大于可用余额
        """
        logger.info("用例编号:22-1---下限价多单,下单数量大于可用余额")
        sda_balance = 9000000000000
        price = 100000000
        num = sda_balance + 100000000
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=sda_balance)

        # 查询可用余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_balance = info_dict["balance"]

        # 下限价委托
        order_resp = self.session.post(url=base + sda_order_create_url,
                                       data=get_sda_order_create_param(
                                           sda_id=sda_id,
                                           order_type=多单,
                                           order_price_type=限价,
                                           order_price=price,
                                           order_num=num,
                                       ))
        msg = JMESPathExtractor().extract(query="MSG", body=order_resp.text)
        status = JMESPathExtractor().extract(query="STATUS",
                                             body=order_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=order_resp.text)
        # order_id = JMESPathExtractor().extract(query="OBJECT.orderId", body=order_resp.text)

        # 查询当前委托
        # get_open_dict = query_order_get_open(user=self.buyer, session=self.session, order_id=order_id)
        # order_quantity = get_open_dict["orderQuantity"]  # 委托数量
        # order_price = get_open_dict["orderPrice"]  # 委托价格
        # order_status = get_open_dict["orderStatus"]  # 委托状态

        # 查询下委托后的可用余额
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id,
                                            price=1000000000)
        after_balance = after_info_dict["balance"]

        flag_one = assert_one(int(before_balance), int(after_balance))
        flag_three = assert_list([200, "可建仓余额不足", "1"],
                                 [order_resp.status_code, msg, status])
        self.assertListEqual([True, True], [flag_one, flag_three])
예제 #3
0
    def test_02(self):
        """
        市价空单5倍杠杆委托,正常下单。
        """
        logger.info("用例编号:108-1--市价空单10倍杠杆委托,正常下单。")
        price = 100000000
        num = 100000000
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=990000000000)

        # 下委托前查询可用余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id,
                                 price=1000000000)
        before_balance = info_dict["balance"]

        # 下委托
        order_resp = self.session.post(url=base + sda_order_create_url,
                                       data=get_sda_order_create_param(
                                           sda_id=sda_id,
                                           order_type=空单,
                                           order_price_type=市价,
                                           order_price=price,
                                           lever="10",
                                           order_num=num))
        logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                               order_resp.json()))
        msg = JMESPathExtractor().extract(query="MSG", body=order_resp.text)
        status = JMESPathExtractor().extract(query="STATUS",
                                             body=order_resp.text)
        order_id = JMESPathExtractor().extract(query="OBJECT.orderId",
                                               body=order_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=order_resp.text)

        # 下委托后查询可用余额
        # time.sleep(1)
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id,
                                            price=1000000000)
        after_balance = after_info_dict["balance"]

        one_flag = assert_one(int(before_balance), int(after_balance))
        list_flag = assert_list([200, "SUCCESS", "0"],
                                [order_resp.status_code, msg, status])
        self.assertListEqual([True, True], [one_flag, list_flag])
예제 #4
0
    def test_01(self):
        """
        限价多单持仓成功,下限价多单委托,验证余额,委托状态
        """
        logger.info("用例编号:32-1---多单持仓成功,下限价多单委托,下限价空单成交,验证余额,委托状态")
        range_num = 10
        price = 100000000
        buy_num = 100000000
        sell_num = buy_num * range_num

        # 下委托前查询可用余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id,
                                 price=1000000000)
        before_balance = info_dict["balance"]

        for i in range(range_num):
            # 下限价委托
            buy_order_resp = self.session.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=多单,
                                                   order_price_type=限价,
                                                   order_price=price,
                                                   order_num=buy_num,
                                               ))
            # time.sleep(0.1)
            logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                                   buy_order_resp.json()))

        sell_order_resp = self.session_54.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=空单,
                                                   order_price_type=限价,
                                                   order_price=price,
                                                   order_num=sell_num))
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=sell_order_resp.text)
        logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                               sell_order_resp.json()))

        # 下委托后查询可用余额
        # time.sleep(2)
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id,
                                            price=1000000000)
        after_balance = after_info_dict["balance"]

        flag = assert_one(int(before_balance), int(after_balance) + sell_num)
        self.assertTrue(flag)
예제 #5
0
 def test_01(self):
     """
     正常访问
     """
     info_dict = account_info(user=self.buyer,
                              session=self.session,
                              sda_id=sda_id,
                              price=1000000000)
     info_user_id = info_dict["userId"]
     info_sda_id = info_dict["sdaId"]
     # 验证返回的sda_id和user_id是否正确
     assert_list([info_user_id, info_sda_id], [self.user_id, sda_id])
예제 #6
0
    def test_01(self):
        """
        连续下N个多单,连续撤单,检查委托状态、用户余额
        """
        logger.info("用例编号:109-1---连续下N个多单,连续撤单,检查委托状态、用户余额")
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type, db=4).sda_clear_user_balance(user_id=self.user_id, keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(user_id=self.user_id, sda_id=sda_id, sda_balance=99000000000000)

        deal_price = 100000000
        deal_num = 100000000
        lever = 100
        # 下委托前查询可用余额
        info_dict = account_info(user=self.buyer, session=self.session, sda_id=sda_id, price=1000000000)
        before_balance = info_dict["balance"]
        cancel_num = None
        sync_id = None
        for i in range(100):
            # 下多单限价
            cancel_num = i
            buy_resp = self.session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(sda_id=sda_id,
                                                                                                        order_type=order_type.多单,
                                                                                                        order_price_type=order_type.限价,
                                                                                                        lever=lever,
                                                                                                        order_price=deal_price,
                                                                                                        order_num=deal_num
                                                                                                        ))
            sync_id = JMESPathExtractor().extract(query="syncLockKey", body=buy_resp.text)
            buy_order_id = JMESPathExtractor().extract(query="OBJECT.orderId", body=buy_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.buyer, sda_order_create_url, buy_resp.status_code, buy_resp.json()
            ))

            # 撤单
            # time.sleep(1)
            cancel_resp = self.session.post(url=base+sda_order_cancel_url, data=get_sda_order_cancel_param(sda_id=sda_id, order_id=buy_order_id, order_type=多单))
            logger.info("撤单接口状态:{0}---返回信息:{1}".format(cancel_resp.status_code, cancel_resp.json()))
            logger.info("撤单次数:{}".format(i))
            # time.sleep(1)

        # 下委托后查询可用余额
        time.sleep(2)
        after_info_dict = account_info_sync(sync_id=sync_id, user=self.buyer, session=self.session, sda_id=sda_id,
                                            price=1000000000)
        after_balance = after_info_dict["balance"]

        logger.info("撤单次数:{}".format(cancel_num))

        available_margin_flag = assert_one(int(before_balance), int(after_balance))
        self.assertTrue(available_margin_flag)
예제 #7
0
    def test_02(self):
        """
        限价空单委托,正常下单。
        """
        logger.info("用例编号:106-2----限价空单10倍杠杆委托,正常下单。")

        num = 1000000000
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type, db=4).sda_clear_user_balance(user_id=self.user_id, keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(user_id=self.user_id, sda_id=sda_id, sda_balance=990000000000)

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer, session=self.session, sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]

        price = int(int(now_stock_price) * 0.95)
        # 下委托前查询可用余额
        info_dict = account_info(user=self.buyer, session=self.session, sda_id=sda_id, price=1000000000)
        before_balance = info_dict["balance"]

        # 下限价空单委托
        order_resp = self.session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(sda_id=sda_id,
                                                                                                      order_type=空单,
                                                                                                      order_price_type=限价,
                                                                                                      lever="10",
                                                                                                      order_price=price,
                                                                                                      order_num=num,))
        msg = JMESPathExtractor().extract(query="MSG", body=order_resp.text)
        status = JMESPathExtractor().extract(query="STATUS", body=order_resp.text)
        order_id = JMESPathExtractor().extract(query="OBJECT.orderId", body=order_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey", body=order_resp.text)

        # 查询当前委托
        # time.sleep(1)
        get_open_dict = query_order_get_open(user=self.buyer, session=self.session, order_id=order_id)
        order_quantity = get_open_dict["orderQuantity"]  # 委托数量
        order_price = get_open_dict["orderPrice"]  # 委托价格
        order_status = get_open_dict["orderStatus"]  # 委托状态

        # 查询委托后可用余额
        after_info_dict = account_info_sync(sync_id=sync_id, user=self.buyer, session=self.session, sda_id=sda_id, price=1000000000)
        after_balance = after_info_dict["balance"]

        flag_one = assert_one(int(before_balance), int(after_balance) + int(price * num / 10 / 100000000))
        flag_two = assert_list([int(order_quantity), int(order_price), order_status], [num, price, "0"])
        flag_three = assert_list([200, "SUCCESS", "0"], [order_resp.status_code, msg, status])
        self.assertListEqual([True, True, True], [flag_one, flag_two, flag_three])
예제 #8
0
    def test_01(self):
        """
        下限价多单,撤单,验证用户余额,委托保证金余额
        """
        logger.info("用例编号:7-1--下多单,撤单,验证用户余额,委托保证金余额,")
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type, db=4).sda_clear_user_balance(user_id=self.user_id, keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(user_id=self.user_id, sda_id=sda_id,
                                                               sda_balance=990000000000000)
        deal_price = 100000000
        deal_num = 100000000

        # 下委托前查询可用余额
        info_dict = account_info(user=self.buyer, session=self.session, sda_id=sda_id, price=1000000000)
        before_balance = info_dict["balance"]

        # 下多单限价
        buy_resp = self.session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id,order_type=order_type.多单,order_price_type=order_type.限价,order_price=deal_price,order_num=deal_num
        ))
        buy_order_id = JMESPathExtractor().extract(query="OBJECT.orderId", body=buy_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code, buy_resp.json()
        ))

        # 撤单
        time.sleep(1)
        cancel_resp = self.session.post(url=base+sda_order_cancel_url, data=get_sda_order_cancel_param(sda_id=sda_id, order_id=buy_order_id, order_type=多单))
        logger.info("撤单接口状态:{0}---返回信息:{1}".format(cancel_resp.status_code, cancel_resp.json()))
        cancel_order_id = JMESPathExtractor().extract(query="OBJECT.orderId", body=cancel_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey", body=cancel_resp.text)
        cancel_msg = JMESPathExtractor().extract(query="MSG", body=cancel_resp.text)

        # 下委托后查询可用余额
        time.sleep(1)
        after_info_dict = account_info_sync(sync_id=sync_id, user=self.buyer, session=self.session, sda_id=sda_id,
                                            price=1000000000)
        after_balance = after_info_dict["balance"]

        order_id_flag = assert_list([buy_order_id, 200, "SUCCESS"], [cancel_order_id, cancel_resp.status_code, cancel_msg])
        available_margin_flag = assert_one(int(before_balance), int(after_balance) )
        self.assertListEqual([True, True], [available_margin_flag, order_id_flag])
예제 #9
0
    def test_02(self):
        """
        空单持仓,平空与空单成交
        """
        logger.info("用例编号:60-2---空单持仓,平空与空单成交")
        range_num = 10
        price = 20*100000000
        buy_num = 10*100000000
        before_sell_account_dict = account_info(user=self.seller, session=self.sell_session, sda_id=sda_id)
        before_sell_account_balance = before_sell_account_dict["balance"]
        print(before_sell_account_balance)
        # 平空单
        # time.sleep(2)
        sell_resp = self.sell_session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id, order_type=平空, order_price_type=限价, order_price=price, order_num=buy_num
        ))
        sell_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=sell_resp.text)
        logger.info("接口:{0}----返回信息:{1}".format(sda_order_create_url, sell_resp.json()))

        # 53用户下空单。
        # time.sleep(2)
        buy_53_resp = self.session_53.post(url=base+sda_order_create_url,data=get_sda_order_create_param(
            sda_id=sda_id, order_type=空单, order_price_type=限价, order_price=price, order_num=buy_num
        ))
        sync_53_id = JMESPathExtractor().extract(query="syncLockKey", body=buy_53_resp.text)
        logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url, buy_53_resp.json()))

        # time.sleep(3)

        after_53_info_dict = account_info_sync(sync_id=sync_53_id, user=self.user_53, session=self.session_53,
                                               sda_id=sda_id)
        after_53_account_balance = after_53_info_dict["balance"]

        after_info_dict = account_info_sync(sync_id=sell_sync_id, user=self.seller, session=self.sell_session,
                                            sda_id=sda_id)
        after_account_balance = after_info_dict["balance"]

        flag_balance = 9999997802034236
        flag_51 = assert_one(int(after_account_balance), int(flag_balance))
        flag_53 = assert_one(self.sda_balance - int(price * buy_num / 100000000), int(after_53_account_balance))
        self.assertListEqual([True, True], [flag_51, flag_53])
예제 #10
0
    def test_06(self):
        """
        限价空单,循环下单,验证可用余额、委托保证金
        :return:
        """
        logger.info("用例编号:6-6---限价空单,循环下单,验证可用余额、委托保证金")
        sda_balance = 9999999900000000
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=sda_balance)

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]
        stock_unit = int(stock_price_dict["tradeUnit"])
        price = int(int(now_stock_price) * 0.95)

        # 查询可用余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id,
                                 price=1000000000)
        before_balance = info_dict["balance"]

        # 下限价委托
        amount_list = []
        sync_flag_list = []
        employ_balance_list = []
        for i in range(50):
            amount = random.randint(1, 100) * 100000000
            amount_list.append(amount)
            order_resp = self.session.post(url=base + sda_order_create_url,
                                           data=get_sda_order_create_param(
                                               sda_id=sda_id,
                                               order_type=空单,
                                               order_price_type=限价,
                                               order_price=price,
                                               order_num=amount,
                                           ))
            sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=order_resp.text)
            sync_flag = sda_sync_lock(session=self.session, sync_id=sync_id)
            sync_flag_list.append(sync_flag)
            logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                                   order_resp.json()))
            # time.sleep(0.1)
            employ_balance = employBalance(price=price,
                                           count=amount,
                                           unit=stock_unit,
                                           lever=1)
            employ_balance_list.append(employ_balance)

        # 查询下委托后的可用余额
        # time.sleep(3)
        for v in sync_flag_list:
            if "OK" != v:
                raise SyncException("sync lock 异常")
        else:
            after_info_dict = account_info(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id,
                                           price=1000000000)
            after_balance = after_info_dict["balance"]

        flag_one = assert_one(int(before_balance),
                              int(after_balance) + sum(employ_balance_list))
        self.assertTrue(flag_one)
예제 #11
0
    def test_08(self):
        """
        市价空单,循环下单,验证可用余额、委托保证金
        """
        sda_balance = 9999999900000000
        logger.info("用例编号:6-8----时间空单,循环下单,验证可用余额、委托保证金")
        price = 100000000
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=sda_balance)

        # 查询可用余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_balance = info_dict["balance"]

        # 下单前查询用户的余额
        buy_balance = self.session.post(
            url=base + sda_account_asset_detail_get_url,
            data=get_sda_account_asset_detail_get_param())
        buy_balance_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].availableMargin", body=buy_balance.text)
        buy_entrust_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].entrustMargin", body=buy_balance.text)
        logger.info(
            "用户:{0}---接口:{1}---状态:{2}---下单前可用保证金:{3}--委托保证金:{4}".format(
                self.buyer, sda_account_asset_detail_get_url,
                buy_balance.status_code, buy_balance_value, buy_entrust_value))

        # 下市价价委托
        sync_id = None
        amount_list = []
        sync_flag_list = []
        for i in range(500):
            amount = random.randint(1, 100) * 100000000
            amount_list.append(amount)
            order_resp = self.session.post(url=base + sda_order_create_url,
                                           data=get_sda_order_create_param(
                                               sda_id=sda_id,
                                               order_type=空单,
                                               order_price_type=市价,
                                               order_num=amount,
                                           ))
            sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=order_resp.text)
            logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                                   order_resp.json()))
            sync_flag = sda_sync_lock(session=self.session, sync_id=sync_id)
            sync_flag_list.append(sync_flag)
            # time.sleep(0.1)

        # 查询下委托后的可用余额
        # time.sleep(1)
        for v in sync_flag_list:
            if "OK" != v:
                raise SyncException("sync lock 异常")
        else:
            after_info_dict = account_info(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id,
                                           price=1000000000)
            after_balance = after_info_dict["balance"]

        # 查询用户余额,然后判断下单前后的用户余额
        after_buy_balance = self.session.post(
            url=base + sda_account_asset_detail_get_url,
            data=get_sda_account_asset_detail_get_param())
        after_buy_balance_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].availableMargin",
            body=after_buy_balance.text)
        after_buy_entrust_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].entrustMargin",
            body=after_buy_balance.text)
        logger.info(
            "用户:{0}---接口:{1}---状态:{2}---下单后可用保证金:{3}---下单后委托保证金:{4}".format(
                self.buyer, sda_account_asset_detail_get_url,
                after_buy_balance.status_code, after_buy_balance_value,
                after_buy_entrust_value))

        flag_one = assert_one(int(before_balance), int(after_balance))
        # flag_two = assert_one(int(buy_entrust_value), int(after_buy_entrust_value))
        self.assertTrue(flag_one)
예제 #12
0
    def test_01(self):
        """
        正常访问,验证接口状态、MSG、STATUS,验证bb账户余额,合约账户余额
        """
        logger.info(
            "用例编号:3-1---合约账户转到币币账户接口测试类--正常访问,验证接口状态、MSG、STATUS,验证bb账户余额、合约账户余额"
        )
        amount = 100000000
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=10000000000)

        # 转出前查询bb账户余额
        before_bb_account_resp = self.session.post(
            url=base + user_balance_servlet_url,
            data=get_user_balance_servlet_param(user=self.buyer,
                                                currency_id=currency_id))
        before_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=before_bb_account_resp.text)
        logger.info("用户:{0}---币ID:{1}---转入前余额:{2}".format(
            self.buyer, currency_id, before_currency_balance))

        # 转出前查询合约账户余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_account_balance = info_dict["balance"]

        # 转出
        withdraw_resp = self.session.post(url=base + sda_account_withdraw_url,
                                          data=get_sda_account_withdraw_param(
                                              sda_id=sda_id, amount=amount))
        msg = JMESPathExtractor().extract(query="MSG", body=withdraw_resp.text)
        status = JMESPathExtractor().extract(query="STATUS",
                                             body=withdraw_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=withdraw_resp.text)
        logger.info("用户:{0}--接口:{1}---状态:{2}--转出金额:{3}--返回信息:{4}".format(
            self.buyer, sda_account_withdraw_url, withdraw_resp.status_code,
            amount, withdraw_resp.json()))

        # time.sleep(3)
        # 转出后查询合约账户余额
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id)
        after_account_balance = after_info_dict["balance"]

        # 转出后查询BB账户余额
        # time.sleep(1)
        after_bb_account_resp = self.session.post(
            url=base + user_balance_servlet_url,
            data=get_user_balance_servlet_param(self.buyer,
                                                currency_id=currency_id))
        after_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=after_bb_account_resp.text)
        logger.info("用户:{0}--币ID:{1}--转入后余额:{2}".format(
            self.buyer, currency_id, after_currency_balance))
        logger.info("转出金额:{}".format(amount))
        self.assertListEqual([200, "SUCCESS", "0"],
                             [withdraw_resp.status_code, msg, status])
        self.assertEqual(
            int(before_currency_balance) + amount, int(after_currency_balance))
        self.assertEqual(
            int(before_account_balance) - int(amount),
            int(after_account_balance))
예제 #13
0
    def test_04(self):
        """
        合约账户余额正好等于转出数量,验证合约账户余额、BB账户余额
        :return:
        """
        logger.info("用例编号:3-4---合约账户余额正好等于转出数量,验证合约账户余额、BB账户余额")
        amount = random.randint(1, 1000) * 100000000
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=amount)

        # 转出前查询合约账户余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_account_balance = info_dict["balance"]

        # 转入前查询bb账户余额
        before_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(user=self.buyer,
                                                currency_id=currency_id))
        before_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=before_bb_account_resp.text)
        logger.info("用户:{0}---币ID:{1}---转入前余额:{2}".format(
            self.buyer, currency_id, before_currency_balance))

        withdraw_resp = self.session.post(url=base + sda_account_withdraw_url,
                                          data=get_sda_account_withdraw_param(
                                              sda_id=sda_id, amount=amount))
        logger.info("转出接口:{0}----返回信息:{1}".format(sda_account_withdraw_url,
                                                  withdraw_resp.json()))
        msg = JMESPathExtractor().extract(query="MSG", body=withdraw_resp.text)
        status = JMESPathExtractor().extract(query="STATUS",
                                             body=withdraw_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=withdraw_resp.text)

        # 转出后查询合约账户余额
        # time.sleep(0.5)
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id)
        after_account_balance = after_info_dict["balance"]

        # 转出后查询BB账户余额
        time.sleep(2)
        after_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(self.buyer,
                                                currency_id=currency_id))
        after_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=after_bb_account_resp.text)
        logger.info("用户:{0}--币ID:{1}--转入后余额:{2}".format(
            self.buyer, currency_id, after_currency_balance))
        logger.info("转出数量:{}".format(amount))
        bb_flag = assert_one(
            int(before_currency_balance) + amount, int(after_currency_balance))
        sda_flag = assert_one(
            int(before_account_balance) - amount, int(after_account_balance))
        self.assertListEqual([True, True], [bb_flag, sda_flag])
예제 #14
0
    def test_01(self):
        """
        多单,验证合约状态、余额。
        """
        logger.info("用例编号:20-1---限价多单,验证合约、用户余额。")
        deal_price = 100000000
        deal_num = 100000000
        # 更新此合约ID下的所有合约状态为2
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=990000000000)

        # 查询当前合约的unit
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        # now_stock_price = int(stock_price_dict["stockPrice"])
        stock_unit = int(stock_price_dict["tradeUnit"])
        # print("now stock price", now_stock_price)

        # 下单前查询两个用户的余额
        account_dict = account_info(user=self.buyer,
                                    session=self.session,
                                    sda_id=sda_id)
        buy_balance = account_dict["balance"]

        buy_resp = self.session.post(url=base + sda_order_create_url,
                                     data=get_sda_order_create_param(
                                         sda_id=sda_id,
                                         order_type=order_type.多单,
                                         order_price_type=order_type.限价,
                                         order_price=deal_price,
                                         order_num=deal_num))
        buy_order_id = JMESPathExtractor().extract(query="OBJECT.orderId",
                                                   body=buy_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=buy_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code,
            buy_resp.json()))

        # 计算委托价值

        stock_value = int(
            stockValue(price=deal_price, count=deal_num, unit=stock_unit))
        print("stock_value", stock_value)

        # 查询当前委托

        order_get_open_resp = self.session.post(
            url=base + sda_order_get_open_url,
            data=get_sda_order_get_open_param(sda_id=sda_id))
        get_order_id = JMESPathExtractor().extract(
            query="LIST[0].orderId", body=order_get_open_resp.text)
        order_num = JMESPathExtractor().extract(query="LIST[0].orderQuantity",
                                                body=order_get_open_resp.text)
        order_price = JMESPathExtractor().extract(
            query="LIST[0].orderPrice", body=order_get_open_resp.text)
        total_price = int(JMESPathExtractor().extract(
            query="LIST[0].totalPrice", body=order_get_open_resp.text))

        order_flag = assert_list(
            [buy_order_id, deal_price, deal_num],
            [get_order_id, int(order_price),
             int(order_num)])
        total_price_flag = assert_one(stock_value, total_price)

        self.assertTrue(total_price_flag)
        self.assertTrue(order_flag)

        after_account_dict = account_info_sync(sync_id=sync_id,
                                               user=self.buyer,
                                               session=self.session,
                                               sda_id=sda_id)
        after_account_balance = after_account_dict["balance"]

        flag = assert_one(int(buy_balance),
                          int(after_account_balance) + deal_num)
        self.assertTrue(flag)
예제 #15
0
    def tet_04(self):
        """
        随机成交测试
        :return:
        """
        warnings.simplefilter("ignore", ResourceWarning)
        lever = 100
        # deal_num = 100000000
        # buy_num = 9*100000000
        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = int(stock_price_dict["stockPrice"])
        stock_unit = int(stock_price_dict["tradeUnit"])

        deal_price = int(int(now_stock_price) * 0.95)

        before_buy_info_dict = account_info(user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id)
        before_buy_balance = int(before_buy_info_dict["balance"])
        print("before buy balance", before_buy_balance)

        before_sell_info_dict = account_info(user=self.seller,
                                             session=self.sell_session,
                                             sda_id=sda_id)
        before_sell_balance = int(before_sell_info_dict["balance"])
        print("before sell balance", before_sell_balance)

        # random_price = random.randint(1, 99) * 100000000
        random_num = random.randint(1, 999999) * 100000000

        # 下一单多单、空单,完全成交
        for i in range(1000):
            buy_resp = self.session.post(url=base + sda_order_create_url,
                                         data=get_sda_order_create_param(
                                             sda_id=sda_id,
                                             order_type=多单,
                                             order_price_type=限价,
                                             lever=lever,
                                             order_price=now_stock_price,
                                             order_num=random_num))
            # buy_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=buy_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.buyer, sda_order_create_url, buy_resp.status_code,
                buy_resp.json()))
            # time.sleep(3)
            sell_resp = self.sell_session.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=空单,
                                                   order_price_type=市价,
                                                   lever=lever,
                                                   order_price=now_stock_price,
                                                   order_num=random_num))
            sell_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                       body=sell_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
                self.seller, sda_order_create_url, sell_resp.status_code,
                sell_resp.json()))
            buy_info_dict = account_info_sync(user=self.buyer,
                                              session=self.session,
                                              sda_id=sda_id,
                                              sync_id=sell_sync_id)
            # print(buy_info_dict)
            after_buy_balance = int(buy_info_dict["balance"])

            sell_info_dict = account_info_sync(user=self.seller,
                                               session=self.sell_session,
                                               sda_id=sda_id,
                                               sync_id=sell_sync_id)
            after_sell_balance = int(sell_info_dict["balance"])
            # print("stock price", deal_price)
            # print("stock unit", stock_unit)
            buy_employ_balance = int(
                employBalance(price=now_stock_price,
                              count=random_num,
                              unit=stock_unit,
                              lever=lever))
            employ_balance = int(
                employBalance(price=now_stock_price,
                              count=random_num,
                              unit=stock_unit,
                              lever=lever))
            print("buy employ balance", buy_employ_balance)
            buy_flag = assert_one(after_buy_balance,
                                  int(before_buy_balance - buy_employ_balance))
            sell_flag = assert_one(after_sell_balance,
                                   int(before_sell_balance - employ_balance))
            self.assertListEqual([True, True], [buy_flag, sell_flag])

            # 平仓
            time.sleep(0.1)
            buy_resp = self.session.post(url=base + sda_order_create_url,
                                         data=get_sda_order_create_param(
                                             sda_id=sda_id,
                                             order_type=平多,
                                             order_price_type=限价,
                                             lever=lever,
                                             order_price=now_stock_price,
                                             order_num=random_num))
            # buy_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=buy_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.buyer, sda_order_create_url, buy_resp.status_code,
                buy_resp.json()))
            time.sleep(0.1)
            sell_resp = self.sell_session.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=平空,
                                                   order_price_type=市价,
                                                   lever=lever,
                                                   order_price=now_stock_price,
                                                   order_num=random_num))
            # sell_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=sell_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
                self.seller, sda_order_create_url, sell_resp.status_code,
                sell_resp.json()))
예제 #16
0
    def test_05(self):
        """
        限价多单,循环多次下单,验证可用余额
        :return:
        """
        logger.info("用例编号:6-5--限价多单,循环多次下单,验证可用余额")
        price = 100000000
        sda_balance = 9999999900000000
        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]
        stock_unit = int(stock_price_dict["tradeUnit"])

        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=sda_balance)

        # 查询可用余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id,
                                 price=1000000000)
        before_balance = info_dict["balance"]

        # 下单前查询用户的余额
        buy_balance = self.session.post(
            url=base + sda_account_asset_detail_get_url,
            data=get_sda_account_asset_detail_get_param())
        buy_balance_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].availableMargin", body=buy_balance.text)
        buy_entrust_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].entrustMargin", body=buy_balance.text)
        logger.info(
            "用户:{0}---接口:{1}---状态:{2}---下单前可用保证金:{3}--委托保证金:{4}".format(
                self.buyer, sda_account_asset_detail_get_url,
                buy_balance.status_code, buy_balance_value, buy_entrust_value))

        # 下限价委托
        amount_list = []
        sync_flag_list = []
        employ_balance_list = []
        for i in range(200):
            amount = random.randint(1, 100) * 100000000
            amount_list.append(amount)
            order_resp = self.session.post(url=base + sda_order_create_url,
                                           data=get_sda_order_create_param(
                                               sda_id=sda_id,
                                               order_type=多单,
                                               order_price_type=限价,
                                               order_price=price,
                                               order_num=amount))
            sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=order_resp.text)
            logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                                   order_resp.json()))
            sync_flag = sda_sync_lock(session=self.session, sync_id=sync_id)
            sync_flag_list.append(sync_flag)
            # time.sleep(0.1)
            # 计算每次下单所使用的保证金
            employ_balance = employBalance(price=price,
                                           count=amount,
                                           unit=stock_unit,
                                           lever=1)
            employ_balance_list.append(employ_balance)

        # 查询下委托后的可用余额
        # time.sleep(2)
        for v in sync_flag_list:
            if "OK" != v:
                raise SyncException("sync lock 异常")
        else:
            after_info_dict = account_info(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id,
                                           price=1000000000)
            after_balance = after_info_dict["balance"]

        # 查询用户余额,然后判断下单前后的用户余额
        after_buy_balance = self.session.post(
            url=base + sda_account_asset_detail_get_url,
            data=get_sda_account_asset_detail_get_param())
        after_buy_balance_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].availableMargin",
            body=after_buy_balance.text)
        after_buy_entrust_value = JMESPathExtractor().extract(
            query="OBJECT.PNLList[0].entrustMargin",
            body=after_buy_balance.text)
        logger.info(
            "用户:{0}---接口:{1}---状态:{2}---下单后可用保证金:{3}---下单后委托保证金:{4}".format(
                self.buyer, sda_account_asset_detail_get_url,
                after_buy_balance.status_code, after_buy_balance_value,
                after_buy_entrust_value))

        flag_one = assert_one(int(before_balance),
                              int(after_balance) + sum(employ_balance_list))
        # flag_two = assert_one(int(buy_entrust_value), int(after_buy_entrust_value) + sum(amount_list))
        self.assertTrue(flag_one)
예제 #17
0
    def test_01(self):
        """
        大数极限测试类
        """
        logger.info("用例编号:110-1---大数极限测试类")
        deal_num = 90000000000*100000000
        lever = 100

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer, session=self.session, sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]
        stock_unit = int(stock_price_dict["tradeUnit"])

        deal_price = int(int(now_stock_price) * 1)
        # deal_price = now_stock_price
        print("stock price", now_stock_price)
        before_buy_dict = account_info(user=self.buyer, session=self.session, sda_id=sda_id)
        before_buy_balance = before_buy_dict["balance"]

        # 下一单多单、空单,完全成交
        buy_resp = self.session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id, order_type=多单, order_price_type=限价, lever=lever, order_price=deal_price,order_num=deal_num
        ))
        buy_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=buy_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code, buy_resp.json()
        ))
        # time.sleep(3)
        sell_resp = self.sell_session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id, order_type=空单, order_price_type=限价, lever=lever, order_price=deal_price,order_num=deal_num
        ))
        sell_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=sell_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
            self.seller, sda_order_create_url, sell_resp.status_code, sell_resp.json()
        ))

        # time.sleep(5)
        # 查询当前持仓中买卖方持仓数量、保证金、开仓均价
        after_buy_position_dict = query_account_position_get(sync_key=sell_sync_id, user=self.buyer,
                                                             session=self.session)
        after_sell_position_dict = query_account_position_get(sync_key=sell_sync_id, user=self.seller,
                                                              session=self.sell_session)

        after_buy_sdaAveragePrice = after_buy_position_dict["sdaAveragePrice"]
        after_buy_sdaCount = after_buy_position_dict["sdaCount"]
        after_buy_currencyBalancePosition = after_buy_position_dict["currencyBalancePosition"]

        after_sell_sdaAveragePrice = after_sell_position_dict["sdaAveragePrice"]
        after_sell_sdaCount = after_sell_position_dict["sdaCount"]
        after_sell_currencyBalancePosition = after_sell_position_dict["currencyBalancePosition"]

        # 计算保证金
        buy_currency_balance = employBalance(price=deal_price, count=deal_num, unit=stock_unit, lever=lever)

        # 检验持仓均价,持仓量,保证金
        balance_flag = assert_one(int(after_buy_currencyBalancePosition), int(buy_currency_balance))
        self.assertTrue(balance_flag)

        price_flag = assert_one(int(deal_price), int(after_buy_sdaAveragePrice))
        num_flag = assert_one(int(deal_num), int(after_buy_sdaCount))
        # after_buy_flag = assert_one(buy_currency_balance, int(after_buy_currencyBalancePosition))
        after_sell_flag = assert_list([int(deal_price), int(deal_num)], [int(after_sell_sdaAveragePrice), int(after_sell_sdaCount)])
        self.assertListEqual([True, True, True], [price_flag, num_flag,after_sell_flag])
예제 #18
0
    def test_01(self):
        """
        多个限价多单、多个限价空单,验证订单状态、用户余额
        """
        logger.info("用例编号:46-1---多个限价多单、多个限价空单,验证订单状态、用户余额")
        deal_num = 100000000
        random_num = 5

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]

        price = int(int(now_stock_price) * 0.95)

        # 下单前查询两个用户的可用余额
        before_buy_account_dict = account_info(user=self.buyer,
                                               session=self.session,
                                               sda_id=sda_id)
        before_buy_account_balance = before_buy_account_dict["balance"]

        before_sell_account_dict = account_info(user=self.seller,
                                                session=self.sell_session,
                                                sda_id=sda_id)
        before_sell_account_balance = before_sell_account_dict["balance"]

        buy_sync_id = None
        for i in range(random_num):
            # 循环下多单
            buy_resp = self.session.post(url=base + sda_order_create_url,
                                         data=get_sda_order_create_param(
                                             sda_id=sda_id,
                                             order_type=多单,
                                             order_price_type=限价,
                                             order_price=price,
                                             order_num=deal_num))
            buy_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                      body=buy_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.buyer, sda_order_create_url, buy_resp.status_code,
                buy_resp.json()))
            # time.sleep(1)

        sell_sync_id = None
        for v in range(random_num):
            # 循环下5个空单
            sell_resp = self.sell_session.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=空单,
                                                   order_price_type=限价,
                                                   order_price=price,
                                                   order_num=deal_num))
            sell_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                       body=sell_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
                self.seller, sda_order_create_url, sell_resp.status_code,
                sell_resp.json()))
            # time.sleep(1)

        # time.sleep(2)

        # 下单结束后查询两个用户可用余额
        after_buy_account_dict = account_info_sync(sync_id=buy_sync_id,
                                                   user=self.buyer,
                                                   session=self.session,
                                                   sda_id=sda_id)
        after_buy_account_balance = after_buy_account_dict["balance"]

        after_sell_account_dict = account_info_sync(sync_id=sell_sync_id,
                                                    user=self.seller,
                                                    session=self.sell_session,
                                                    sda_id=sda_id)
        after_sell_account_balance = after_sell_account_dict["balance"]

        buy_flag = assert_one(
            self.sda_balance,
            int(after_buy_account_balance) +
            int(random_num * deal_num * price / 100000000))
        sell_flag = assert_one(
            self.sda_balance,
            int(after_sell_account_balance) +
            int(random_num * deal_num * price / 100000000))
        self.assertListEqual([True, True], [buy_flag, sell_flag])
예제 #19
0
    def test_01(self):
        """
        参数化测试不同手续费和资金费率
        :return:
        """
        lever = 10
        logger.info("用例编号:130-1---参数化测试不同开仓手续费和资金费率")
        deal_num = 100000000
        warnings.simplefilter("ignore", ResourceWarning)

        for i in range(50):
            charge = int(random.uniform(0.01, 0.99) * 100) / 100
            cost = int(random.uniform(0.01, 0.99) * 100) / 100
            # print("charge", charge)
            # print("cost", cost)
            # 更新用户开仓手续费和资金费率
            ConnectMysql(_type=mysql_type).update_user_charge(
                user_mail=self.buyer, sda_id=sda_id, charge=charge, cost=cost)

            # 查询当前股价
            stock_price_dict = market_info_get(user=self.buyer,
                                               session=self.session,
                                               sda_id=sda_id)
            now_stock_price = int(stock_price_dict["stockPrice"])
            stock_unit = int(stock_price_dict["tradeUnit"])

            deal_price = int(int(now_stock_price) * 0.95)

            # 查询交易前用户余额
            before_buy_info_dict = account_info(user=self.buyer,
                                                session=self.session,
                                                sda_id=sda_id)
            before_buy_balance = int(before_buy_info_dict["balance"])

            # 下一单多单、空单,完全成交
            buy_resp = self.session.post(url=base + sda_order_create_url,
                                         data=get_sda_order_create_param(
                                             sda_id=sda_id,
                                             order_type=多单,
                                             order_price_type=限价,
                                             lever=lever,
                                             order_price=deal_price,
                                             order_num=deal_num))
            buy_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                      body=buy_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.buyer, sda_order_create_url, buy_resp.status_code,
                buy_resp.json()))
            # time.sleep(3)
            sell_resp = self.sell_session.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=空单,
                                                   order_price_type=限价,
                                                   lever=lever,
                                                   order_price=deal_price,
                                                   order_num=deal_num))
            sell_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                       body=sell_resp.text)
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
                self.seller, sda_order_create_url, sell_resp.status_code,
                sell_resp.json()))

            time.sleep(1)
            # 第三个用户下多单
            three_resp = self.three_session.post(
                url=base + sda_order_create_url,
                data=get_sda_order_create_param(sda_id=sda_id,
                                                order_type=多单,
                                                order_price_type=限价,
                                                lever=lever,
                                                order_price=deal_price,
                                                order_num=deal_num))
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.three_user, sda_order_create_url, three_resp.status_code,
                three_resp.json()))

            # 买方做平多单于多单成交
            close_buy_resp = self.session.post(url=base + sda_order_create_url,
                                               data=get_sda_order_create_param(
                                                   sda_id=sda_id,
                                                   order_type=平多,
                                                   order_price_type=限价,
                                                   order_price=deal_price,
                                                   order_num=deal_num))
            logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
                self.buyer, sda_order_create_url, close_buy_resp.status_code,
                close_buy_resp.json()))
            sync_key = JMESPathExtractor().extract(query="syncLockKey",
                                                   body=close_buy_resp.text)

            buy_info_resp = account_info_sync(user=self.buyer,
                                              session=self.session,
                                              sda_id=sda_id,
                                              sync_id=sync_key)
            after_buy_balance = int(buy_info_resp["balance"])
            buy_open_cost = openStockCost(price=deal_price,
                                          count=deal_num,
                                          stockPrice=now_stock_price,
                                          doMore=True,
                                          unit=stock_unit)
            buy_close_cost = openStockCost(price=deal_price,
                                           count=deal_num,
                                           stockPrice=now_stock_price,
                                           doMore=False,
                                           unit=stock_unit)
            # print("after buy balance :", after_buy_balance)
            assert before_buy_balance, after_buy_balance + int(buy_open_cost +
                                                               buy_close_cost)
예제 #20
0
    def test_01(self):
        """
        正常访问资金划转接口,验证接口状态、status、msg
        """
        amount = 100000000
        logger.info("用例编号:2-1---资金划转接口测试类,正常访问资金划转接口,验证接口状态、status、msg")
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=self.buyer,
            currency_id=currency_id,
            balance_value=90000000000)

        # 转入前查询bb账户余额
        before_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(user=self.buyer,
                                                currency_id=currency_id))
        before_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=before_bb_account_resp.text)
        logger.info("用户:{0}---币ID:{1}---转入前余额:{2}".format(
            self.buyer, currency_id, before_currency_balance))

        # 转入前查询合约账户余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_account_balance = info_dict["balance"]

        deposit_resp = self.session.post(url=base + sda_account_deposit_url,
                                         data=get_sda_account_deposit_param(
                                             sda_id=sda_id, amount=amount))
        logger.info("用户:{0}---接口:{1}---状态:{2}---正常划转返回信息:{3}".format(
            self.buyer, sda_account_deposit_url, deposit_resp.status_code,
            deposit_resp.json()))
        status = JMESPathExtractor().extract(query="STATUS",
                                             body=deposit_resp.text)
        msg = JMESPathExtractor().extract(query="MSG", body=deposit_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=deposit_resp.text)
        print("msg:", type(msg))
        time.sleep(2)
        # 转入后查询合约账户余额
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.buyer,
                                            session=self.session,
                                            sda_id=sda_id)
        after_account_balance = after_info_dict["balance"]

        # 转入后查询BB账户余额
        # time.sleep(1)
        after_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(self.buyer,
                                                currency_id=currency_id))
        after_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=after_bb_account_resp.text)
        logger.info("用户:{0}--币ID:{1}--转入后余额:{2}".format(
            self.buyer, currency_id, after_currency_balance))
        # _object = JMESPathExtractor().extract(query="OBJECT", body=deposit_resp.text)
        print("before account balance", before_account_balance)
        print("amount:", amount)
        print("after account balance:", after_account_balance)
        flag = assert_list([200, "0"], [deposit_resp.status_code, status])
        flag_1 = assert_one(
            int(before_currency_balance) - int(amount),
            int(after_currency_balance))
        flag_2 = assert_one(
            int(before_account_balance) + int(amount),
            int(after_account_balance))
        self.assertListEqual([True, True, True], [flag, flag_1, flag_2])
예제 #21
0
    def test_04(self):
        """
        多次转入查询余额
        """
        logger.info("用例编号:02-4-多次转入查询余额")

        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=self.buyer,
            currency_id=currency_id,
            balance_value=900000000000000)

        # 转入前查询bb账户余额
        before_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(user=self.buyer,
                                                currency_id=currency_id))
        before_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=before_bb_account_resp.text)
        logger.info("用户:{0}---币ID:{1}---转入前余额:{2}".format(
            self.buyer, currency_id, before_currency_balance))

        # 转入前查询合约账户余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_account_balance = info_dict["balance"]
        sync_flag_list = []
        amount_list = []
        for i in range(200):
            amount = random.randint(1, 1000) * 100000000
            amount_list.append(amount)
            deposit_resp = self.session.post(
                url=base + sda_account_deposit_url,
                data=get_sda_account_deposit_param(sda_id=sda_id,
                                                   amount=amount))
            logger.info("用户:{0}---接口:{1}---状态:{2}---正常划转返回信息:{3}".format(
                self.buyer, sda_account_deposit_url, deposit_resp.status_code,
                deposit_resp.json()))
            # status = JMESPathExtractor().extract(query="STATUS", body=deposit_resp.text)
            # msg = JMESPathExtractor().extract(query="MSG", body=deposit_resp.text)
            sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=deposit_resp.text)
            sync_flag = sda_sync_lock(session=self.session, sync_id=sync_id)
            sync_flag_list.append(sync_flag)
            logger.info("转入次数:{}".format(i))
            time.sleep(0.1)

        # time.sleep(2)
        # 转入后查询合约账户余额
        for i in sync_flag_list:
            if "OK" != i:
                raise SyncException("sync lock 返回的不是ok!")
        else:
            after_info_dict = account_info(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
            after_account_balance = after_info_dict["balance"]

        # 转入后查询BB账户余额
        # time.sleep(1)
        after_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(self.buyer,
                                                currency_id=currency_id))
        after_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=after_bb_account_resp.text)
        logger.info("用户:{0}--币ID:{1}--转入后余额:{2}".format(
            self.buyer, currency_id, after_currency_balance))
        # _object = JMESPathExtractor().extract(query="OBJECT", body=deposit_resp.text)

        # flag = assert_list([200, "0", "SUCCESS"], [deposit_resp.status_code, status, msg])
        logger.info("用户总转入数量:{}".format(sum(amount_list)))
        logger.info("转入之前总量:{}".format(before_account_balance))
        logger.info("转入之后的总量:{}".format(after_account_balance))
        flag_1 = assert_one(
            int(before_currency_balance) - int(sum(amount_list)),
            int(after_currency_balance))
        flag_2 = assert_one(
            int(before_account_balance) + int(sum(amount_list)),
            int(after_account_balance))
        self.assertListEqual([True, True], [flag_1, flag_2])
예제 #22
0
    def test_01(self):
        """
        限价多单1单,杠杆5倍,限价空单1单,杠杆1倍,完全成交,验证合约状态、用户余额
        """
        logger.info(
            "用例编号:119-1---限价多单1单,杠杆50倍,限价空单1单,杠杆1倍,完全成交,验证保证金、开仓手续费、预估爆仓价")
        deal_num = 10 * 100000000
        lever = 50

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = int(stock_price_dict["stockPrice"])
        stock_unit = int(stock_price_dict["tradeUnit"])

        deal_price = int(int(now_stock_price) * 0.95)
        # deal_price = 18*100000000

        before_buy_dict = account_info(user=self.buyer,
                                       session=self.session,
                                       sda_id=sda_id)
        before_buy_balance = before_buy_dict["balance"]

        # 下一单多单、空单,完全成交
        buy_resp = self.session.post(url=base + sda_order_create_url,
                                     data=get_sda_order_create_param(
                                         sda_id=sda_id,
                                         order_type=多单,
                                         order_price_type=限价,
                                         lever=lever,
                                         order_price=deal_price,
                                         order_num=deal_num))
        buy_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=buy_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code,
            buy_resp.json()))
        # time.sleep(3)
        sell_resp = self.sell_session.post(url=base + sda_order_create_url,
                                           data=get_sda_order_create_param(
                                               sda_id=sda_id,
                                               order_type=空单,
                                               order_price_type=限价,
                                               lever=lever,
                                               order_price=deal_price,
                                               order_num=deal_num))
        sell_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                   body=sell_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
            self.seller, sda_order_create_url, sell_resp.status_code,
            sell_resp.json()))

        # 计算仓位保证金
        buy_employ_balance = employBalance(price=deal_price,
                                           count=deal_num,
                                           unit=stock_unit,
                                           lever=lever)
        print(buy_employ_balance)
        # 计算开仓手续费
        open_stock_cost = openStockCost(price=deal_price,
                                        count=deal_num,
                                        doMore=True,
                                        unit=stock_unit,
                                        stockPrice=now_stock_price)

        # 计算未实现盈亏
        buy_real_less = int(
            unRealLoss(holdAvgPrice=deal_price,
                       count=deal_num,
                       unit=stock_unit,
                       doMore=True,
                       holdCharge=open_stock_cost,
                       stock_price=now_stock_price))

        # 计算爆仓价
        buy_crash_price = crashPrice(holdAvgPrice=deal_price,
                                     holdCount=deal_num,
                                     totalBalance=self.sda_balance -
                                     open_stock_cost,
                                     unit=stock_unit,
                                     doMore=True)
        time.sleep(0.1)
        buy_position_get_dict = query_account_position_get(
            user=self.buyer, session=self.session, sync_key=sell_sync_id)
        buy_bust_price = int(buy_position_get_dict["sdaBustPrice"])  # 预估爆仓价
        buy_balance_position = int(
            buy_position_get_dict["currencyBalancePosition"])  # 仓位保证金
        buy_unrealized_PNL = int(
            buy_position_get_dict["unrealizedPNL"])  # 未实现盈亏

        balance_flag = assert_one(buy_balance_position,
                                  buy_employ_balance)  # 检验保证金
        bust_flag = assert_one(buy_bust_price, buy_crash_price)  # 检验爆仓
        pnl_flag = assert_one(buy_unrealized_PNL, buy_real_less)  # 检验未实现盈亏
        self.assertListEqual([True, True, True],
                             [bust_flag, pnl_flag, balance_flag])
예제 #23
0
    def test_01(self):
        """
        限价多单1单,杠杆5倍,限价空单1单,杠杆1倍,完全成交,验证合约状态、用户余额
        """
        logger.info(
            "用例编号:120-1---限价多单1单,杠杆50倍,限价空单1单,杠杆1倍,完全成交,调整股价到爆仓价,引发多单爆仓,验证是否爆仓"
        )
        deal_num = 10 * 100000000
        lever = 50

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = int(stock_price_dict["stockPrice"])
        stock_unit = int(stock_price_dict["tradeUnit"])
        print("now stock price", now_stock_price)

        deal_price = int(now_stock_price * 0.95)
        # deal_price = 18*100000000

        before_buy_dict = account_info(user=self.buyer,
                                       session=self.session,
                                       sda_id=sda_id)
        before_buy_balance = before_buy_dict["balance"]

        # 下一单多单、空单,完全成交
        buy_resp = self.session.post(url=base + sda_order_create_url,
                                     data=get_sda_order_create_param(
                                         sda_id=sda_id,
                                         order_type=多单,
                                         order_price_type=限价,
                                         lever=lever,
                                         order_price=deal_price,
                                         order_num=deal_num))
        buy_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=buy_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code,
            buy_resp.json()))
        # time.sleep(3)
        sell_resp = self.sell_session.post(url=base + sda_order_create_url,
                                           data=get_sda_order_create_param(
                                               sda_id=sda_id,
                                               order_type=空单,
                                               order_price_type=限价,
                                               lever=lever,
                                               order_price=deal_price,
                                               order_num=deal_num))
        sell_sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                   body=sell_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
            self.seller, sda_order_create_url, sell_resp.status_code,
            sell_resp.json()))

        # 计算开仓手续费
        open_stock_cost = openStockCost(price=deal_price,
                                        count=deal_num,
                                        doMore=True,
                                        unit=stock_unit,
                                        stockPrice=now_stock_price)

        # 计算爆仓价
        buy_crash_price = crashPrice(holdAvgPrice=deal_price,
                                     holdCount=deal_num,
                                     totalBalance=self.sda_balance -
                                     open_stock_cost,
                                     unit=stock_unit,
                                     doMore=True)

        print(buy_crash_price)
        # 调整股价低于多单爆仓价
        set_stock_price(stock_price=int(buy_crash_price / 10000) / 10000)
        print("_buy_crash", int(buy_crash_price / 10000) / 10000)
        time.sleep(6)
        buy_history_dict = query_order_get_history(user=self.buyer,
                                                   session=self.session)
        crash_status = buy_history_dict["orderStatus"]
        status_flag = assert_one("3", crash_status)
        self.assertTrue(status_flag)
예제 #24
0
    def test_02(self):
        """
        限价空单持仓成功,下空单委托
        """
        logger.info("用例编号:32-2---空单持仓成功,下限价空单委托,下限价多单成交,验证余额,委托状态")
        range_num = 10
        sell_num = 100000000
        buy_num = sell_num * range_num

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]

        price = int(int(now_stock_price) * 0.95)

        # 下委托前查询可用余额
        info_dict = account_info(user=self.seller,
                                 session=self.sell_session,
                                 sda_id=sda_id,
                                 price=1000000000)
        before_balance = info_dict["balance"]

        # 下空单委托
        for i in range(range_num):

            sell_order_resp = self.sell_session.post(
                url=base + sda_order_create_url,
                data=get_sda_order_create_param(sda_id=sda_id,
                                                order_type=空单,
                                                order_price_type=限价,
                                                order_price=price,
                                                order_num=sell_num))
            # time.sleep(0.1)
            logger.info("接口:{0}----返回信息:{1}".format(sda_order_create_url,
                                                    sell_order_resp.json()))

        buy_order_resp = self.session_53.post(url=base + sda_order_create_url,
                                              data=get_sda_order_create_param(
                                                  sda_id=sda_id,
                                                  order_type=多单,
                                                  order_price_type=限价,
                                                  order_price=price,
                                                  order_num=buy_num))
        logger.info("接口:{0}---返回信息:{1}".format(sda_order_create_url,
                                               buy_order_resp.json()))
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=buy_order_resp.text)

        # 下委托后查询可用余额
        # time.sleep(1)
        after_info_dict = account_info_sync(sync_id=sync_id,
                                            user=self.seller,
                                            session=self.sell_session,
                                            sda_id=sda_id,
                                            price=1000000000)
        after_balance = after_info_dict["balance"]

        flag = assert_one(int(before_balance),
                          int(after_balance) + buy_num * price / 100000000)
        self.assertTrue(flag)
예제 #25
0
    def run(self):
        buy_account_dict = account_info(user="******",
                                        session=session,
                                        sda_id=self.sda_id)
        before_buy_balance = int(buy_account_dict["balance"])
        sell_account_dict = account_info(user="******",
                                         session=self.sell_session,
                                         sda_id=self.sda_id)
        before_sell_balance = int(sell_account_dict["balance"])
        print("before buy balance :", before_buy_balance)
        print("before sell balance :", before_sell_balance)
        marker_info_dict = market_info_get(user="******",
                                           session=self.session,
                                           sda_id=self.sda_id)
        now_stock_price = int(marker_info_dict["stockPrice"])
        buy_resp = session.post(url=base + names.sda_order_create_url,
                                data=get_sda_order_create_param(
                                    sda_id=self.sda_id,
                                    order_type=names.多单,
                                    order_price_type=0,
                                    order_price=now_stock_price,
                                    order_num=100000000))
        # print("buy resp :", buy_resp.json())
        order_id = JMESPathExtractor().extract(query="OBJECT.orderId",
                                               body=buy_resp.text)
        # time.sleep(0.2)
        sell_resp = self.sell_session.post(url=base +
                                           names.sda_order_create_url,
                                           data=get_sda_order_create_param(
                                               sda_id=self.sda_id,
                                               order_type=names.空单,
                                               order_price_type=1,
                                               order_price=now_stock_price,
                                               order_num=100000000,
                                           ))
        close_buy_resp = session.post(url=base + names.sda_order_create_url,
                                      data=get_sda_order_create_param(
                                          sda_id=self.sda_id,
                                          order_type=names.平多,
                                          order_price_type=0,
                                          order_price=now_stock_price,
                                          order_num=100000000,
                                      ))
        close_sell_resp = sell_session.post(url=base +
                                            names.sda_order_create_url,
                                            data=get_sda_order_create_param(
                                                sda_id=self.sda_id,
                                                order_type=names.平空,
                                                order_price_type=1,
                                                order_price=now_stock_price,
                                                order_num=100000000,
                                            ))
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=close_sell_resp.text)
        after_buy_balance_dict = account_info_sync(user="******",
                                                   session=self.session,
                                                   sda_id=self.sda_id,
                                                   sync_id=sync_id)
        after_buy_balance = after_buy_balance_dict["balance"]

        after_sell_balance_dict = account_info(user="******",
                                               session=self.sell_session,
                                               sda_id=self.sda_id)
        after_sell_balance = after_sell_balance_dict["balance"]

        print("after buy balance :", after_buy_balance)
        print("after sell balance :", after_sell_balance)
        time.sleep(0.1)
예제 #26
0
    def test_03(self):
        """
        合约账户余额充足,随机提现多次,验证接口状态、MSG、STATUS,验证bb账户,合约账户余额
        """
        logger.info(
            "用例编号:3-3--合约账户转到币币账户接口测试类,合约账户余额充足,随机提现多次,验证接口状态、MSG、STATUS、验证Bb账户余额、合约账户余额"
        )
        sda_balance = 999999900000000
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=sda_balance)

        # 转出前查询合约账户余额
        info_dict = account_info(user=self.buyer,
                                 session=self.session,
                                 sda_id=sda_id)
        before_account_balance = info_dict["balance"]

        # 转入前查询bb账户余额
        before_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(user=self.buyer,
                                                currency_id=currency_id))
        before_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=before_bb_account_resp.text)
        logger.info("用户:{0}---币ID:{1}---转入前余额:{2}".format(
            self.buyer, currency_id, before_currency_balance))

        amount_list = []
        sync_flag_list = []
        for i in range(100):  # 循环下1000次
            amount = random.randint(1, 1000) * 100000000
            amount_list.append(amount)
            withdraw_resp = self.session.post(
                url=base + sda_account_withdraw_url,
                data=get_sda_account_withdraw_param(sda_id=sda_id,
                                                    amount=amount))
            logger.info("转出金额:{0}----接口返回信息:{1}".format(
                amount, withdraw_resp.json()))
            # msg = JMESPathExtractor().extract(query="MSG", body=withdraw_resp.text)
            # status = JMESPathExtractor().extract(query="STATUS", body=withdraw_resp.text)
            sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                                  body=withdraw_resp.text)
            sync_flag = sda_sync_lock(session=self.session, sync_id=sync_id)
            sync_flag_list.append(sync_flag)
            logger.info("转出次数:{}".format(i))
            # time.sleep(0.5)

        # 转出后查询合约账户余额
        for i in sync_flag_list:
            if "OK" != i:
                raise SyncException("sync lock 异常")
        else:
            after_info_dict = account_info(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
            after_account_balance = after_info_dict["balance"]

        # 转出后查询BB账户余额
        time.sleep(1)
        after_bb_account_resp = self.session.post(
            url=base + get_user_balance_servlet_url,
            data=get_user_balance_servlet_param(self.buyer,
                                                currency_id=currency_id))
        after_currency_balance = JMESPathExtractor().extract(
            query="OBJECT.balanceValue", body=after_bb_account_resp.text)
        logger.info("用户:{0}--币ID:{1}--转入后余额:{2}".format(
            self.buyer, currency_id, after_currency_balance))
        logger.info("转出前余额:{}".format(before_account_balance))
        logger.info("转出后余额:{}".format(after_account_balance))
        logger.info("转出总量:{}".format(sum(amount_list)))
        logger.info("转出前BB账户余额:{}".format(before_currency_balance))
        logger.info("转出后BB账户余额:{}".format(after_currency_balance))
        logger.info("转出金额列表:{}".format(amount_list))
        bb_flag = assert_one(int(before_currency_balance),
                             int(after_currency_balance) - sum(amount_list))
        sda_flag = assert_one(int(before_account_balance),
                              int(after_account_balance) + sum(amount_list))
        self.assertListEqual([True, True], [bb_flag, sda_flag])
예제 #27
0
    def test_02(self):
        """
        限价空单1单,50倍杠杆,限价多单1单,1倍杠杆,完全成交,验证合约状态、用户余额
        """
        logger.info("用例编号:110-2---限价空单1单,50倍杠杆,限价多单1单,1倍杠杆,完全成交,验证合约状态、用户余额")
        deal_num = 200000000
        lever = 50

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer, session=self.session, sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]

        deal_price = int(int(now_stock_price) * 0.95)

        # 交易前查询用户余额
        before_buy_dict = account_info(user=self.buyer, session=self.session, sda_id=sda_id)
        before_buy_balance = before_buy_dict["balance"]

        # 下一单多单、空单,完全成交
        buy_resp = self.session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id, order_type=空单, order_price_type=限价, lever=lever, order_price=deal_price,order_num=deal_num
        ))
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code, buy_resp.json()
        ))
        # time.sleep(3)
        sell_resp = self.sell_session.post(url=base+sda_order_create_url, data=get_sda_order_create_param(
            sda_id=sda_id, order_type=多单, order_price_type=限价, order_price=deal_price, order_num=deal_num
        ))
        sell_sync_id = JMESPathExtractor().extract(query="syncLockKey", body=sell_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:多单--返回信息:{3}".format(
            self.seller, sda_order_create_url, sell_resp.status_code, sell_resp.json()
        ))

        # time.sleep(1)
        # 查询当前持仓中买卖方持仓数量、保证金、开仓均价
        after_buy_position_dict = query_account_position_get(sync_key=sell_sync_id, user=self.buyer,
                                                             session=self.session)
        after_sell_position_dict = query_account_position_get(sync_key=sell_sync_id, user=self.seller,
                                                              session=self.sell_session)

        after_buy_sdaAveragePrice = after_buy_position_dict["sdaAveragePrice"]
        after_buy_sdaCount = after_buy_position_dict["sdaCount"]
        after_buy_currencyBalancePosition = after_buy_position_dict["currencyBalancePosition"]

        after_sell_sdaAveragePrice = after_sell_position_dict["sdaAveragePrice"]
        after_sell_sdaCount = after_sell_position_dict["sdaCount"]
        after_sell_currencyBalancePosition = after_sell_position_dict["currencyBalancePosition"]

        # 计算保证金
        buy_currency_balance = (deal_num * deal_price / 100000000) / lever
        # sell_currency_balance = make_currency_balance(num=deal_num, price=deal_price)

        # 检验持仓均价,持仓量,保证金
        balance_flag = assert_one(int(after_buy_currencyBalancePosition), int(buy_currency_balance))
        self.assertTrue(balance_flag)

        price_flag = assert_one(int(deal_price), int(after_buy_sdaAveragePrice))
        num_flag = assert_one(int(deal_num), int(after_buy_sdaCount))
        # after_buy_flag = assert_one(buy_currency_balance, int(after_buy_currencyBalancePosition))
        after_sell_flag = assert_list([int(deal_price), int(deal_num)], [int(after_sell_sdaAveragePrice),
                                                                         int(after_sell_sdaCount)])
        self.assertListEqual([True, True, True], [price_flag, num_flag,after_sell_flag])
예제 #28
0
    def test_02(self):
        """
        空单,验证合约状态、余额。
        """
        logger.info("用例编号:20-2---限价空单,验证合约状态、余额。")

        # 查询当前股价
        stock_price_dict = market_info_get(user=self.buyer,
                                           session=self.session,
                                           sda_id=sda_id)
        now_stock_price = stock_price_dict["stockPrice"]

        price = int(int(now_stock_price) * 0.95)

        deal_num = 100000000
        # 更新此合约ID下的所有合约状态为3
        ConnectMysql(_type=mysql_type).sda_clear_open_empty_close_multi_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectMysql(_type=mysql_type).sda_clear_open_multi_close_open_order(
            user_id=self.user_id, contract_id=sda_id, status=2)
        ConnectRedis(_type=redis_type).sda_clear_order(sda_id=sda_id)
        ConnectRedis(_type=redis_type,
                     db=4).sda_clear_user_balance(user_id=self.user_id,
                                                  keys=sda_id)
        ConnectMysql(_type=mysql_type).sda_update_user_balance(
            user_id=self.user_id, sda_id=sda_id, sda_balance=990000000000)

        # 下单前查询两个用户的余额
        account_dict = account_info(user=self.buyer,
                                    session=self.session,
                                    sda_id=sda_id)
        buy_balance = account_dict["balance"]

        # 下空单
        buy_resp = self.session.post(url=base + sda_order_create_url,
                                     data=get_sda_order_create_param(
                                         sda_id=sda_id,
                                         order_type=order_type.空单,
                                         order_price_type=order_type.限价,
                                         order_price=price,
                                         order_num=deal_num))
        buy_order_id = JMESPathExtractor().extract(query="OBJECT.orderId",
                                                   body=buy_resp.text)
        sync_id = JMESPathExtractor().extract(query="syncLockKey",
                                              body=buy_resp.text)
        logger.info("用户:{0}--接口:{1}--状态:{2}--类型:空单--返回信息:{3}".format(
            self.buyer, sda_order_create_url, buy_resp.status_code,
            buy_resp.json()))
        # 查询当前委托
        order_get_open_resp = self.session.post(
            url=base + sda_order_get_open_url,
            data=get_sda_order_get_open_param(sda_id=sda_id,
                                              order_id=buy_order_id))

        get_order_id = JMESPathExtractor().extract(
            query="LIST[0].orderId", body=order_get_open_resp.text)
        order_num = JMESPathExtractor().extract(query="LIST[0].orderQuantity",
                                                body=order_get_open_resp.text)
        order_price = JMESPathExtractor().extract(
            query="LIST[0].orderPrice", body=order_get_open_resp.text)

        # 查询用户余额,然后判断下单前后的用户余额
        after_account_dict = account_info_sync(sync_id=sync_id,
                                               user=self.buyer,
                                               session=self.session,
                                               sda_id=sda_id)
        after_account_balance = after_account_dict["balance"]

        flag = assert_one(
            int(buy_balance),
            int(after_account_balance) + deal_num * price / 100000000)
        self.assertTrue(flag)