Skip to content

Commit

Permalink
improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Jun 24, 2022
1 parent e971009 commit e220930
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
17 changes: 8 additions & 9 deletions examples/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def report_targets(
data_provider,
title,
entity_type="stock",
informer: EmailInformer = None,
em_group=None,
em_group_over_write=True,
filter_by_volume=True,
Expand All @@ -62,8 +63,6 @@ def report_targets(
error_count = 0

while error_count <= 10:
email_action = EmailInformer()

try:
if not adjust_type:
adjust_type = default_adjust_type(entity_type=entity_type)
Expand Down Expand Up @@ -131,7 +130,7 @@ def report_targets(
long_stocks = my_selector.get_open_long_targets(timestamp=target_date)

inform(
email_action,
informer,
entity_ids=long_stocks,
target_date=target_date,
title=title,
Expand All @@ -147,7 +146,7 @@ def report_targets(
time.sleep(60 * 3)
error_count = error_count + 1
if error_count == 10:
email_action.send_message(
informer.send_message(
zvt_config["email_username"],
f"report {entity_type}{factor_cls.__name__} error",
f"report {entity_type}{factor_cls.__name__} error: {e}",
Expand All @@ -166,6 +165,7 @@ def report_top_entities(
top_count=30,
turnover_threshold=100000000,
turnover_rate_threshold=0.02,
informer: EmailInformer = None,
em_group=None,
em_group_over_write=True,
return_type=TopType.positive,
Expand All @@ -178,7 +178,6 @@ def report_top_entities(
entity_schema = get_entity_schema(entity_type=entity_type)

target_date = get_latest_kdata_date(provider=data_provider, entity_type=entity_type, adjust_type=adjust_type)
email_action = EmailInformer()

filter_entity_ids = get_entity_ids_by_filter(
provider=entity_provider,
Expand All @@ -192,7 +191,7 @@ def report_top_entities(
if not filter_entity_ids:
msg = f"{entity_type} no entity_ids selected"
logger.error(msg)
email_action.send_message(zvt_config["email_username"], "report_top_stats error", msg)
informer.send_message(zvt_config["email_username"], "report_top_stats error", msg)
return

filter_turnover_df = kdata_schema.query_data(
Expand All @@ -213,7 +212,7 @@ def report_top_entities(
if not filter_entity_ids:
msg = f"{entity_type} no entity_ids selected"
logger.error(msg)
email_action.send_message(zvt_config["email_username"], "report_top_stats error", msg)
informer.send_message(zvt_config["email_username"], "report_top_stats error", msg)
return

logger.info(f"{entity_type} filter_entity_ids size: {len(filter_entity_ids)}")
Expand Down Expand Up @@ -243,7 +242,7 @@ def report_top_entities(

if i == 0:
inform(
email_action,
informer,
entity_ids=df.index[:top_count].tolist(),
target_date=target_date,
title=f"{entity_type} {period}日内 {tag}",
Expand All @@ -254,7 +253,7 @@ def report_top_entities(
)
else:
inform(
email_action,
informer,
entity_ids=df.index[:top_count].tolist(),
target_date=target_date,
title=f"{entity_type} {period}日内 {tag}",
Expand Down
4 changes: 4 additions & 0 deletions examples/reports/report_bull.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
from zvt.api import get_latest_kdata_date
from zvt.api.selector import get_middle_and_big_stock
from zvt.contract import AdjustType
from zvt.informer import EmailInformer

logger = logging.getLogger(__name__)

sched = BackgroundScheduler()
email_informer = EmailInformer()


@sched.scheduled_job("cron", hour=18, minute=0, day_of_week="mon-fri")
Expand All @@ -26,6 +28,7 @@ def report_bull():
data_provider="em",
title="bull股票",
entity_type="stock",
informer=email_informer,
em_group="bull股票",
em_group_over_write=False,
filter_by_volume=False,
Expand All @@ -41,6 +44,7 @@ def report_bull():
data_provider="em",
title="bull板块",
entity_type="block",
informer=email_informer,
em_group="bull股票",
em_group_over_write=False,
filter_by_volume=False,
Expand Down
22 changes: 17 additions & 5 deletions examples/reports/report_tops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
from zvt import init_log
from zvt.api import TopType
from zvt.domain import Block, BlockCategory
from zvt.informer import EmailInformer

logger = logging.getLogger(__name__)

sched = BackgroundScheduler()

email_informer = EmailInformer()


@sched.scheduled_job("cron", hour=17, minute=0, day_of_week="mon-fri")
def report_top_stocks():

report_top_entities(
entity_type="stock",
entity_provider="em",
Expand All @@ -26,6 +30,7 @@ def report_top_stocks():
top_count=20,
turnover_threshold=0,
turnover_rate_threshold=0,
informer=email_informer,
em_group="短期最强",
em_group_over_write=True,
return_type=TopType.positive,
Expand All @@ -42,6 +47,7 @@ def report_top_stocks():
top_count=20,
turnover_threshold=0,
turnover_rate_threshold=0,
informer=email_informer,
em_group="中期最强",
em_group_over_write=True,
return_type=TopType.positive,
Expand All @@ -58,6 +64,7 @@ def report_top_stocks():
top_count=25,
turnover_threshold=100000000,
turnover_rate_threshold=0.01,
informer=email_informer,
em_group="谁有我惨",
em_group_over_write=True,
return_type=TopType.negative,
Expand All @@ -80,6 +87,7 @@ def report_top_blocks():
top_count=10,
turnover_threshold=0,
turnover_rate_threshold=0,
informer=email_informer,
em_group="关注板块",
em_group_over_write=True,
return_type=TopType.positive,
Expand All @@ -97,6 +105,7 @@ def report_top_blocks():
top_count=10,
turnover_threshold=0,
turnover_rate_threshold=0,
informer=email_informer,
em_group="关注板块",
em_group_over_write=False,
return_type=TopType.negative,
Expand All @@ -116,7 +125,8 @@ def report_top_stockhks():
ignore_st=False,
adjust_type=None,
turnover_threshold=50000000,
turnover_rate_threshold=0.005,
turnover_rate_threshold=0.001,
informer=email_informer,
em_group="短期最强",
em_group_over_write=False,
return_type=TopType.positive,
Expand All @@ -132,7 +142,8 @@ def report_top_stockhks():
ignore_st=False,
adjust_type=None,
turnover_threshold=50000000,
turnover_rate_threshold=0.005,
turnover_rate_threshold=0.001,
informer=email_informer,
em_group="中期最强",
em_group_over_write=False,
return_type=TopType.positive,
Expand All @@ -142,25 +153,26 @@ def report_top_stockhks():
entity_type="stockhk",
entity_provider="em",
data_provider="em",
top_count=10,
top_count=20,
periods=[365, 750],
ignore_new_stock=True,
ignore_st=False,
adjust_type=None,
turnover_threshold=50000000,
turnover_rate_threshold=0.005,
informer=email_informer,
em_group="谁有我惨",
em_group_over_write=False,
return_type=TopType.negative,
)


if __name__ == "__main__":
init_log("report_top_stocks.log")
init_log("report_tops.log")

report_top_stocks()
report_top_stockhks()
report_top_blocks()
report_top_stockhks()

sched.start()

Expand Down
7 changes: 7 additions & 0 deletions examples/reports/report_vol_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@
from zvt.api.selector import get_mini_and_small_stock, get_middle_and_big_stock
from zvt.contract import AdjustType
from zvt.factors import VolumeUpMaFactor
from zvt.informer import EmailInformer

logger = logging.getLogger(__name__)

sched = BackgroundScheduler()

email_informer = EmailInformer()


@sched.scheduled_job("cron", hour=17, minute=0, day_of_week="mon-fri")
def report_vol_up():
target_date = get_latest_kdata_date(entity_type="stock", adjust_type=AdjustType.hfq, provider="em")
entity_ids = get_mini_and_small_stock(timestamp=target_date, provider="em")

report_targets(
factor_cls=VolumeUpMaFactor,
entity_provider="em",
data_provider="em",
informer=email_informer,
em_group="年线股票",
title="放量突破(半)年线小市值股票",
entity_type="stock",
Expand All @@ -44,6 +49,7 @@ def report_vol_up():
factor_cls=VolumeUpMaFactor,
entity_provider="em",
data_provider="em",
informer=email_informer,
em_group="年线股票",
title="放量突破(半)年线大市值股票",
entity_type="stock",
Expand All @@ -64,6 +70,7 @@ def report_vol_up():
factor_cls=VolumeUpMaFactor,
entity_provider="em",
data_provider="em",
informer=email_informer,
em_group="年线股票",
title="放量突破(半)年线港股",
entity_type="stockhk",
Expand Down

0 comments on commit e220930

Please sign in to comment.