def record(self, entity, start, end, size, timestamps): df = get_locked_shares([to_jq_entity_id(entity)], start_date=to_time_str(start), end_date=to_time_str(now_pd_timestamp() + timedelta(days=150))) if pd_is_not_null(df): df['locked_rate1'] = df['rate1'] * 100 df['locked_rate2'] = df['rate2'] * 100 df['locked_num'] = df['num'] df['entity_id'] = entity.id df['end_date'] = pd.to_datetime(df.day) df['timestamp'] = df['end_date'] df['provider'] = 'joinquant' df['code'] = entity.code def generate_id(se): return "{}_{}".format( se['entity_id'], to_time_str(se['timestamp'], fmt=TIME_FORMAT_DAY)) df['id'] = df[['entity_id', 'timestamp']].apply(generate_id, axis=1) df_to_db(df=df, data_schema=self.data_schema, provider=self.provider, force_update=self.force_update) return None
def record(self, entity, start, end, size, timestamps): df = finance.run_query( query(finance.STK_SHARES_PLEDGE).filter( finance.STK_SHARES_PLEDGE.code == to_jq_entity_id(entity)). filter(finance.STK_SHARES_PLEDGE.pub_date >= to_time_str(start))) if pd_is_not_null(df): df['name'] = entity.name df['entity_id'] = entity.id df['pub_date'] = pd.to_datetime(df.pub_date) df['timestamp'] = df['pub_date'] df['provider'] = 'joinquant' df['code'] = entity.code def generate_id(se): return "{}_{}_{}".format( se['entity_id'], to_time_str(se['timestamp'], fmt=TIME_FORMAT_DAY), se.name) df = pd.concat([ i.reset_index(drop=True) for i in dict(list(df.groupby('timestamp'))).values() ]) df.index += 1 df['id'] = df[['entity_id', 'timestamp']].apply(generate_id, axis=1) df_to_db(df=df, data_schema=self.data_schema, provider=self.provider, force_update=self.force_update) return None
def record(self, entity, start, end, size, timestamps): df = finance.run_query( query(finance.STK_SHAREHOLDERS_SHARE_CHANGE).filter( finance.STK_SHAREHOLDERS_SHARE_CHANGE.code == to_jq_entity_id( entity)).filter(finance.STK_SHAREHOLDERS_SHARE_CHANGE. pub_date >= to_time_str(start))) if pd_is_not_null(df): df.reset_index(inplace=True, drop=True) df['name'] = entity.name df['index_columns'] = df.index df.rename( columns={ 'pub_date': 'timestamp', # 公告日期 'end_date': 'holder_end_date', # 变动截至日期 'shareholder_name': 'holder_name', # 股东名称 'change_number': 'volume', # 变动数量 'change_ratio': 'change_pct', # 变动比例 变动数量占总股本比例(%) 'after_change_ratio': 'holding_pct', # 变动后_占总股本比例(%) 'price_ceiling': 'price', # 交易均价(元) }, inplace=True) df['entity_id'] = entity.id df['timestamp'] = pd.to_datetime(df.timestamp) df['provider'] = 'joinquant' df['code'] = entity.code df['holder_direction'] = df.type.replace(1, '减持').replace(0, '增持') def generate_id(se): return "{}_{}_{}".format( se['entity_id'], to_time_str(se['timestamp'], fmt=TIME_FORMAT_DAY), se.name) df = pd.concat([ i.reset_index(drop=True) for i in dict(list(df.groupby('timestamp'))).values() ]) df.index += 1 df['id'] = df[['entity_id', 'timestamp']].apply(generate_id, axis=1) df['holder_name'] = df['holder_name'].apply( lambda x: str(x).replace('(有限合伙)', '')) df['holder_name'] = df['holder_name'].apply( lambda x: str(x).replace('(有限合伙)', '')) df['holder_name'] = df['holder_name'].apply( lambda x: str(x).split('-')[0]) df_to_db(df=df, data_schema=self.data_schema, provider=self.provider, force_update=self.force_update) return None
def generate_id(se): return "{}_{}".format( se['entity_id'], to_time_str(se['timestamp'], fmt=TIME_FORMAT_DAY))