def ts_index_basic(self, market_code: str) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().index_basic( market=market_code, fields= 'ts_code,name,fullname,market,publisher,index_type,category,base_date,base_point,list_date,weight_rule,desc,exp_date' ) df['list_date'] = df['list_date'].apply(lambda x: to_datetime64(x)) df['exp_date'] = df['exp_date'].apply(lambda x: to_datetime64(x)) logging.info(colorama.Fore.YELLOW + '下载 %s [指数基本信息] 数据, 共 %s 条' % (self.index_markets[market_code], df.shape[0])) return df
def ts_pledge_detail(self) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().pledge_detail( ts_code = self.stock_code, fields = 'ts_code,ann_date,holder_name,pledge_amount,start_date,end_date,is_release,release_date,pledgor,holding_amount,pledged_amount,p_total_ratio,h_total_ratio,is_buyback' ) if not df.empty: df['ann_date'] = df['ann_date'].apply(lambda x: to_datetime64(x)) df['start_date'] = df['start_date'].apply(lambda x: to_datetime64(x)) df['end_date'] = df['end_date'].apply(lambda x: to_datetime64(x)) df['release_date'] = df['release_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by = 'end_date', inplace = True) logging.info(colorama.Fore.YELLOW + '下载 %s [股权质押明细] 数据 共 %s 条' % (self.stock_code, df.shape[0])) else: logging.info(colorama.Fore.YELLOW + '%s [股权质押明细] 无最新数据' % self.stock_code) return df
def ts_top_inst(trade_date: date) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().top_inst( trade_date=ts_date(trade_date), ) df['trade_date'] = df['trade_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by='trade_date', inplace=True) logging.info(colorama.Fore.YELLOW + '下载 [龙虎榜机构明细] 数据: %s, %s 条' % (trade_date, df.shape[0])) return df
def ts_top10_holders(self, start_date: date, end_date: date) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().top10_holders( ts_code=self.stock_code, start_date=ts_date(start_date), end_date=ts_date(end_date)) if not df.empty: df['ann_date'] = df['ann_date'].apply(lambda x: to_datetime64(x)) df['end_date'] = df['end_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by='end_date', inplace=True) logging.info(colorama.Fore.YELLOW + '下载 %s 前十大股东数据: %s -- %s, 共 %s 条' % (self.stock_code, start_date, end_date, df.shape[0])) else: logging.info(colorama.Fore.YELLOW + '%s 前十大股东数据: %s -- %s 无数据' % (self.stock_code, start_date, end_date)) return df
def ts_margin_detail(trade_date: date) -> pd.DataFrame: # 只取1个交易日的数据, 以保证数据记录数不会超过上限(经过测试观察为 2000 条) df: pd.DataFrame = ts_pro_api().margin_detail( start_date=ts_date(trade_date), end_date=ts_date(trade_date)) df['trade_date'] = df['trade_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by='trade_date', inplace=True) logging.info(colorama.Fore.YELLOW + '下载 [融资融券交易明细] %s 数据: 共 %s 条' % (trade_date, df.shape[0])) return df
def ts_margin(start_date: date, end_date: date) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().margin(start_date=ts_date(start_date), end_date=ts_date(end_date)) df['trade_date'] = df['trade_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by='trade_date', inplace=True) logging.info(colorama.Fore.YELLOW + '下载 [融资融券每日交易汇总] 数据: %s - %s, 共 %s 条' % (start_date, end_date, df.shape[0])) return df
def ts_suspend(self) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().suspend( ts_code=self.stock_code, fields= 'ts_code,suspend_date,resume_date,ann_date,suspend_reason,reason_type' ) if not df.empty: df['suspend_date'] = df['suspend_date'].apply( lambda x: to_datetime64(x)) df['resume_date'] = df['resume_date'].apply( lambda x: to_datetime64(x)) df['ann_date'] = df['ann_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by='ann_date', inplace=True) logging.info(colorama.Fore.YELLOW + '下载 %s [停复牌信息] 数据 共 %s 条' % (self.stock_code, df.shape[0])) else: logging.info(colorama.Fore.YELLOW + '%s [停复牌信息] 数据: 无数据' % self.stock_code) return df
def ts_pledge_stat(self) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().pledge_stat( ts_code = self.stock_code, fields = 'ts_code,end_date,pledge_count,unrest_pledge,rest_pledge,total_share,pledge_ratio' ) if not df.empty: df['end_date'] = df['end_date'].apply(lambda x: to_datetime64(x)) df.sort_values(by = 'end_date', inplace = True) logging.info(colorama.Fore.YELLOW + '下载 %s [股权质押统计] 数据 共 %s 条' % (self.stock_code, df.shape[0])) else: logging.info(colorama.Fore.YELLOW + '%s [股权质押统计] 无最新数据' % self.stock_code) return df
def ts_top10_holders(self, start_date: date, end_date: date) -> pd.DataFrame: df: pd.DataFrame = ts_pro_api().stk_holdertrade( ts_code=self.stock_code, start_date=ts_date(start_date), end_date=ts_date(end_date), fields= 'ts_code,ann_date,holder_name,holder_type,in_de,change_vol,change_ratio,after_share,after_ratio,avg_price,total_share,begin_date,close_date' ) if not df.empty: df['ann_date'] = df['ann_date'].apply(lambda x: to_datetime64(x)) df['begin_date'] = df['begin_date'].apply( lambda x: to_datetime64(x)) df['close_date'] = df['close_date'].apply( lambda x: to_datetime64(x)) df.sort_values(by='ann_date', inplace=True) logging.info(colorama.Fore.YELLOW + '下载 %s [股东增减持] 数据: %s -- %s, 共 %s 条' % (self.stock_code, start_date, end_date, df.shape[0])) else: logging.info(colorama.Fore.YELLOW + '%s [股东增减持] 数据: %s -- %s 无数据' % (self.stock_code, start_date, end_date)) return df