Ejemplo n.º 1
0
class SubK5M(object):
    '''
    订阅实时K线:5分K,股票个数:用满500个订阅额度为止
    '''
    def sub(self):
        #日志
        logger_dir = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        self.logger = Logs().getNewLogger(name=self.__class__.__name__,
                                          dir=logger_dir)
        #行情上下文实例
        quote_ctx = futuquant.OpenQuoteContext(host=host, port=port_k5)
        quote_ctx.start()
        # 设置监听
        handler = CurKlineTest()  #5分K
        handler.set_loggerDir(logger_dir)
        quote_ctx.set_handler(handler)
        #订阅
        sub_weight = 2  #订阅权重
        sub_limit = 500
        codes_len = sub_limit // sub_weight
        codes = get_codes_cvs()[0:codes_len]
        subtype = SubType.K_5M  #订阅类型
        ret_code_sub, ret_data_sub = quote_ctx.subscribe(codes, subtype)
        # 记录订阅结果
        self.logger.info('subType = ' + subtype + ' ret_code_sub = ' +
                         str(ret_code_sub) + ' ret_data_sub = ' +
                         str(ret_data_sub))
Ejemplo n.º 2
0
class OrderBookTest(OrderBookHandlerBase):
    def set_loggerDir(self, logger_dir=None):
        self.logger = Logs().getNewLogger('OrderBookTest', logger_dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(OrderBookTest, self).on_recv_rsp(rsp_pb)
        #打印
        self.logger.info('OrderBookTest')
        self.logger.info(ret_code)
        self.logger.info(ret_data)
        return RET_OK, ret_data
Ejemplo n.º 3
0
class TickerTest(TickerHandlerBase):
    '''获取逐笔 get_rt_ticker 和 TickerHandlerBase'''
    def set_loggerDir(self, logger_dir=None):
        self.logger = Logs().getNewLogger('TickerTest', logger_dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(TickerTest, self).on_recv_rsp(rsp_pb)
        # 打印,记录日志
        self.logger.info('TickerTest')
        self.logger.info(ret_code)
        self.logger.info(ret_data)
        return RET_OK, ret_data
Ejemplo n.º 4
0
class StockQuoteTest(StockQuoteHandlerBase):
    # 获取报价get_stock_quote和StockQuoteHandlerBase

    def set_loggerDir(self, logger_dir=None):
        self.logger = Logs().getNewLogger('StockQuoteTest', logger_dir)

    def on_recv_rsp(self, rsp_str):
        ret_code, ret_data = super(StockQuoteTest, self).on_recv_rsp(
            rsp_str)  # 基类的on_recv_rsp方法解包返回了报价信息,格式与get_stock_quote一样
        #打印,记录日志
        self.logger.info('StockQuoteTest')
        self.logger.info(ret_code)
        self.logger.info(ret_data)
        return RET_OK, ret_data
Ejemplo n.º 5
0
class CurKlineTest(CurKlineHandlerBase):
    '''获取实时K线 get_cur_kline 和 CurKlineHandlerBase'''

    # logger = Logs().getNewLogger('CurKlineTest', None)

    def set_loggerDir(self, logger_dir=None):
        self.logger = Logs().getNewLogger('CurKlineTest', logger_dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(CurKlineTest, self).on_recv_rsp(rsp_pb)
        # 打印,记录日志
        self.logger.info('CurKlineTest')
        self.logger.info(ret_code)
        self.logger.info(ret_data)
        return RET_OK, ret_data
Ejemplo n.º 6
0
class SubAType(object):
    '''
    压测:同时订阅500只股票的一种实时数据
    '''
    subTypes = [
        SubType.QUOTE, SubType.ORDER_BOOK, SubType.TICKER, SubType.RT_DATA,
        SubType.BROKER, SubType.K_1M, SubType.K_5M, SubType.K_15M,
        SubType.K_30M, SubType.K_60M, SubType.K_DAY, SubType.K_WEEK,
        SubType.K_MON
    ]  #

    def __init__(self):
        timestamp = (int)(time.time())
        self.dir = 'SubAType_' + str(timestamp)
        self.logger = Logs().getNewLogger('sub', self.dir)

    def sub(self, codes, subType, port):

        #行情上下文实例
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=port)
        quote_ctx.start()
        # 判断监听类型
        subType_index = SubAType.subTypes.index(subType)
        print('subType_index = %s' % subType_index)
        handler = None
        if subType_index is SubAType.subTypes.index(SubType.QUOTE):
            handler = StockQuoteTest()
        elif subType_index is SubAType.subTypes.index(SubType.ORDER_BOOK):
            handler = OrderBookTest()
        elif subType_index is SubAType.subTypes.index(SubType.TICKER):
            handler = TickerTest()
        elif subType_index is SubAType.subTypes.index(SubType.RT_DATA):
            handler = RTDataTest()
        elif subType_index is SubAType.subTypes.index(SubType.BROKER):
            handler = BrokerTest()
        else:
            handler = CurKlineTest()
        # 设置监听
        handler.set_loggerDir(self.dir)
        quote_ctx.set_handler(handler)
        # 触发订阅
        ret_code_sub, ret_data_sub = quote_ctx.subscribe(codes, subType)
        print(quote_ctx.query_subscription())
        #记录订阅结果
        self.logger.info('subType = ' + subType + ' ret_code_sub = ' +
                         str(ret_code_sub) + ' ret_data_sub = ' +
                         str(ret_data_sub))
        return ret_code_sub
Ejemplo n.º 7
0
    def allStockQoutation(self):
        '''
        订阅多只股票的行情数据
        :return:
        '''
        logger = Logs().getNewLogger('allStockQoutation',
                                     QoutationAsynPush.dir)
        markets = [Market.HK, Market.SH, Market.SZ]  #Market.US,
        stockTypes = [
            SecurityType.STOCK, SecurityType.WARRANT, SecurityType.IDX,
            SecurityType.BOND, SecurityType.ETF
        ]

        for stockType in stockTypes:
            for market in markets:
                ret_code_stock_basicinfo, ret_data_stock_basicinfo = self.quote_ctx.get_stock_basicinfo(
                    market, stockType)
                codes = ret_data_stock_basicinfo['code'].tolist()
                codes_len = len(codes)
                code_sub = 0
                code_sub_succ = 0
                for code in codes:
                    ret_code = self.aStockQoutation(code, logger)
                    code_sub += 1
                    if ret_code is RET_OK:
                        code_sub_succ += 1
                    logger.info(
                        '市场 = %s,股票类型 = %s, 股票总数 = %d, 已发起订阅 = %d,订阅成功 = %d' %
                        (market, stockType, codes_len, code_sub,
                         code_sub_succ))  # 记录
                logger.info(
                    'end-------->市场 = %s,股票类型 = %s, 股票总数 = %d, 已发起订阅 = %d,订阅成功 = %d'
                    % (market, stockType, codes_len, code_sub,
                       code_sub_succ))  # 记录

        time.sleep(5)
        self.quote_ctx.stop()
        self.quote_ctx.close()
Ejemplo n.º 8
0
class SubOrderBook(object):
    '''
    订阅实时摆盘,股票个数:用满500个订阅额度为止
    '''
    def sub(self):
        #日志
        logger_dir = time.strftime('%Y-%m-%d',time.localtime(time.time()))
        self.logger = Logs().getNewLogger(name=self.__class__.__name__,dir=logger_dir)
        #行情上下文实例
        quote_ctx = futuquant.OpenQuoteContext(host= '127.0.0.1', port= 11111)
        quote_ctx.start()
        # 设置监听
        handler = OrderBookTest()  #摆盘
        handler.set_loggerDir(logger_dir)
        quote_ctx.set_handler(handler)
        #订阅
        sub_weight = 5  #订阅权重
        sub_limit = 500
        codes_len = sub_limit//sub_weight
        codes = get_codes_cvs()[0:codes_len]
        subtype = SubType.ORDER_BOOK #订阅类型
        ret_code_sub, ret_data_sub = quote_ctx.subscribe(codes,subtype)
        # 记录订阅结果
        self.logger.info('subType = ' + subtype + ' ret_code_sub = ' + str(ret_code_sub) + ' ret_data_sub = ' + str(ret_data_sub))
Ejemplo n.º 9
0
class BrokerTest(BrokerHandlerBase):
    def set_loggerDir(self, logger_dir=None):
        self.logger = Logs().getNewLogger('BrokerTest', logger_dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, stock_code, ret_data = super(BrokerTest,
                                               self).on_recv_rsp(rsp_pb)
        #打印日志
        self.logger.info('BrokerTest')
        self.logger.info(stock_code)
        self.logger.info(ret_code)
        self.logger.info(ret_data)

        return RET_OK, ret_data
Ejemplo n.º 10
0
class MaxCodesLen(object):
    '''
    计算入参code_list的最大值
    '''
    def __init__(self):
        self.quote_ctx = futuquant.OpenQuoteContext('127.0.0.1', 11111)
        self.quote_ctx.start()
        timestamp = (int)(time.time())
        self.logger = Logs().getNewLogger(str(timestamp), 'MaxCodesLen')
        self.code_list = self.get_market_all()

    def close(self):
        self.quote_ctx.stop()
        self.quote_ctx.close()

    def test_get_autype_list(self):
        api_name = 'get_autype_list'

        index_left = 0
        index_right = len(self.code_list) - 1
        index_mid = len(self.code_list) - 1
        while (index_mid >= 0 and index_mid < len(self.code_list)):
            # 调用接口
            ret_code, ret_data = self.quote_ctx.ret_code, ret_data = self.quote_ctx.get_autype_list(
                self.code_list[0:index_mid])
            self.logger.info(api_name + ' ret_code = ' + str(ret_code) +
                             ' len(code_list)= ' + str(index_mid))
            if ret_code == RET_OK:
                if index_mid < len(
                        self.code_list) - 1 and index_left < index_right:
                    index_left = index_mid + 1
                else:
                    self.logger.info(api_name + ' 可请求成功的code_list最大长度 = ' +
                                     str(index_mid))
                    break
            else:
                index_right = index_mid - 1
            index_mid = (index_left + index_right) // 2

    def test_get_multi_points_history_kline(self):
        api_name = 'get_multi_points_history_kline'

        index_left = 0
        index_right = len(self.code_list) - 1
        index_mid = len(self.code_list) - 1
        while (index_mid >= 0 and index_mid < len(self.code_list)):
            # 调用接口
            ret_code, ret_data = self.quote_ctx.ret_code, ret_data = self.quote_ctx.get_multi_points_history_kline(
                self.code_list[0:index_mid],
                dates=['2018-5-28'],
                fields=KL_FIELD.ALL_REAL,
                ktype=KLType.K_DAY,
                autype=AuType.QFQ,
                no_data_mode=KLNoDataMode.FORWARD)
            self.logger.info(api_name + ' ret_code = ' + str(ret_code) +
                             ' len(code_list)= ' + str(index_mid))
            if ret_code == RET_OK:
                if index_mid < len(
                        self.code_list) - 1 and index_left < index_right:
                    index_left = index_mid + 1
                else:
                    self.logger.info(api_name + ' 可请求成功的code_list最大长度 = ' +
                                     str(index_mid))
                    break
            else:
                index_right = index_mid - 1
            index_mid = (index_left + index_right) // 2

    def test_subscribe(self):
        api_name = 'subscribe'

        index_left = 0
        index_right = len(self.code_list) - 1
        index_mid = len(self.code_list) - 1
        while (index_mid > 0 and index_mid < len(self.code_list)):
            # 调用接口
            ret_code, ret_data = self.quote_ctx.ret_code, ret_data = self.quote_ctx.subscribe(
                self.code_list[0:index_mid], subtype_list=[SubType.RT_DATA])
            self.logger.info(api_name + ' ret_code = ' + str(ret_code) +
                             ' len(code_list)= ' + str(index_mid))
            if ret_code == RET_OK:
                if index_mid < len(
                        self.code_list) - 1 and index_left < index_right:
                    index_left = index_mid + 1
                else:
                    self.logger.info(api_name + ' 可请求成功的code_list最大长度 = ' +
                                     str(index_mid))
                    break
            else:
                index_right = index_mid - 1
            index_mid = (index_left + index_right) // 2

    def test_get_market_snapshot(self):
        api_name = 'get_market_snapshot'

        index_left = 0
        index_right = len(self.code_list) - 1
        index_mid = len(self.code_list) - 1
        req_times = 0
        while (index_mid >= 0 and index_mid < len(self.code_list)):
            # 调用接口
            ret_code, ret_data = self.quote_ctx.ret_code, ret_data = self.quote_ctx.get_market_snapshot(
                self.code_list[0:index_mid])
            req_times += 1  #
            self.logger.info(api_name + ' ret_code = ' + str(ret_code) +
                             ' len(code_list)= ' + str(index_mid))
            if ret_code == RET_OK:
                if index_mid < len(
                        self.code_list) - 1 and index_left < index_right:
                    index_left = index_mid + 1
                else:
                    self.logger.info(api_name + ' 可请求成功的code_list最大长度 = ' +
                                     str(index_mid))
                    break
            else:
                index_right = index_mid - 1
            index_mid = (index_left + index_right) // 2

            if req_times >= 10:
                time.sleep(30)  #每30秒最多请求10次

    def test_get_stock_quote(self):
        api_name = 'get_stock_quote'

        index_left = 0
        index_right = len(self.code_list) - 1
        index_mid = len(self.code_list) - 1
        req_times = 0
        while (index_mid >= 0 and index_mid < len(self.code_list)):
            # 调用接口
            ret_code, ret_data = self.quote_ctx.ret_code, ret_data = self.quote_ctx.get_stock_quote(
                self.code_list[0:index_mid])
            req_times += 1  #
            self.logger.info(api_name + ' ret_code = ' + str(ret_code) +
                             ' len(code_list)= ' + str(index_mid))
            if ret_code == RET_OK:
                if index_mid < len(
                        self.code_list) - 1 and index_left < index_right:
                    index_left = index_mid + 1
                else:
                    self.logger.info(api_name + ' 可请求成功的code_list最大长度 = ' +
                                     str(index_mid))
                    break
            else:
                index_right = index_mid - 1
            index_mid = (index_left + index_right) // 2

            if req_times >= 10:
                time.sleep(30)  #每30秒最多请求10次

    def get_market_all(self):
        '''获取3大市场下的所有股票'''
        markets = [Market.HK, Market.SZ, Market.SH, Market.US]
        stockTypes = [
            SecurityType.STOCK, SecurityType.WARRANT, SecurityType.IDX,
            SecurityType.BOND, SecurityType.ETF
        ]
        codes = []
        for market in markets:
            for stock_type in stockTypes:
                ret_code, ret_data = self.quote_ctx.get_stock_basicinfo(
                    market=market, stock_type=stock_type)
                codes += ret_data['code'].tolist()
                # print('market = %s, stock_type = %s, len(codes) = %d'%(market, stock_type, len(ret_data['code'].tolist())))
        self.logger.info('3大市场所有股票总数 = ' + str(len(codes)))
        return codes
Ejemplo n.º 11
0
class SubQuoteTimeUse(object):
    '''
    订阅实时报价,股票个数:用满500个订阅额度为止
    '''
    def __init__(self):
        # 日志
        self.logger = Logs().getNewLogger(name=self.__class__.__name__)
        # 行情上下文实例
        self.quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1',
                                                    port=11111)
        self.quote_ctx.start()

    def close(self):
        self.quote_ctx.stop()
        self.quote_ctx.close()

    def get_stock_warrant(self):
        '''
        获取港股所有正股和涡轮
        :return: code列表
        '''
        codes = []
        types = [SecurityType.STOCK, SecurityType.WARRANT
                 ]  # , SecurityType.ETF, SecurityType.IDX, SecurityType.BOND
        for type in types:
            ret_code, ret_data = self.quote_ctx.get_stock_basicinfo(
                Market.HK, type)
            if ret_code == RET_OK:
                codes += ret_data['code'].tolist()

        return codes

    def sub_rang(self):
        codes_len = 10000  # 500, 10000
        codes = self.get_stock_warrant()[0:codes_len]
        subTypes = [SubType.QUOTE]

        start_sub = time.time() * 1000
        i = 0
        for code in codes:
            ret_code_sub, ret_data_sub = self.quote_ctx.subscribe(
                code, subTypes)  # 订阅
            print(i, ' sub ', ret_code_sub, ret_data_sub)
            i += 1

        end_sub = time.time() * 1000
        self.logger.info('start_sub = %d' % start_sub)
        self.logger.info('end_sub = %d' % end_sub)
        self.logger.info('订阅,耗时(ms) = %d' % (end_sub - start_sub))

        # 反订阅
        time.sleep(60)
        start_unsub = time.time() * 1000
        i = 0
        for code in codes:
            ret_code_unsub, ret_data_unsub = self.quote_ctx.unsubscribe(
                code, subTypes)  # 订阅
            print(i, ' unsub ', ret_code_unsub, ret_data_unsub)
            i += 1

        end_unsub = time.time() * 1000

        self.logger.info('start_unsub = %d' % start_unsub)
        self.logger.info('end_unsub = %d' % end_unsub)
        self.logger.info('反订阅,耗时(ms) = %d' % (end_unsub - start_unsub))

    def sub(self):

        # 设置监听
        # handler = StockQuoteTest()  #报价
        # handler.set_loggerDir(logger_dir)
        # quote_ctx.set_handler(handler)
        #订阅
        # sub_weight = 1  #订阅权重
        # sub_limit = 500
        codes_len = 10000
        codes = self.get_stock_warrant()[0:codes_len]
        subtype = SubType.QUOTE  #订阅类型

        start_sub = time.time() * 1000
        self.logger.info('start_sub = %d' % start_sub)
        ret_code_sub, ret_data_sub = self.quote_ctx.subscribe(codes,
                                                              subtype)  #订阅
        end_sub = time.time() * 1000
        self.logger.info('end_sub = %d' % end_sub)
        self.logger.info('订阅,耗时(ms) = %d' % (end_sub - start_sub))

        # 记录订阅结果
        self.logger.info('subType = ' + subtype + ' ret_code_sub = ' +
                         str(ret_code_sub) + ' ret_data_sub = ' +
                         str(ret_data_sub))

        time.sleep(61)
        start_unsub = time.time() * 1000
        self.logger.info('start_unsub = %d' % start_unsub)
        ret_code_unsub, ret_data_unsub = self.quote_ctx.unsubscribe(
            codes, subtype)  # 反订阅
        end_unsub = time.time() * 1000
        self.logger.info('end_unsub = %d' % end_unsub)
        self.logger.info('反订阅,耗时(ms) = %d' % (end_unsub - start_unsub))

        # 记录反订阅结果
        self.logger.info('unsubType = ' + subtype + ' ret_code_unsub = ' +
                         str(ret_code_unsub) + ' ret_data_unsub = ' +
                         str(ret_data_unsub))
        return end_sub - start_sub, end_unsub - start_unsub
Ejemplo n.º 12
0
class MaxReqPerSec(object):
    '''计算各接口每秒最大请求次数'''
    def __init__(self):
        #日志
        timestamp = (int)(time.time())
        self.logger = Logs().getNewLogger(str(timestamp), 'MaxReqPerSec')

    #行情接口
    def test_maxReqPerSec_get_stock_quote(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        code_list = ['HK.00700']
        subtype_list = [SubType.QUOTE]
        quote_ctx.subscribe(code_list=code_list, subtype_list=subtype_list)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_stock_quote(['HK.00700'])
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_stock_quote req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.unsubscribe(code_list=code_list, subtype_list=subtype_list)
        quote_ctx.close()
        self.logger.info('get_stock_quote req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_rt_ticker(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        code = 'HK.00700'
        subtype = SubType.TICKER
        quote_ctx.subscribe(code_list=code, subtype_list=subtype)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_rt_ticker(code=code)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_rt_ticker req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.unsubscribe(code_list=code, subtype_list=subtype)
        quote_ctx.close()
        self.logger.info('get_rt_ticker req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_cur_kline(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        code = 'HK.00700'
        ktype = SubType.K_DAY
        quote_ctx.subscribe(code_list=code, subtype_list=ktype)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_cur_kline(code=code,
                                                         ktype=ktype,
                                                         num=10)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_cur_kline req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.unsubscribe(code_list=code, subtype_list=ktype)
        quote_ctx.close()
        self.logger.info('get_cur_kline req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_order_book(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        code = 'HK.00700'
        ktype = SubType.ORDER_BOOK
        quote_ctx.subscribe(code_list=code, subtype_list=ktype)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_order_book(code=code)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_order_book req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.unsubscribe(code_list=code, subtype_list=ktype)
        quote_ctx.close()
        self.logger.info('get_order_book req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_rt_data(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        code = 'HK.00700'
        ktype = SubType.RT_DATA
        quote_ctx.subscribe(code_list=code, subtype_list=ktype)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_rt_data(code=code)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_rt_data req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.unsubscribe(code_list=code, subtype_list=ktype)
        quote_ctx.close()
        self.logger.info('get_rt_data req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_broker_queue(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        code = 'HK.00700'
        ktype = SubType.BROKER
        quote_ctx.subscribe(code_list=code, subtype_list=ktype)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, bid_frame_table, ask_frame_table = quote_ctx.get_broker_queue(
                code=code)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_broker_queue req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' +
                                 bid_frame_table + ask_frame_table)
        quote_ctx.unsubscribe(code_list=code, subtype_list=ktype)
        quote_ctx.close()
        self.logger.info('get_broker_queue req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_subscribe(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.subscribe(
                code_list=['HK.00700'], subtype_list=[SubType.K_1M])
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('subscribe req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('subscribe req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_unsubscribe(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)
        #获取测试股票
        stock_types = [
            SecurityType.STOCK, SecurityType.WARRANT, SecurityType.ETF,
            SecurityType.BOND, SecurityType.IDX
        ]
        codes = []
        for stock_type in stock_types:
            ret_code, ret_data = quote_ctx.get_stock_basicinfo(
                market=Market.HK, stock_type=stock_type)
            codes += ret_data['code'].tolist()
        #订阅,创造反订阅的条件
        subtype = SubType.K_1M
        quote_ctx.subscribe(code_list=codes, subtype_list=subtype)
        # time.sleep(61)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.unsubscribe(
                code_list=codes[req_times_total], subtype_list=subtype)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('unsubscribe req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('unsubscribe req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_query_subscription(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.query_subscription()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('query_subscription req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('query_subscription req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_trading_days(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_trading_days(market=Market.HK)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_trading_days req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('get_trading_days req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_stock_basicinfo(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_stock_basicinfo(
                market=Market.HK)
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_stock_basicinfo req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('get_stock_basicinfo req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_autype_list(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_autype_list(
                code_list=['HK.00700'])
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_autype_list req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('get_autype_list req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_global_state(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_global_state()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_global_state req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)

        quote_ctx.close()
        self.logger.info('get_global_state req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_history_kline(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_history_kline(code='HK.00700')
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_history_kline req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)

        quote_ctx.close()
        self.logger.info('get_history_kline req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_get_multi_points_history_kline(self):
        quote_ctx = futuquant.OpenQuoteContext(host='127.0.0.1', port=11111)

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = quote_ctx.get_multi_points_history_kline(
                code_list=['HK.00700'],
                dates=['2018-5-30 9:30:00', '2018-5-29'],
                fields=KL_FIELD.ALL_REAL,
            )
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info(
                    'get_multi_points_history_kline req_times_total = ' +
                    str(req_times_total) + ' ret_code = ' + str(ret_code) +
                    ' ret_data = ' + ret_data)
        quote_ctx.close()
        self.logger.info('get_multi_points_history_kline req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    #交易接口
    def test_maxReqPerSec_get_acc_list(self):
        trade_ctx = futuquant.OpenHKTradeContext(host='127.0.0.1', port=11111)
        trade_ctx.unlock_trade(password='******')

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = trade_ctx.get_acc_list()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('get_acc_list req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        trade_ctx.close()
        self.logger.info('get_acc_list req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_accinfo_query(self):
        trade_ctx = futuquant.OpenHKTradeContext(host='127.0.0.1', port=11111)
        trade_ctx.unlock_trade(password='******')

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = trade_ctx.accinfo_query()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('accinfo_query req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        trade_ctx.close()
        self.logger.info('accinfo_query req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_order_list_query(self):
        trade_ctx = futuquant.OpenHKTradeContext(host='127.0.0.1', port=11111)
        trade_ctx.unlock_trade(password='******')

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = trade_ctx.order_list_query()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('order_list_query req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        trade_ctx.close()
        self.logger.info('order_list_query req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_position_list_query(self):
        trade_ctx = futuquant.OpenHKTradeContext(host='127.0.0.1', port=11111)
        trade_ctx.unlock_trade(password='******')

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = trade_ctx.position_list_query()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('position_list_query req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        trade_ctx.close()
        self.logger.info('position_list_query req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))

    def test_maxReqPerSec_deal_list_query(self):
        trade_ctx = futuquant.OpenHKTradeContext(host='127.0.0.1', port=11111)
        trade_ctx.unlock_trade(password='******')

        req_times_succ = 0
        req_times_total = 0
        t_start = time.time()
        while time.time() <= (t_start + 1):
            ret_code, ret_data = trade_ctx.deal_list_query()
            req_times_total += 1
            if ret_code is RET_OK:
                req_times_succ += 1
            else:
                self.logger.info('deal_list_query req_times_total = ' +
                                 str(req_times_total) + ' ret_code = ' +
                                 str(ret_code) + ' ret_data = ' + ret_data)
        trade_ctx.close()
        self.logger.info('deal_list_query req_times_total = ' +
                         str(req_times_total) + ' req_times_succ = ' +
                         str(req_times_succ))