Ejemplo n.º 1
0
    def index(self,
              symbol='000001',
              market=MARKET_SH,
              frequency='9',
              start=1,
              offset=2):
        '''
        获取指数k线

        K线种类:
        - 0 5分钟K线
        - 1 15分钟K线
        - 2 30分钟K线
        - 3 1小时K线
        - 4 日K线
        - 5 周K线
        - 6 月K线
        - 7 1分钟
        - 8 1分钟K线
        - 9 日K线
        - 10 季K线
        - 11 年K线

        :param symbol: 股票代码
        :param frequency: 数据类别
        :param market: 证券市场
        :param start: 开始位置
        :param offset: 每次获取条数
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            result = self.client.get_index_bars(int(frequency), int(market),
                                                str(symbol), int(start),
                                                int(offset))
            return to_data(result)
Ejemplo n.º 2
0
    def markets(self):
        '''
        获取实时市场列表

        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip) as client:
            result = client.get_markets()
            return to_data(result)
Ejemplo n.º 3
0
    def stocks(self, market=MARKET_SH):
        '''
        获取股票列表

        :param market:
        :return:
        '''
        with self.client.connect(*self.bestip):
            counts = self.client.get_security_count(market=market)
            stocks = None

            for start in tqdm(range(0, counts, 1000)):
                result = self.client.get_security_list(market=market,
                                                       start=start)
                stocks = pandas.concat(
                    [stocks, to_data(result)],
                    ignore_index=True) if start > 1 else to_data(result)

            return stocks
Ejemplo n.º 4
0
    def block(self, tofile="block.dat"):
        '''
        获取证券板块信息

        :param tofile:
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            result = self.client.get_and_parse_block_info(tofile)
            return to_data(result)
Ejemplo n.º 5
0
    def minute(self, market='', symbol=''):
        '''
        查询分时行情

        :param market:
        :param symbol:
        :return:
        '''
        market, symbol = self.validate(market, symbol)
        with self.client.connect(*self.bestip):
            result = self.client.get_minute_time_data(market, symbol)
            return to_data(result)
Ejemplo n.º 6
0
    def quote(self, market='', symbol=''):
        '''
        查询五档行情

        :param market:
        :param symbol:
        :return:
        '''
        market, symbol = self.validate(market, symbol)
        with self.client.connect(*self.bestip):
            result = self.client.get_instrument_quote(market, symbol)
            return to_data(result)
Ejemplo n.º 7
0
    def instrument(self, start=0, offset=100):
        '''
        查询代码列表

        :param offset:
        :param start:
        :return:
        '''

        with self.client.connect(*self.bestip):
            result = self.client.get_instrument_info(start=start, count=offset)
            return to_data(result)
Ejemplo n.º 8
0
    def stocks(self, market=MARKET_SH, start=0):
        '''
        获取股票列表

        :param start:
        :param market:
        :return:
        '''
        with self.client.connect(*self.bestip):
            result = self.client.get_security_list(market=market, start=start)

            return to_data(result)
Ejemplo n.º 9
0
    def k(self, symbol='', begin=None, end=None):
        '''
        读取k线信息

        :param symbol:
        :param begin: 开始日期
        :param end: 截止日期
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            result = self.client.get_k_data(symbol, begin, end)
            return to_data(result)
Ejemplo n.º 10
0
    def finance(self, symbol='000001'):
        '''
        读取财务信息

        :param symbol:
        :return:
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_finance_info(market=market, code=symbol)

            return to_data(result)
Ejemplo n.º 11
0
    def xdxr(self, symbol=''):
        '''
        读取除权除息信息

        :param market: 市场代码
        :param symbol: 股票代码
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_xdxr_info(int(market), symbol)

            return to_data(result)
