示例#1
0
    def takeAllPart(self):
        """tester02申报bid,吃掉test01申报的全部ask一价"""
        ask_price_list = []
        bid_price_list = []
        ask_count_list = []
        bid_count_list = []

        ask_price = robot_fun.getAskPrice(ask_price_list)
        bid_price = robot_fun.getBidPrice(bid_price_list)
        ask_count = robot_fun.getBtcCount(ask_count_list)
        bid_count = robot_fun.getBtcCount(bid_count_list)

        #生成深度数据
        tester01_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester01,
                                                    get_basic_cfg.password)

        tester02_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester02,
                                                    get_basic_cfg.password)
        bid_amount = 0

        ask_order = {}
        bid_order = {}

        for i in range(0, 5):
            ask_req = robot_fun.takeOrder('sell', ask_price[i], ask_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester01_token)
            bid_req = robot_fun.takeOrder('buy', bid_price[i], bid_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester02_token)

            ask_order[ask_price[i]] = ask_count[i]
            bid_order[bid_price[i]] = bid_count[i]

            bid_amount = bid_amount + bid_price[i] * bid_count[i]

        sorted_ask_prices = sorted(ask_order.keys())
        sorted_bid_prices = sorted(bid_order.keys())

        ask_1_price = sorted_ask_prices[0]
        ask_2_price = sorted_ask_prices[1]
        ask_3_price = sorted_ask_prices[2]
        ask_4_price = sorted_ask_prices[3]
        ask_5_price = sorted_ask_prices[4]

        ask_1_count = ask_order[ask_1_price]
        ask_2_count = ask_order[ask_2_price]
        ask_3_count = ask_order[ask_3_price]
        ask_4_count = ask_order[ask_4_price]
        ask_5_count = ask_order[ask_5_price]

        bid_1_price = sorted_bid_prices[0]
        bid_2_price = sorted_bid_prices[1]
        bid_3_price = sorted_bid_prices[2]
        bid_4_price = sorted_bid_prices[3]
        bid_5_price = sorted_bid_prices[4]

        bid_1_count = bid_order[bid_1_price]
        bid_2_count = bid_order[bid_2_price]
        bid_3_count = bid_order[bid_3_price]
        bid_4_count = bid_order[bid_4_price]
        bid_5_count = bid_order[bid_5_price]

        print("*******当前深度图*******")
        print("--------------------------------------")
        print("----------#price#----------#count#----")
        print("    |***%f***|***%f***|" % (ask_5_price, ask_5_count))
        print("    |***%f***|***%f***|" % (ask_4_price, ask_4_count))
        print("ASK |***%f***|***%f***|" % (ask_3_price, ask_3_count))
        print("    |***%f***|***%f***|" % (ask_2_price, ask_2_count))
        print("    |***%f***|***%f***|" % (ask_1_price, ask_1_count))
        print("———————————————————————————————————————")
        print("    |***%f***|***%f***|" % (bid_5_price, bid_5_count))
        print("    |***%f***|***%f***|" % (bid_4_price, bid_4_count))
        print("BID |***%f***|***%f***|" % (bid_3_price, bid_3_count))
        print("    |***%f***|***%f***|" % (bid_2_price, bid_2_count))
        print("    |***%f***|***%f***|" % (bid_1_price, bid_1_count))
        print("--------------------------------------")
        print("--------------------------------------")

        #第一次挂卖单的总数量
        ask_count_amount = round(robot_fun.getListSum(ask_count), 3)

        # bid价格进行排序(由大到小)
        # bid_price.sort()
        # bid_price.reverse()

        #挂bid并吃ask一价的全部,二价的部分(价格大于ask二价,数量大于ask一价数量,小于ask一价二价数量和)
        deal_price = round(random.uniform(ask_2_price, 7100), 2)
        deal_count = round(
            random.uniform(ask_1_count, ask_1_count + ask_2_count), 3)

        time.sleep(3)

        next_bid_req = robot_fun.takeOrder('buy', deal_price, deal_count,
                                           get_basic_cfg.orderUrl,
                                           tester02_token)

        time.sleep(3)

        print("\n")
        print("Bid申报 价格:%f 数量:%f" % (deal_price, deal_count))

        userId = next_bid_req.json()['data']['id']
        trade_order_id = robot_fun.getTradeOrderId(userId)
        sqlstr = "select close_code,close_msg from trade_order where id = %s" % trade_order_id
        data = ctcdbUtil.execute(sqlstr)
        self.assertEqual(data[0][0], 8001, msg="验证订单状态是否正确")
        self.assertEqual(data[0][1], '撮合成功完成', msg="验证关闭消息是否正确")

        #获取挂单吃单手续费
        rate = robot_fun.getRate()
        maker_rate = rate[0]
        taker_rate = rate[1]

        #交易总价
        deal_amount = round((ask_1_price * ask_1_count) +
                            (ask_2_price * (deal_count - ask_1_count)), 5)
        print("\n")
        print("交易总价:", deal_amount)
        print("\n")
        maker_change_amount = deal_amount - deal_amount * maker_rate
        taker_change_amount = deal_count - deal_count * taker_rate

        tester01_available_BTC = round(100 - ask_count_amount, 3)

        tester01_reserved_BTC = round(ask_count_amount - deal_count, 3)

        tester01_available_USDT = round(1000000 + maker_change_amount, 8)

        tester02_available_BTC = round(100 + taker_change_amount, 8)

        tester02_available_USDT = round(
            1000000 - bid_amount - deal_price * deal_count +
            (deal_price - ask_1_price) * ask_1_count +
            (deal_price - ask_2_price) * (deal_count - ask_1_count), 5)

        tester02_reserved_USDT = round(bid_amount, 8)

        print("tester01可用btc:", tester01_available_BTC)
        print("tester01冻结btc:", tester01_reserved_BTC)
        print("tester01可用usdt:", tester01_available_USDT)
        print("tester02可用btc:", tester02_available_BTC)
        print("tester02可用usdt:", tester02_available_USDT)
        print("tester02冻结usdt:", tester02_reserved_USDT)

        tester01_BTC = ctcdbUtil.execute(get_ctcdb.search_tester01_money[0])
        tester01_USDT = ctcdbUtil.execute(get_ctcdb.search_tester01_money[1])
        tester02_BTC = ctcdbUtil.execute(get_ctcdb.search_tester02_money[0])
        tester02_USDT = ctcdbUtil.execute(get_ctcdb.search_tester02_money[1])

        self.assertEqual(float(tester01_BTC[0][0]),
                         tester01_available_BTC,
                         msg='验证tester01BTC的可用余额')
        self.assertEqual(float(tester01_BTC[0][1]),
                         tester01_reserved_BTC,
                         msg='验证tester01BTC的冻结数额')
        self.assertEqual(float(tester01_USDT[0][0]),
                         tester01_available_USDT,
                         msg='验证tester01USDT的可用余额')
        self.assertEqual(float(tester02_BTC[0][0]),
                         tester02_available_BTC,
                         msg='验证tester02BTC的可用余额')
        self.assertEqual(float(tester02_USDT[0][0]),
                         tester02_available_USDT,
                         msg='验证tester02USDT的可用余额')
        self.assertEqual(float(tester02_USDT[0][1]),
                         tester02_reserved_USDT,
                         msg='验证tester02USDT的冻结数额')

        print("\n")
        print("测试用例说明:")
        print("1.用户1挂5个ask,用户2挂5个bid,形成深度图")
        print(
            "2.用户2挂一个bid(价格大于ask二价,数量大于ask一价,小于ask一价和ask二价数量和),吃掉全部ask一价,部分ask二价"
        )
        print("3.验证第二次挂bid的订单状态")
        print("4.验证用户1和用户2的各货币金额")
