Пример #1
0
class OrderBookTest(OrderBookHandlerBase):
    logger = Logs().getNewLogger('OrderBookTest', QoutationAsynPush.dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(OrderBookTest, self).on_recv_rsp(rsp_pb)
        #打印
        OrderBookTest.logger.info('OrderBookTest')
        OrderBookTest.logger.info(ret_code)
        OrderBookTest.logger.info(ret_data)
        return RET_OK, ret_data
Пример #2
0
class TickerTest(TickerHandlerBase):
    '''获取逐笔 get_rt_ticker 和 TickerHandlerBase'''
    logger = Logs().getNewLogger('TickerTest', QoutationAsynPush.dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(TickerTest, self).on_recv_rsp(rsp_pb)
        # 打印,记录日志
        TickerTest.logger.info('TickerTest')
        TickerTest.logger.info(ret_code)
        TickerTest.logger.info(ret_data)
        return RET_OK, ret_data
Пример #3
0
class RTDataTest(RTDataHandlerBase):
    logger = Logs().getNewLogger('RTDataTest', QoutationAsynPush.dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(RTDataTest, self).on_recv_rsp(rsp_pb)
        #打印信息
        RTDataTest.logger.info('RTDataTest')
        RTDataTest.logger.info(ret_code)
        RTDataTest.logger.info(ret_data)

        return RET_OK, ret_data
Пример #4
0
class CurKlineTest(CurKlineHandlerBase):
    '''获取实时K线 get_cur_kline 和 CurKlineHandlerBase'''
    logger = Logs().getNewLogger('CurKlineTest', QoutationAsynPush.dir)

    def on_recv_rsp(self, rsp_pb):
        ret_code, ret_data = super(CurKlineTest, self).on_recv_rsp(rsp_pb)
        # 打印,记录日志
        CurKlineTest.logger.info('CurKlineTest')
        CurKlineTest.logger.info(ret_code)
        CurKlineTest.logger.info(ret_data)
        return RET_OK, ret_data
Пример #5
0
class StockQuoteTest(StockQuoteHandlerBase):
    # 获取报价get_stock_quote和StockQuoteHandlerBase
    logger = Logs().getNewLogger('StockQuoteTest', QoutationAsynPush.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一样
        #打印,记录日志
        StockQuoteTest.logger.info('StockQuoteTest')
        StockQuoteTest.logger.info(ret_code)
        StockQuoteTest.logger.info(ret_data)
        return RET_OK, ret_data
Пример #6
0
class BrokerTest(BrokerHandlerBase):
    logger = Logs().getNewLogger('BrokerTest', QoutationAsynPush.dir)

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

        return RET_OK, ret_data
Пример #7
0
    def allStockQoutation(self):
        '''
        订阅多只股票的行情数据
        :return:
        '''
        logger = Logs().getNewLogger('allStockQoutation',
                                     QoutationAsynPush.dir)
        markets = [Market.HK, Market.US, Market.SH,
                   Market.SZ]  #,Market.HK_FUTURE,Market.US_OPTION
        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)
                    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()