Ejemplo n.º 12
0
    def minute(self, symbol=''):
        '''
        获取实时分时数据

        :param market: 证券市场
        :param symbol: 股票代码
        :return: pd.DataFrame
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_minute_time_data(market=market,
                                                      code=symbol)
            return to_data(result)
Ejemplo n.º 13
0
    def minutes(self, market=None, symbol='', date=''):
        '''
        查询历史分时行情

        :param market:
        :param symbol:
        :param date:
        :return:
        '''
        market, symbol = self.validate(market, symbol)
        with self.client.connect(*self.bestip):
            result = self.client.get_history_minute_time_data(market, symbol, date)
            return to_data(result)
Ejemplo n.º 14
0
    def transaction(self, market=None, symbol='', start=0, offset=1800):
        '''
        查询分笔成交

        :param market:
        :param symbol:
        :param start:
        :param offset:
        :return:
        '''
        market, symbol = self.validate(market, symbol)
        with self.client.connect(*self.bestip):
            result = self.client.get_transaction_data(market=market, code=symbol, start=start, count=offset)
            return to_data(result)
Ejemplo n.º 15
0
    def minutes(self, symbol='', date='20191023'):
        '''
        分时历史数据

        :param market:
        :param symbol:
        :param date:
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_history_minute_time_data(
                market=market, code=symbol, date=date)

            return to_data(result)
Ejemplo n.º 16
0
    def instruments(self):
        '''
        查询所有代码列表

        :return:
        '''
        with self.client.connect(*self.bestip):
            count = self.client.get_instrument_count()
            pages = math.ceil(count / 100)
            result = []

            for page in tqdm(range(0, pages)):
                result += self.client.get_instrument_info(page * 100, (page + 1) * 100)

            return to_data(result)
Ejemplo n.º 17
0
    def index_bars(self, symbol='000001', frequency='9', start='0', offset='100'):
        '''
        获取指数k线

        :param symbol:
        :param frequency:
        :param start:
        :param offset:
        :return:
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_index_bars(
                frequency=frequency, market=market, code=symbol, start=start, count=offset)

            return to_data(result)
Ejemplo n.º 18
0
    def transaction(self, symbol='', start=0, offset=10):
        '''
        查询分笔成交

        :param market: 市场代码
        :param symbol: 股票代码
        :param start: 起始位置
        :param offset: 请求数量
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_transaction_data(int(market), symbol,
                                                      int(start), int(market))

            return to_data(result)
Ejemplo n.º 19
0
    def bars(self, frequency='', market='', symbol='', start='', offset=0):
        '''
        查询k线数据
        参数: K线周期, 市场ID, 证券代码,起始位置, 数量

        :param frequency: K线周期
        :param market: 市场ID
        :param symbol: 证券代码
        :param start: 起始位置
        :param offset: 数量
        :return:
        '''
        market, symbol = self.validate(market, symbol)
        with self.client.connect(*self.bestip):
            result = self.client.get_instrument_bars(
                frequency=frequency, market=market, code=symbol, start=start, count=offset)
            return to_data(result)
Ejemplo n.º 20
0
    def bars(self, symbol='000001', frequency='9', start='0', offset='100'):
        '''
        获取实时日K线数据

        :param symbol: 股票代码
        :param frequency: 数据类别
        :param market: 证券市场
        :param start: 开始位置
        :param offset: 每次获取条数
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol)
            result = self.client.get_security_bars(
                int(frequency), int(market), str(symbol), int(start), int(offset))

            return to_data(result)
Ejemplo n.º 21
0
    def quotes(self, symbol=None):
        '''
        获取实时日行情数据

        :param symbol: 股票代码
        :return: pd.dataFrame or None
        '''
        if not symbol:
            return None

        if type(symbol) is str:
            symbol = [symbol]

        with self.client.connect(*self.bestip):
            symbol = get_stock_markets(symbol)
            result = self.client.get_security_quotes(symbol)

            return to_data(result)
Ejemplo n.º 22
0
    def transactions(self, symbol='', start=0, offset=10, date='20170209'):
        '''
        查询历史分笔成交
        参数:市场代码, 股票代码,起始位置,日期 数量 如: 0,000001,0,10,20170209


        :param symbol: 股票代码
        :param start: 起始位置
        :param offset: 数量
        :param date: 日期
        :return: pd.dataFrame or None
        '''
        with self.client.connect(*self.bestip):
            market = get_stock_market(symbol, string=False)
            result = self.client.get_history_transaction_data(
                market=market, code=symbol, start=start, count=offset, date=date)

            return to_data(result)