示例#2
0
    def takeAllupWall(self):
        """tester01申报ask,吃掉test02申报的全部bid一价,剩余部分进入深度图"""
        ask_price_list = []
        bid_price_list = []
        ask_count_list = []
        bid_count_list = []

        ask_price = robot_fun.getAskPrice(ask_price_list)
        bid_price = robot_fun.getBidPrice(bid_price_list)
        ask_count = robot_fun.getBtcCount(ask_count_list)
        bid_count = robot_fun.getBtcCount(bid_count_list)

        #生成深度数据
        tester01_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester01,
                                                    get_basic_cfg.password)

        tester02_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester02,
                                                    get_basic_cfg.password)

        bid_amount = 0

        ask_order = {}
        bid_order = {}

        ask_req_list = []
        bid_req_list = []

        for i in range(0, 5):

            ask_req = robot_fun.takeOrder('sell', ask_price[i], ask_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester01_token)
            bid_req = robot_fun.takeOrder('buy', bid_price[i], bid_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester02_token)

            ask_order[ask_price[i]] = ask_count[i]
            bid_order[bid_price[i]] = bid_count[i]

            ask_req_list.append(ask_req)
            bid_req_list.append(bid_req)

            bid_amount = bid_amount + bid_price[i] * bid_count[i]

        sorted_ask_prices = sorted(ask_order.keys())
        sorted_bid_prices = sorted(bid_order.keys())

        ask_1_price = sorted_ask_prices[0]
        ask_2_price = sorted_ask_prices[1]
        ask_3_price = sorted_ask_prices[2]
        ask_4_price = sorted_ask_prices[3]
        ask_5_price = sorted_ask_prices[4]

        ask_1_count = ask_order[ask_1_price]
        ask_2_count = ask_order[ask_2_price]
        ask_3_count = ask_order[ask_3_price]
        ask_4_count = ask_order[ask_4_price]
        ask_5_count = ask_order[ask_5_price]

        bid_1_price = sorted_bid_prices[0]
        bid_2_price = sorted_bid_prices[1]
        bid_3_price = sorted_bid_prices[2]
        bid_4_price = sorted_bid_prices[3]
        bid_5_price = sorted_bid_prices[4]

        bid_1_count = bid_order[bid_1_price]
        bid_2_count = bid_order[bid_2_price]
        bid_3_count = bid_order[bid_3_price]
        bid_4_count = bid_order[bid_4_price]
        bid_5_count = bid_order[bid_5_price]

        print("*******当前深度图*******")
        print("--------------------------------------")
        print("----------#price#----------#count#----")
        print("    |***%f***|***%f***|" % (ask_5_price, ask_5_count))
        print("    |***%f***|***%f***|" % (ask_4_price, ask_4_count))
        print("ASK |***%f***|***%f***|" % (ask_3_price, ask_3_count))
        print("    |***%f***|***%f***|" % (ask_2_price, ask_2_count))
        print("    |***%f***|***%f***|" % (ask_1_price, ask_1_count))
        print("———————————————————————————————————————")
        print("    |***%f***|***%f***|" % (bid_5_price, bid_5_count))
        print("    |***%f***|***%f***|" % (bid_4_price, bid_4_count))
        print("BID |***%f***|***%f***|" % (bid_3_price, bid_3_count))
        print("    |***%f***|***%f***|" % (bid_2_price, bid_2_count))
        print("    |***%f***|***%f***|" % (bid_1_price, bid_1_count))
        print("--------------------------------------")
        print("--------------------------------------")

        #第一次挂卖单的总数量
        ask_count_amount = round(robot_fun.getListSum(ask_count), 3)

        # bid价格进行排序(由大到小)
        # bid_price.sort()
        # bid_price.reverse()

        #挂ask并吃bid一价的全部(价格小于bid一价,大于bid二价,数量大于bid一价数量)
        deal_price = round(random.uniform(bid_4_price, bid_5_price), 2)
        #交易价格
        deal_count = bid_5_count
        #挂单总量(交易前BTC总数)
        before_deal_count = round(random.uniform(bid_5_count, 5), 3)
        #交易后BTC剩余数量
        after_deal_count = round(before_deal_count - deal_count, 3)

        time.sleep(3)

        next_ask_req = robot_fun.takeOrder('sell', deal_price,
                                           before_deal_count,
                                           get_basic_cfg.orderUrl,
                                           tester01_token)

        time.sleep(3)

        # trade_order_id = next_ask_req.json()['data']['id']

        print("\n")
        print("Ask申报 价格:%f 数量:%f" % (deal_price, before_deal_count))

        # sqlstr = "select close_code,close_msg from trade_order where id = %d" % trade_order_id
        # data = ctcdbUtil.execute(sqlstr)
        # self.assertEqual(data[0][0], 8001, msg="验证订单状态是否正确")
        # self.assertEqual(data[0][1], '撮合成功完成', msg="验证关闭消息是否正确")

        #获取挂单吃单手续费
        rate = robot_fun.getRate()
        maker_rate = rate[0]
        taker_rate = rate[1]

        #交易总价
        deal_amount = round(deal_price * deal_count, 5)
        print("\n")
        print("交易总价:", deal_amount)
        print("\n")
        maker_change_amount = deal_count - deal_count * maker_rate
        taker_change_amount = deal_amount - deal_amount * taker_rate

        tester01_available_BTC = round(
            100 - ask_count_amount - before_deal_count, 3)

        tester01_reserved_BTC = round(ask_count_amount + after_deal_count, 3)

        tester01_available_USDT = round(1000000 + taker_change_amount, 8)

        tester02_available_BTC = round(100 + maker_change_amount, 8)

        tester02_available_USDT = round(
            1000000 - bid_amount + (bid_5_price - deal_price) * deal_count, 5)

        tester02_reserved_USDT = round(bid_amount - bid_5_price * deal_count,
                                       5)

        print("tester01可用btc:", tester01_available_BTC)
        print("tester01冻结btc:", tester01_reserved_BTC)
        print("tester01可用usdt:", tester01_available_USDT)
        print("tester02可用btc:", tester02_available_BTC)
        print("tester02可用usdt:", tester02_available_USDT)
        print("tester02冻结usdt:", tester02_reserved_USDT)

        tester01_BTC = ctcdbUtil.execute(get_ctcdb.search_tester01_money[0])
        tester01_USDT = ctcdbUtil.execute(get_ctcdb.search_tester01_money[1])
        tester02_BTC = ctcdbUtil.execute(get_ctcdb.search_tester02_money[0])
        tester02_USDT = ctcdbUtil.execute(get_ctcdb.search_tester02_money[1])

        self.assertEqual(float(tester01_BTC[0][0]),
                         tester01_available_BTC,
                         msg='验证tester01BTC的可用余额')
        self.assertEqual(float(tester01_BTC[0][1]),
                         tester01_reserved_BTC,
                         msg='验证tester01BTC的冻结数额')
        self.assertEqual(float(tester01_USDT[0][0]),
                         tester01_available_USDT,
                         msg='验证tester01USDT的可用余额')
        self.assertEqual(float(tester02_BTC[0][0]),
                         tester02_available_BTC,
                         msg='验证tester02BTC的可用余额')
        self.assertEqual(float(tester02_USDT[0][0]),
                         tester02_available_USDT,
                         msg='验证tester02USDT的可用余额')
        self.assertEqual(float(tester02_USDT[0][1]),
                         tester02_reserved_USDT,
                         msg='验证tester02USDT的冻结数额')

        print("\n")
        print("测试用例说明:")
        print("1.用户1挂5个ask,用户2挂5个bid,形成深度图")
        print("2.用户1挂一个ask(价格小于bid一价,大于bid二价,数量大于bid一价数量),吃掉全部bid一价,剩余部分上架")
        print("3.验证用户1和用户2的各货币金额")
