From 56b744c28aaa2d2b3b30721b5b5677f1ce7684d0 Mon Sep 17 00:00:00 2001 From: foolcage <5533061@qq.com> Date: Fri, 27 Oct 2023 18:13:57 +0800 Subject: [PATCH] Support exchange bj for Stock and China time utils --- examples/utils.py | 4 +- examples/zhdate/__init__.py | 1 + examples/zhdate/constants.py | 424 ++++++++++++++++++ examples/zhdate/zhdate.py | 257 +++++++++++ examples/ztime.py | 66 +++ src/zvt/api/selector.py | 4 +- src/zvt/api/utils.py | 5 +- src/zvt/contract/__init__.py | 4 +- src/zvt/recorders/em/em_api.py | 15 +- .../em/meta/em_stock_meta_recorder.py | 2 +- .../em/news/em_stock_news_recorder.py | 5 +- .../recorders/em/quotes/em_kdata_recorder.py | 6 +- 12 files changed, 779 insertions(+), 14 deletions(-) create mode 100644 examples/zhdate/__init__.py create mode 100644 examples/zhdate/constants.py create mode 100644 examples/zhdate/zhdate.py create mode 100644 examples/ztime.py diff --git a/examples/utils.py b/examples/utils.py index 9923fdc4..d2f6f58d 100644 --- a/examples/utils.py +++ b/examples/utils.py @@ -43,7 +43,7 @@ def count_hot_words(text: str): for topic in hot_words_config: topic_count = 0 for word in hot_words_config[topic]: - word_stats[word] = text.count(word) + word_stats[word] = text.lower().count(word) topic_count = topic_count + word_stats[word] topic_stats[topic] = topic_count return topic_stats, word_stats @@ -104,7 +104,7 @@ def group_stocks_by_topic( word_count.setdefault(words, 0) count = 0 for word in words.split(","): - count = text.count(word) + count + count = text.lower().count(word) + count if count >= threshold: word_count[words] = word_count[words] + 1 topic_count[topic] = topic_count[topic] + 1 diff --git a/examples/zhdate/__init__.py b/examples/zhdate/__init__.py new file mode 100644 index 00000000..40a96afc --- /dev/null +++ b/examples/zhdate/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/examples/zhdate/constants.py b/examples/zhdate/constants.py new file mode 100644 index 00000000..94e50a65 --- /dev/null +++ b/examples/zhdate/constants.py @@ -0,0 +1,424 @@ +# -*- coding: utf-8 -*- +CHINESEYEARCODE = [ + 19416, + 19168, + 42352, + 21717, + 53856, + 55632, + 91476, + 22176, + 39632, + 21970, + 19168, + 42422, + 42192, + 53840, + 119381, + 46400, + 54944, + 44450, + 38320, + 84343, + 18800, + 42160, + 46261, + 27216, + 27968, + 109396, + 11104, + 38256, + 21234, + 18800, + 25958, + 54432, + 59984, + 92821, + 23248, + 11104, + 100067, + 37600, + 116951, + 51536, + 54432, + 120998, + 46416, + 22176, + 107956, + 9680, + 37584, + 53938, + 43344, + 46423, + 27808, + 46416, + 86869, + 19872, + 42416, + 83315, + 21168, + 43432, + 59728, + 27296, + 44710, + 43856, + 19296, + 43748, + 42352, + 21088, + 62051, + 55632, + 23383, + 22176, + 38608, + 19925, + 19152, + 42192, + 54484, + 53840, + 54616, + 46400, + 46752, + 103846, + 38320, + 18864, + 43380, + 42160, + 45690, + 27216, + 27968, + 44870, + 43872, + 38256, + 19189, + 18800, + 25776, + 29859, + 59984, + 27480, + 23232, + 43872, + 38613, + 37600, + 51552, + 55636, + 54432, + 55888, + 30034, + 22176, + 43959, + 9680, + 37584, + 51893, + 43344, + 46240, + 47780, + 44368, + 21977, + 19360, + 42416, + 86390, + 21168, + 43312, + 31060, + 27296, + 44368, + 23378, + 19296, + 42726, + 42208, + 53856, + 60005, + 54576, + 23200, + 30371, + 38608, + 19195, + 19152, + 42192, + 118966, + 53840, + 54560, + 56645, + 46496, + 22224, + 21938, + 18864, + 42359, + 42160, + 43600, + 111189, + 27936, + 44448, + 84835, + 37744, + 18936, + 18800, + 25776, + 92326, + 59984, + 27296, + 108228, + 43744, + 37600, + 53987, + 51552, + 54615, + 54432, + 55888, + 23893, + 22176, + 42704, + 21972, + 21200, + 43448, + 43344, + 46240, + 46758, + 44368, + 21920, + 43940, + 42416, + 21168, + 45683, + 26928, + 29495, + 27296, + 44368, + 84821, + 19296, + 42352, + 21732, + 53600, + 59752, + 54560, + 55968, + 92838, + 22224, + 19168, + 43476, + 41680, + 53584, + 62034, + 54560, +] +""" +从1900年到2100年的农历月份数据代码 20位二进制代码表示一个年份的数据。 + +前四位0:表示闰月为29天,1:表示闰月为30天 +中间12位:从左起表示1-12月每月的大小,1为30天,0为29天 +最后四位:表示闰月的月份,0表示当年无闰月 + +前四位和最后四位应该结合使用,如果最后四位为0,则不考虑前四位 +例: +1901年代码为 19168,转成二进制为 0b100101011100000, 最后四位为0,当年无闰月,月份数据为 010010101110 分别代表12月的大小情况 +1903年代码为 21717,转成二进制为 0b101010011010101,最后四位为5,当年为闰五月,首四位为0,闰月为29天,月份数据为 010101001101 分别代表12月的大小情况 + +""" + +CHINESENEWYEAR = [ + "19000131", + "19010219", + "19020208", + "19030129", + "19040216", + "19050204", + "19060125", + "19070213", + "19080202", + "19090122", + "19100210", + "19110130", + "19120218", + "19130206", + "19140126", + "19150214", + "19160203", + "19170123", + "19180211", + "19190201", + "19200220", + "19210208", + "19220128", + "19230216", + "19240205", + "19250124", + "19260213", + "19270202", + "19280123", + "19290210", + "19300130", + "19310217", + "19320206", + "19330126", + "19340214", + "19350204", + "19360124", + "19370211", + "19380131", + "19390219", + "19400208", + "19410127", + "19420215", + "19430205", + "19440125", + "19450213", + "19460202", + "19470122", + "19480210", + "19490129", + "19500217", + "19510206", + "19520127", + "19530214", + "19540203", + "19550124", + "19560212", + "19570131", + "19580218", + "19590208", + "19600128", + "19610215", + "19620205", + "19630125", + "19640213", + "19650202", + "19660121", + "19670209", + "19680130", + "19690217", + "19700206", + "19710127", + "19720215", + "19730203", + "19740123", + "19750211", + "19760131", + "19770218", + "19780207", + "19790128", + "19800216", + "19810205", + "19820125", + "19830213", + "19840202", + "19850220", + "19860209", + "19870129", + "19880217", + "19890206", + "19900127", + "19910215", + "19920204", + "19930123", + "19940210", + "19950131", + "19960219", + "19970207", + "19980128", + "19990216", + "20000205", + "20010124", + "20020212", + "20030201", + "20040122", + "20050209", + "20060129", + "20070218", + "20080207", + "20090126", + "20100214", + "20110203", + "20120123", + "20130210", + "20140131", + "20150219", + "20160208", + "20170128", + "20180216", + "20190205", + "20200125", + "20210212", + "20220201", + "20230122", + "20240210", + "20250129", + "20260217", + "20270206", + "20280126", + "20290213", + "20300203", + "20310123", + "20320211", + "20330131", + "20340219", + "20350208", + "20360128", + "20370215", + "20380204", + "20390124", + "20400212", + "20410201", + "20420122", + "20430210", + "20440130", + "20450217", + "20460206", + "20470126", + "20480214", + "20490202", + "20500123", + "20510211", + "20520201", + "20530219", + "20540208", + "20550128", + "20560215", + "20570204", + "20580124", + "20590212", + "20600202", + "20610121", + "20620209", + "20630129", + "20640217", + "20650205", + "20660126", + "20670214", + "20680203", + "20690123", + "20700211", + "20710131", + "20720219", + "20730207", + "20740127", + "20750215", + "20760205", + "20770124", + "20780212", + "20790202", + "20800122", + "20810209", + "20820129", + "20830217", + "20840206", + "20850126", + "20860214", + "20870203", + "20880124", + "20890210", + "20900130", + "20910218", + "20920207", + "20930127", + "20940215", + "20950205", + "20960125", + "20970212", + "20980201", + "20990121", + "21000209", +] +""" +从1900年,至2100年每年的农历春节的公历日期 +""" diff --git a/examples/zhdate/zhdate.py b/examples/zhdate/zhdate.py new file mode 100644 index 00000000..2fa68b42 --- /dev/null +++ b/examples/zhdate/zhdate.py @@ -0,0 +1,257 @@ +""" +-*- coding: utf-8 -*- +thanks to https://github.com/CutePandaSh/zhdate +""" +from datetime import datetime, timedelta +from itertools import accumulate + +from examples.zhdate.constants import CHINESEYEARCODE, CHINESENEWYEAR + + +class ZhDate: + def __init__(self, lunar_year, lunar_month, lunar_day, leap_month=False): + """初始化函数 + + Arguments: + lunar_year {int} -- 农历年 + lunar_month {int} -- 农历月份 + lunar_day {int} -- 农历日 + + Keyword Arguments: + leap_month {bool} -- 是否是在农历闰月中 (default: {False}) + """ + self.lunar_year = lunar_year + self.lunar_month = lunar_month + self.lunar_day = lunar_day + self.leap_month = leap_month + self.year_code = CHINESEYEARCODE[self.lunar_year - 1900] + self.newyear = datetime.strptime(CHINESENEWYEAR[self.lunar_year - 1900], "%Y%m%d") + if not ZhDate.validate(lunar_year, lunar_month, lunar_day, leap_month): + raise TypeError("农历日期不支持所谓“{}”,超出农历1900年1月1日至2100年12月29日,或日期不存在".format(self)) + + def to_datetime(self): + """农历日期转换称公历日期 + + Returns: + datetime -- 当前农历对应的公历日期 + """ + return self.newyear + timedelta(days=self.__days_passed()) + + @staticmethod + def from_datetime(dt): + """静态方法,从公历日期生成农历日期 + + Arguments: + dt {datetime} -- 公历的日期 + + Returns: + ZhDate -- 生成的农历日期对象 + """ + lunar_year = dt.year + # 如果还没有到农历正月初一 农历年份减去1 + lunar_year -= (datetime.strptime(CHINESENEWYEAR[lunar_year - 1900], "%Y%m%d") - dt).total_seconds() > 0 + # 当时农历新年时的日期对象 + newyear_dt = datetime.strptime(CHINESENEWYEAR[lunar_year - 1900], "%Y%m%d") + # 查询日期距离当年的春节差了多久 + days_passed = (dt - newyear_dt).days + # 被查询日期的年份码 + year_code = CHINESEYEARCODE[lunar_year - 1900] + # 取得本年的月份列表 + month_days = ZhDate.decode(year_code) + + for pos, days in enumerate(accumulate(month_days)): + if days_passed + 1 <= days: + month = pos + 1 + lunar_day = month_days[pos] - (days - days_passed) + 1 + break + + leap_month = False + if (year_code & 0xF) == 0 or month <= (year_code & 0xF): + lunar_month = month + else: + lunar_month = month - 1 + + if (year_code & 0xF) != 0 and month == (year_code & 0xF) + 1: + leap_month = True + + return ZhDate(lunar_year, lunar_month, lunar_day, leap_month) + + @staticmethod + def today(): + return ZhDate.from_datetime(datetime.now()) + + def __days_passed(self): + """私有方法,计算当前农历日期和当年农历新年之间的天数差值 + + Returns: + int -- 差值天数 + """ + month_days = ZhDate.decode(self.year_code) + # 当前农历年的闰月,为0表示无润叶 + month_leap = self.year_code & 0xF + + # 当年无闰月,或者有闰月但是当前月小于闰月 + if (month_leap == 0) or (self.lunar_month < month_leap): + days_passed_month = sum(month_days[: self.lunar_month - 1]) + # 当前不是闰月,并且当前月份和闰月相同 + elif (not self.leap_month) and (self.lunar_month == month_leap): + days_passed_month = sum(month_days[: self.lunar_month - 1]) + else: + days_passed_month = sum(month_days[: self.lunar_month]) + + return days_passed_month + self.lunar_day - 1 + + def chinese(self): + ZHNUMS = "〇一二三四五六七八九十" + zh_year = "" + for i in range(0, 4): + zh_year += ZHNUMS[int(str(self.lunar_year)[i])] + + if self.leap_month: + zh_month = "闰" + else: + zh_month = "" + + if self.lunar_month == 1: + zh_month += "正" + elif self.lunar_month == 12: + zh_month += "腊" + elif self.lunar_month <= 10: + zh_month += ZHNUMS[self.lunar_month] + else: + zh_month += "十{}".format(ZHNUMS[self.lunar_month - 10]) + + if self.lunar_day <= 10: + zh_day = "初{}".format(ZHNUMS[self.lunar_day]) + elif self.lunar_day < 20: + zh_day = "十{}".format(ZHNUMS[self.lunar_day - 10]) + elif self.lunar_day == 20: + zh_day = "二十" + elif self.lunar_day < 30: + zh_day = "廿{}".format(ZHNUMS[self.lunar_day - 20]) + else: + zh_day = "三十" + + year_tiandi = ZhDate.__tiandi(self.lunar_year - 1900 + 36) + + shengxiao = "鼠牛虎兔龙蛇马羊猴鸡狗猪" + + return "{}年{}月{} {}{}年".format(zh_year, zh_month, zh_day, year_tiandi, shengxiao[(self.lunar_year - 1900) % 12]) + + def __str__(self): + """打印字符串的方法 + + Returns: + str -- 标准格式农历日期字符串 + """ + return "农历{}年{}{}月{}日".format(self.lunar_year, "闰" if self.leap_month else "", self.lunar_month, self.lunar_day) + + def __repr__(self): + return self.__str__() + + def __eq__(self, another): + if not isinstance(another, ZhDate): + raise TypeError("比较必须都是ZhDate类型") + cond1 = self.lunar_year == another.lunar_year + cond2 = self.lunar_month == another.lunar_month + cond3 = self.lunar_day == another.lunar_day + cond4 = self.leap_month == another.leap_month + return cond1 and cond2 and cond3 and cond4 + + def __add__(self, another): + if not isinstance(another, int): + raise TypeError("加法只支持整数天数相加") + return ZhDate.from_datetime(self.to_datetime() + timedelta(days=another)) + + def __sub__(self, another): + if isinstance(another, int): + return ZhDate.from_datetime(self.to_datetime() - timedelta(days=another)) + elif isinstance(another, ZhDate): + return (self.to_datetime() - another.to_datetime()).days + elif isinstance(another, datetime): + return (self.to_datetime() - another).days + else: + raise TypeError("减法只支持整数,ZhDate, Datetime类型") + + """ + 以下为帮助函数 + """ + + @staticmethod + def __tiandi(anum): + tian = "甲乙丙丁戊己庚辛壬癸" + di = "子丑寅卯辰巳午未申酉戌亥" + return "{}{}".format(tian[anum % 10], di[anum % 12]) + + @staticmethod + def validate(year, month, day, leap): + """农历日期校验 + + Arguments: + year {int} -- 农历年份 + month {int} -- 农历月份 + day {int} -- 农历日期 + leap {bool} -- 农历是否为闰月日期 + + Returns: + bool -- 校验是否通过 + """ + # 年份低于1900,大于2100,或者月份不属于 1-12,或者日期不属于 1-30,返回校验失败 + if not (1900 <= year <= 2100 and 1 <= month <= 12 and 1 <= day <= 30): + return False + + year_code = CHINESEYEARCODE[year - 1900] + + # 有闰月标志 + if leap: + if (year_code & 0xF) != month: # 年度闰月和校验闰月不一致的话,返回校验失败 + return False + elif day == 30: # 如果日期是30的话,直接返回年度代码首位是否为1,即闰月是否为大月 + return (year_code >> 16) == 1 + else: # 年度闰月和当前月份相同,日期不为30的情况,返回通过 + return True + elif day <= 29: # 非闰月,并且日期小于等于29,返回通过 + return True + else: # 非闰月日期为30,返回年度代码中的月份位是否为1,即是否为大月 + return ((year_code >> (12 - month) + 4) & 1) == 1 + + @staticmethod + def decode(year_code): + """解析年度农历代码函数 + + Arguments: + year_code {int} -- 从年度代码数组中获取的代码整数 + + Returns: + list[int, ] -- 当前年度代码解析以后形成的每月天数数组,已将闰月嵌入对应位置,即有闰月的年份返回的列表长度为13,否则为12 + """ + # 请问您为什么不在这么重要的地方写注释? + month_days = [] + for i in range(4, 16): + # 向右移动相应的位数 + # 1 这个数只有一位,与任何数进行 按位与 都只能获得其 + # 从后往前第一位,对!是获得这一位 + month_days.insert(0, 30 if (year_code >> i) & 1 else 29) + + # 0xf 即 15 即二进制的 1111 + # 所以 1111 与任何数进行 按位与 + # 都将获得其最后四位,对!是获得这最后四位 + # 后四位非0则表示有闰月(多一月),则插入一次月份 + # 而首四位表示闰月的天数 + if year_code & 0xF: + month_days.insert((year_code & 0xF), 30 if year_code >> 16 else 29) + + # 返回一个列表 + return month_days + + @staticmethod + def month_days(year): + """根据年份返回当前农历月份天数list + + Arguments: + year {int} -- 1900到2100的之间的整数 + + Returns: + [int] -- 农历年份所对应的农历月份天数列表 + """ + return ZhDate.decode(CHINESEYEARCODE[year - 1900]) diff --git a/examples/ztime.py b/examples/ztime.py new file mode 100644 index 00000000..0b1e7ac1 --- /dev/null +++ b/examples/ztime.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +from examples.zhdate.zhdate import ZhDate + +from zvt.utils import to_pd_timestamp, current_date, count_interval + + +def holiday_distance(timestamp=None, days=15): + if not timestamp: + the_date = current_date() + else: + the_date = to_pd_timestamp(timestamp) + # 业绩预告 + month = the_date.month + + infos = [f"现在是{month}月,关注:"] + if month == 12: + infos.append("业绩预告期,注意排雷") + + # 元旦 + new_year = to_pd_timestamp(f"{the_date.year + 1}-01-01") + distance = count_interval(the_date, new_year) + if 0 < distance < days: + infos.append(f"距离元旦还有{distance}天") + if month in (1, 2): + # 春节 + zh_date = ZhDate(lunar_year=the_date.year, lunar_month=1, lunar_day=1) + spring_date = zh_date.newyear + distance = count_interval(the_date, spring_date) + if 0 < distance < days: + infos.append(f"距离春节还有{distance}天") + + # 两会 + # 三月初 + lianghui = to_pd_timestamp(f"{the_date.year}-03-01") + distance = count_interval(the_date, lianghui) + if 0 < distance < days: + infos.append(f"距离两会还有{distance}天") + + # 业绩发布 + if month in (3, 4): + infos.append("业绩发布期,注意排雷") + + # 五一 + if month == 4: + wuyi = to_pd_timestamp(f"{the_date.year}-05-01") + distance = count_interval(the_date, wuyi) + if 0 < distance < days: + infos.append(f"距离五一还有{distance}天") + + if month == 9: + # 国庆 + shiyi = to_pd_timestamp(f"{the_date.year}-10-01") + distance = count_interval(the_date, shiyi) + if 0 < distance < days: + infos.append(f"距离国庆还有{distance}天") + + msg = "\n".join(infos) + msg = msg + "\n" + print(msg) + return msg + + +if __name__ == "__main__": + for month in range(1, 13): + holiday_distance(f"2023-{month}-15") + holiday_distance(f"2023-{month}-20") diff --git a/src/zvt/api/selector.py b/src/zvt/api/selector.py index 89d938e1..816dca6a 100644 --- a/src/zvt/api/selector.py +++ b/src/zvt/api/selector.py @@ -29,7 +29,7 @@ def get_entity_ids_by_filter( provider="em", ignore_delist=True, ignore_st=True, - ignore_new_stock=True, + ignore_new_stock=False, target_date=None, entity_schema=Stock, entity_ids=None, @@ -291,7 +291,7 @@ def get_middle_and_big_stock(timestamp, provider="em"): # print(len(mini)) # print(mini) # df = get_player_performance(start_timestamp="2022-01-01") - print(len(get_entity_ids_by_filter())) + print((get_entity_ids_by_filter(ignore_new_stock=False))) # the __all__ is generated __all__ = [ "get_dragon_and_tigger_player", diff --git a/src/zvt/api/utils.py b/src/zvt/api/utils.py index 0aed56e9..dc3892bf 100644 --- a/src/zvt/api/utils.py +++ b/src/zvt/api/utils.py @@ -45,8 +45,11 @@ def get_recent_report_period(the_date=now_pd_timestamp(), step=0): def get_china_exchange(code): - if code >= "333333": + code_ = int(code) + if code_ >= 600000: return "sh" + elif code_ >= 400000: + return "bj" else: return "sz" diff --git a/src/zvt/contract/__init__.py b/src/zvt/contract/__init__.py index 9aa34eb2..7657b0a8 100644 --- a/src/zvt/contract/__init__.py +++ b/src/zvt/contract/__init__.py @@ -197,6 +197,8 @@ class Exchange(Enum): sh = "sh" #: 深证交易所 sz = "sz" + #: 北交所 + bj = "bj" #: 对于中国的非交易所的 标的 cn = "cn" @@ -236,7 +238,7 @@ class Exchange(Enum): tradable_type_map_exchanges = { TradableType.block: [Exchange.cn], TradableType.index: [Exchange.sh, Exchange.sz], - TradableType.stock: [Exchange.sh, Exchange.sz], + TradableType.stock: [Exchange.sh, Exchange.sz, Exchange.bj], TradableType.stockhk: [Exchange.hk], TradableType.stockus: [Exchange.nasdaq, Exchange.nyse], TradableType.indexus: [Exchange.us], diff --git a/src/zvt/recorders/em/em_api.py b/src/zvt/recorders/em/em_api.py index 2daed84b..c3bebe59 100644 --- a/src/zvt/recorders/em/em_api.py +++ b/src/zvt/recorders/em/em_api.py @@ -486,11 +486,13 @@ def get_tradable_list( if exchange == Exchange.sh: # t=2 主板 # t=23 科创板 - entity_flag = f"fs=m:1+t:2,m:1+t:23" + entity_flag = "fs=m:1+t:2,m:1+t:23" if exchange == Exchange.sz: # t=6 主板 # t=80 创业板 - entity_flag = f"fs=m:0+t:6,m:0+t:13,m:0+t:80" + entity_flag = "fs=m:0+t:6,m:0+t:13,m:0+t:80" + if exchange == Exchange.bj: + entity_flag = "fs=m:0+t:81+s:2048" if exchange == Exchange.hk: if hk_south: # 港股通 @@ -640,6 +642,8 @@ def to_em_fc(entity_id): Exchange.sz: 0, #: 上证交易所 Exchange.sh: 1, + #: 北交所 + Exchange.bj: 0, #: 纳斯达克 Exchange.nasdaq: 105, #: 纽交所 @@ -764,7 +768,12 @@ def to_zvt_code(code): # # df = get_tradable_list() # # df_delist = df[df["name"].str.contains("退")] # print(df_delist[["id", "name"]].values.tolist()) - print(get_block_stocks(block_id="block_cn_BK1144")) + # print(get_block_stocks(block_id="block_cn_BK1144")) + df = get_tradable_list(entity_type="stock", exchange=Exchange.bj) + print(df) + df = get_kdata(entity_id="stock_bj_873693", level="1d") + print(df) + # the __all__ is generated __all__ = [ "get_treasury_yield", diff --git a/src/zvt/recorders/em/meta/em_stock_meta_recorder.py b/src/zvt/recorders/em/meta/em_stock_meta_recorder.py index acba5a7e..b10c9459 100644 --- a/src/zvt/recorders/em/meta/em_stock_meta_recorder.py +++ b/src/zvt/recorders/em/meta/em_stock_meta_recorder.py @@ -13,7 +13,7 @@ class EMStockRecorder(Recorder): data_schema = Stock def run(self): - for exchange in [Exchange.sh, Exchange.sz]: + for exchange in [Exchange.sh, Exchange.sz, Exchange.bj]: df = em_api.get_tradable_list(entity_type="stock", exchange=exchange) # df_delist = df[df["name"].str.contains("退")] if pd_is_not_null(df): diff --git a/src/zvt/recorders/em/news/em_stock_news_recorder.py b/src/zvt/recorders/em/news/em_stock_news_recorder.py index 52025341..fa77d830 100644 --- a/src/zvt/recorders/em/news/em_stock_news_recorder.py +++ b/src/zvt/recorders/em/news/em_stock_news_recorder.py @@ -33,8 +33,9 @@ def record(self, entity, start, end, size, timestamps): if __name__ == "__main__": - # Stock.record_data(provider="em") - r = EMStockNewsRecorder(entity_ids=["stock_sz_000005"]) + df = Stock.query_data(filters=[Stock.exchange == "bj"], provider="em") + entity_ids = df["entity_id"].tolist() + r = EMStockNewsRecorder(entity_ids=entity_ids, sleeping_time=0) r.run() # the __all__ is generated __all__ = ["EMStockNewsRecorder"] diff --git a/src/zvt/recorders/em/quotes/em_kdata_recorder.py b/src/zvt/recorders/em/quotes/em_kdata_recorder.py index 5758bb30..163a66aa 100644 --- a/src/zvt/recorders/em/quotes/em_kdata_recorder.py +++ b/src/zvt/recorders/em/quotes/em_kdata_recorder.py @@ -163,9 +163,11 @@ class EMCurrencyKdataRecorder(BaseEMStockKdataRecorder): if __name__ == "__main__": - df = Currency.query_data(filters=[Currency.code.like("USD%")]) + df = Stock.query_data(filters=[Stock.exchange == "bj"], provider="em") entity_ids = df["entity_id"].tolist() - recorder = EMCurrencyKdataRecorder(level=IntervalLevel.LEVEL_1DAY, entity_ids=entity_ids, sleeping_time=0) + recorder = EMStockKdataRecorder( + level=IntervalLevel.LEVEL_1DAY, entity_ids=entity_ids, sleeping_time=0, adjust_type=AdjustType.hfq + ) recorder.run() # the __all__ is generated __all__ = [