示例#3
0
    def bidAskCancelAsk(self):
        """tester02申报bid,吃掉test01申报的ask一价一部分"""
        ask_price_list = []
        bid_price_list = []
        ask_count_list = []
        bid_count_list = []

        ask_price = robot_fun.getAskPrice(ask_price_list)
        bid_price = robot_fun.getBidPrice(bid_price_list)
        ask_count = robot_fun.getBtcCount(ask_count_list)
        bid_count = robot_fun.getBtcCount(bid_count_list)

        #生成深度数据
        tester01_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester01,
                                                    get_basic_cfg.password)

        tester02_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester02,
                                                    get_basic_cfg.password)
        bid_amount = 0

        ask_order = {}
        bid_order = {}

        for i in range(0,5):
            ask_req = robot_fun.takeOrder('sell',
                                          ask_price[i],
                                          ask_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester01_token)
            bid_req = robot_fun.takeOrder('buy',
                                          bid_price[i],
                                          bid_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester02_token)

            ask_order[ask_price[i]] = ask_count[i]
            bid_order[bid_price[i]] = bid_count[i]

            bid_amount = bid_amount + bid_price[i] * bid_count[i]

        sorted_ask_prices = sorted(ask_order.keys())
        sorted_bid_prices = sorted(bid_order.keys())

        ask_1_price = sorted_ask_prices[0]
        ask_2_price = sorted_ask_prices[1]
        ask_3_price = sorted_ask_prices[2]
        ask_4_price = sorted_ask_prices[3]
        ask_5_price = sorted_ask_prices[4]

        ask_1_count = ask_order[ask_1_price]
        ask_2_count = ask_order[ask_2_price]
        ask_3_count = ask_order[ask_3_price]
        ask_4_count = ask_order[ask_4_price]
        ask_5_count = ask_order[ask_5_price]

        bid_1_price = sorted_bid_prices[0]
        bid_2_price = sorted_bid_prices[1]
        bid_3_price = sorted_bid_prices[2]
        bid_4_price = sorted_bid_prices[3]
        bid_5_price = sorted_bid_prices[4]

        bid_1_count = bid_order[bid_1_price]
        bid_2_count = bid_order[bid_2_price]
        bid_3_count = bid_order[bid_3_price]
        bid_4_count = bid_order[bid_4_price]
        bid_5_count = bid_order[bid_5_price]

        print("*******当前深度图*******")
        print("--------------------------------------")
        print("----------#price#----------#count#----")
        print("    |***%f***|***%f***|" % (ask_5_price, ask_5_count))
        print("    |***%f***|***%f***|" % (ask_4_price, ask_4_count))
        print("ASK |***%f***|***%f***|" % (ask_3_price, ask_3_count))
        print("    |***%f***|***%f***|" % (ask_2_price, ask_2_count))
        print("    |***%f***|***%f***|" % (ask_1_price, ask_1_count))
        print("———————————————————————————————————————")
        print("    |***%f***|***%f***|" % (bid_5_price, bid_5_count))
        print("    |***%f***|***%f***|" % (bid_4_price, bid_4_count))
        print("BID |***%f***|***%f***|" % (bid_3_price, bid_3_count))
        print("    |***%f***|***%f***|" % (bid_2_price, bid_2_count))
        print("    |***%f***|***%f***|" % (bid_1_price, bid_1_count))
        print("--------------------------------------")
        print("--------------------------------------")

        #第一次挂卖单的总数量
        ask_count_amount = round(robot_fun.getListSum(ask_count),3)

        # bid价格进行排序(由大到小)
        # bid_price.sort()
        # bid_price.reverse()

        #挂bid并吃ask一价的一部分(价格大于ask一价,数量小于ask一价数量)
        deal_price = round(random.uniform(ask_1_price, 7100), 2)
        deal_count = round(random.uniform(0.001, ask_1_count), 3)

        time.sleep(3)

        next_bid_req = robot_fun.takeOrder('buy',
                                           deal_price,
                                           deal_count,
                                           get_basic_cfg.orderUrl,
                                           tester02_token)

        time.sleep(3)

        print("\n")
        print("Bid申报 价格:%f 数量:%f"%(deal_price,deal_count))

        userId = next_bid_req.json()['data']['id']
        trade_order_id = robot_fun.getTradeOrderId(userId)
        sqlstr = "select close_code,close_msg from trade_order where id = %s" % trade_order_id
        data = ctcdbUtil.execute(sqlstr)
        self.assertEqual(data[0][0], 8001, msg="验证订单状态是否正确")
        self.assertEqual(data[0][1], '撮合成功完成', msg="验证关闭消息是否正确")

        #获取挂单吃单手续费
        rate = robot_fun.getRate()
        maker_rate = rate[0]
        taker_rate = rate[1]

        #交易总价
        deal_amount = round(ask_1_price*deal_count,5)
        print("\n")
        print("交易总价:",deal_amount)
        print("\n")
        maker_change_amount = deal_amount-deal_amount * maker_rate
        taker_change_amount = deal_count-deal_count * taker_rate

        tester01_available_BTC = round(100 - ask_count_amount,3)

        tester01_reserved_BTC = round(ask_count_amount - deal_count,3)

        tester01_available_USDT = round(1000000 + maker_change_amount,8)

        tester02_available_BTC = round(100 + taker_change_amount,8)

        tester02_available_USDT = round(1000000 - bid_amount - deal_price * deal_count + (deal_price - ask_1_price) * deal_count,5)

        tester02_reserved_USDT = round(bid_amount,8)

        print("tester01可用btc:",tester01_available_BTC)
        print("tester01冻结btc:",tester01_reserved_BTC)
        print("tester01可用usdt:",tester01_available_USDT)
        print("tester02可用btc:",tester02_available_BTC)
        print("tester02可用usdt:",tester02_available_USDT)
        print("tester02冻结usdt:",tester02_reserved_USDT)

        tester01_BTC = ctcdbUtil.execute(get_ctcdb.search_tester01_money[0])
        tester01_USDT = ctcdbUtil.execute(get_ctcdb.search_tester01_money[1])
        tester02_BTC = ctcdbUtil.execute(get_ctcdb.search_tester02_money[0])
        tester02_USDT = ctcdbUtil.execute(get_ctcdb.search_tester02_money[1])

        self.assertEqual(float(tester01_BTC[0][0]), tester01_available_BTC, msg='验证tester01BTC的可用余额')
        self.assertEqual(float(tester01_BTC[0][1]), tester01_reserved_BTC, msg='验证tester01BTC的冻结数额')
        self.assertEqual(float(tester01_USDT[0][0]), tester01_available_USDT, msg='验证tester01USDT的可用余额')
        self.assertEqual(float(tester02_BTC[0][0]), tester02_available_BTC, msg='验证tester02BTC的可用余额')
        self.assertEqual(float(tester02_USDT[0][0]), tester02_available_USDT, msg='验证tester02USDT的可用余额')
        self.assertEqual(float(tester02_USDT[0][1]), tester02_reserved_USDT, msg='验证tester02USDT的冻结数额')

        # 获取需要撤单的orderid
        search_orderid_sql = "select id from trade_order where price = %f and count = %f and status != 9000" % (ask_1_price, ask_1_count)
        cancel_orderid_data = ctcdbUtil.execute(search_orderid_sql)
        cancel_orderid = cancel_orderid_data[0][0]
        print("\n")
        print("撤单的id:", cancel_orderid)

        cancel_req = robot_fun.cancelOrder(get_basic_cfg.cancelOrderUrl, cancel_orderid, "订单备注", tester01_token)

        sqlstr = "select status from trade_order where id = %d" % cancel_orderid
        data = ctcdbUtil.execute(sqlstr)
        self.assertEqual(data[0][0], 8400, msg="验证订单状态是否正确")
        self.assertEqual(cancel_req.json()['msg'], 'success', msg="验证是否撤单成功")

        # 再次验证tester01的BTC
        tester01_BTC = ctcdbUtil.execute(get_ctcdb.search_tester01_money[0])
        tester01_available_BTC = round(100 - ask_count_amount + (ask_1_count - deal_count), 3)
        tester01_reserved_BTC = round(ask_count_amount - ask_1_count, 3)

        self.assertEqual(float(tester01_BTC[0][0]), tester01_available_BTC, msg='验证tester01BTC的可用余额')
        self.assertEqual(float(tester01_BTC[0][1]), tester01_reserved_BTC, msg='验证tester01BTC的冻结数额')

        print("\n")
        print("撤单后的各账户货币数量:")
        print("\n")
        print("tester01可用btc:",tester01_available_BTC)
        print("tester01冻结btc:",tester01_reserved_BTC)
        print("tester01可用usdt:",tester01_available_USDT)
        print("tester02可用btc:",tester02_available_BTC)
        print("tester02可用usdt:",tester02_available_USDT)
        print("tester02冻结usdt:",tester02_reserved_USDT)

        print("\n")
        print("测试用例说明:")
        print("1.用户1挂5个ask,用户2挂5个bid,形成深度图")
        print("2.用户2挂一个bid(价格大于ask一价,数量小于ask一价数量),吃掉部分ask一价")
        print("3.用户1部分成交的ask挂单进行撤单")
        print("4.验证用户2第二次挂单的订单状态")
        print("5.验证用户1撤单的订单状态")
        print("6.验证用户1和用户2的各货币金额")
示例#4
0
    def twoAskEatOnebid(self):
        """tester01申报2个ask,吃掉test02申报的全部bid一价"""
        ask_price_list = []
        bid_price_list = []
        ask_count_list = []
        bid_count_list = []

        ask_price = robot_fun.getAskPrice(ask_price_list)
        bid_price = robot_fun.getBidPrice(bid_price_list)
        ask_count = robot_fun.getBtcCount(ask_count_list)
        bid_count = robot_fun.getBtcCount(bid_count_list)

        #生成深度数据
        tester01_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester01,
                                                    get_basic_cfg.password)

        tester02_token = robot_fun.get_access_token(get_basic_cfg.loginUrl,
                                                    get_basic_cfg.tester02,
                                                    get_basic_cfg.password)
        bid_amount = 0

        ask_order = {}
        bid_order = {}

        for i in range(0, 5):
            ask_req = robot_fun.takeOrder('sell', ask_price[i], ask_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester01_token)
            bid_req = robot_fun.takeOrder('buy', bid_price[i], bid_count[i],
                                          get_basic_cfg.orderUrl,
                                          tester02_token)

            ask_order[ask_price[i]] = ask_count[i]
            bid_order[bid_price[i]] = bid_count[i]

            bid_amount = bid_amount + bid_price[i] * bid_count[i]

        sorted_ask_prices = sorted(ask_order.keys())
        sorted_bid_prices = sorted(bid_order.keys())

        ask_1_price = sorted_ask_prices[0]
        ask_2_price = sorted_ask_prices[1]
        ask_3_price = sorted_ask_prices[2]
        ask_4_price = sorted_ask_prices[3]
        ask_5_price = sorted_ask_prices[4]

        ask_1_count = ask_order[ask_1_price]
        ask_2_count = ask_order[ask_2_price]
        ask_3_count = ask_order[ask_3_price]
        ask_4_count = ask_order[ask_4_price]
        ask_5_count = ask_order[ask_5_price]

        bid_1_price = sorted_bid_prices[0]
        bid_2_price = sorted_bid_prices[1]
        bid_3_price = sorted_bid_prices[2]
        bid_4_price = sorted_bid_prices[3]
        bid_5_price = sorted_bid_prices[4]

        bid_1_count = bid_order[bid_1_price]
        bid_2_count = bid_order[bid_2_price]
        bid_3_count = bid_order[bid_3_price]
        bid_4_count = bid_order[bid_4_price]
        bid_5_count = bid_order[bid_5_price]

        print("*******当前深度图*******")
        print("--------------------------------------")
        print("----------#price#----------#count#----")
        print("    |***%f***|***%f***|" % (ask_5_price, ask_5_count))
        print("    |***%f***|***%f***|" % (ask_4_price, ask_4_count))
        print("ASK |***%f***|***%f***|" % (ask_3_price, ask_3_count))
        print("    |***%f***|***%f***|" % (ask_2_price, ask_2_count))
        print("    |***%f***|***%f***|" % (ask_1_price, ask_1_count))
        print("———————————————————————————————————————")
        print("    |***%f***|***%f***|" % (bid_5_price, bid_5_count))
        print("    |***%f***|***%f***|" % (bid_4_price, bid_4_count))
        print("BID |***%f***|***%f***|" % (bid_3_price, bid_3_count))
        print("    |***%f***|***%f***|" % (bid_2_price, bid_2_count))
        print("    |***%f***|***%f***|" % (bid_1_price, bid_1_count))
        print("--------------------------------------")
        print("--------------------------------------")

        #第一次挂卖单的总数量
        ask_count_amount = round(robot_fun.getListSum(ask_count), 3)

        # bid价格进行排序(由大到小)
        # bid_price.sort()
        # bid_price.reverse()

        #挂两个价格的Ask,小于买一大于买二
        deal_price_1 = round(random.uniform(bid_4_price, bid_5_price), 2)
        deal_price_2 = round(random.uniform(bid_4_price, bid_5_price), 2)
        deal_count_1 = round(random.uniform(0.001, bid_5_count), 3)
        deal_count_2 = round(bid_5_count - deal_count_1, 3)

        time.sleep(3)

        ask_req_1 = robot_fun.takeOrder('sell', deal_price_1, deal_count_1,
                                        get_basic_cfg.orderUrl, tester01_token)

        ask_req_2 = robot_fun.takeOrder('sell', deal_price_2, deal_count_2,
                                        get_basic_cfg.orderUrl, tester01_token)
        time.sleep(3)

        print("\n")
        print("Ask申报1 价格:%f 数量:%f" % (deal_price_1, deal_count_1))
        print("\n")
        print("Ask申报2 价格:%f 数量:%f" % (deal_price_2, deal_count_2))

        userId_1 = ask_req_1.json()['data']['id']
        trade_order_id_1 = robot_fun.getTradeOrderId(userId_1)
        sqlstr1 = "select close_code,close_msg from trade_order where id = %s" % trade_order_id_1

        userId_2 = ask_req_2.json()['data']['id']
        trade_order_id_2 = robot_fun.getTradeOrderId(userId_2)
        sqlstr2 = "select close_code,close_msg from trade_order where id = %s" % trade_order_id_2

        data1 = ctcdbUtil.execute(sqlstr1)
        data2 = ctcdbUtil.execute(sqlstr2)

        self.assertEqual(data1[0][0], 8001, msg="验证订单状态是否正确")
        self.assertEqual(data1[0][1], '撮合成功完成', msg="验证关闭消息是否正确")

        self.assertEqual(data2[0][0], 8001, msg="验证订单状态是否正确")
        self.assertEqual(data2[0][1], '撮合成功完成', msg="验证关闭消息是否正确")

        #获取挂单吃单手续费
        rate = robot_fun.getRate()
        maker_rate = rate[0]
        taker_rate = rate[1]

        #交易总价
        deal_amount = round(
            deal_price_1 * deal_count_1 + deal_price_2 * deal_count_2, 5)
        print("\n")
        print("交易总价:", deal_amount)
        print("\n")

        maker_change_amount = bid_5_count - bid_5_count * maker_rate
        taker_change_amount = deal_amount - deal_amount * taker_rate

        tester01_available_BTC = round(100 - ask_count_amount - bid_5_count, 3)

        tester01_reserved_BTC = ask_count_amount

        tester01_available_USDT = round(1000000 + taker_change_amount, 8)

        tester02_available_BTC = round(100 + maker_change_amount, 8)

        tester02_available_USDT = round(
            1000000 - bid_amount +
            (bid_5_price - deal_price_1) * deal_count_1 +
            (bid_5_price - deal_price_2) * deal_count_2, 5)

        tester02_reserved_USDT = round(bid_amount - bid_5_price * bid_5_count,
                                       5)

        print("tester01可用btc:", tester01_available_BTC)
        print("tester01冻结btc:", tester01_reserved_BTC)
        print("tester01可用usdt:", tester01_available_USDT)
        print("tester02可用btc:", tester02_available_BTC)
        print("tester02可用usdt:", tester02_available_USDT)
        print("tester02冻结usdt:", tester02_reserved_USDT)

        tester01_BTC = ctcdbUtil.execute(get_ctcdb.search_tester01_money[0])
        tester01_USDT = ctcdbUtil.execute(get_ctcdb.search_tester01_money[1])
        tester02_BTC = ctcdbUtil.execute(get_ctcdb.search_tester02_money[0])
        tester02_USDT = ctcdbUtil.execute(get_ctcdb.search_tester02_money[1])

        self.assertEqual(float(tester01_BTC[0][0]),
                         tester01_available_BTC,
                         msg='验证tester01BTC的可用余额')
        self.assertEqual(float(tester01_BTC[0][1]),
                         tester01_reserved_BTC,
                         msg='验证tester01BTC的冻结数额')
        self.assertEqual(float(tester01_USDT[0][0]),
                         tester01_available_USDT,
                         msg='验证tester01USDT的可用余额')
        self.assertEqual(float(tester02_BTC[0][0]),
                         tester02_available_BTC,
                         msg='验证tester02BTC的可用余额')
        self.assertEqual(float(tester02_USDT[0][0]),
                         tester02_available_USDT,
                         msg='验证tester02USDT的可用余额')
        self.assertEqual(float(tester02_USDT[0][1]),
                         tester02_reserved_USDT,
                         msg='验证tester02USDT的冻结数额')

        print("\n")
        print("测试用例说明:")
        print("1.用户1挂5个ask,用户2挂5个bid,形成深度图")
        print("2.用户1挂一个ask(价格小于bid一价,数量小于bid一价数量),吃掉部分bid一价")
        print("3.用户1挂一个ask(价格小于bid一价,数量等于剩余bid一价数量),吃掉剩余bid一价")
        print("4.验证后面两次挂ask的订单状态")
        print("5.验证用户1和用户2的各货币金额")