diff --git a/examples/data_runner/actor_runner.py b/examples/data_runner/actor_runner.py index ba360ead..8a61e4e2 100644 --- a/examples/data_runner/actor_runner.py +++ b/examples/data_runner/actor_runner.py @@ -3,13 +3,13 @@ from apscheduler.schedulers.background import BackgroundScheduler -from zvt.utils.recorder_utils import run_data_recorder from zvt import init_log from zvt.domain import ( StockInstitutionalInvestorHolder, StockTopTenFreeHolder, StockActorSummary, ) +from zvt.utils.recorder_utils import run_data_recorder logger = logging.getLogger(__name__) diff --git a/examples/data_runner/finance_runner.py b/examples/data_runner/finance_runner.py index 73490ff0..5966700f 100644 --- a/examples/data_runner/finance_runner.py +++ b/examples/data_runner/finance_runner.py @@ -3,7 +3,6 @@ from apscheduler.schedulers.background import BackgroundScheduler -from zvt.utils.recorder_utils import run_data_recorder from zvt import init_log from zvt.domain import ( Stock, @@ -13,6 +12,7 @@ IncomeStatement, CashFlowStatement, ) +from zvt.utils.recorder_utils import run_data_recorder logger = logging.getLogger(__name__) diff --git a/examples/data_runner/index_runner.py b/examples/data_runner/index_runner.py index 9eaf1a63..3751871c 100644 --- a/examples/data_runner/index_runner.py +++ b/examples/data_runner/index_runner.py @@ -3,10 +3,10 @@ from apscheduler.schedulers.background import BackgroundScheduler -from zvt.utils.recorder_utils import run_data_recorder from zvt import init_log from zvt.consts import IMPORTANT_INDEX from zvt.domain import Index, Index1dKdata, IndexStock +from zvt.utils.recorder_utils import run_data_recorder logger = logging.getLogger(__name__) diff --git a/examples/data_runner/joinquant_fund_runner.py b/examples/data_runner/joinquant_fund_runner.py index 92d026ae..0749afaf 100644 --- a/examples/data_runner/joinquant_fund_runner.py +++ b/examples/data_runner/joinquant_fund_runner.py @@ -3,9 +3,9 @@ from apscheduler.schedulers.background import BackgroundScheduler -from zvt.utils.recorder_utils import run_data_recorder from zvt import init_log from zvt.domain import Fund, FundStock, StockValuation +from zvt.utils.recorder_utils import run_data_recorder logger = logging.getLogger(__name__) diff --git a/examples/data_runner/kdata_runner.py b/examples/data_runner/kdata_runner.py index 4358844c..f9078ce4 100644 --- a/examples/data_runner/kdata_runner.py +++ b/examples/data_runner/kdata_runner.py @@ -3,7 +3,6 @@ from apscheduler.schedulers.background import BackgroundScheduler -from zvt.utils.recorder_utils import run_data_recorder from examples.report_utils import inform from examples.utils import get_hot_topics from zvt import init_log, zvt_config @@ -23,6 +22,7 @@ ) from zvt.informer import EmailInformer from zvt.utils import current_date +from zvt.utils.recorder_utils import run_data_recorder logger = logging.getLogger(__name__) diff --git a/examples/data_runner/sina_data_runner.py b/examples/data_runner/sina_data_runner.py index 732ba614..0f91fa4f 100644 --- a/examples/data_runner/sina_data_runner.py +++ b/examples/data_runner/sina_data_runner.py @@ -3,9 +3,9 @@ from apscheduler.schedulers.background import BackgroundScheduler -from zvt.utils.recorder_utils import run_data_recorder from zvt import init_log from zvt.domain import * +from zvt.utils.recorder_utils import run_data_recorder logger = logging.getLogger(__name__) diff --git a/examples/data_runner/trading_runner.py b/examples/data_runner/trading_runner.py index 29de58e3..ab473fde 100644 --- a/examples/data_runner/trading_runner.py +++ b/examples/data_runner/trading_runner.py @@ -4,16 +4,17 @@ from apscheduler.schedulers.background import BackgroundScheduler from sqlalchemy import or_, and_ -from zvt.utils.recorder_utils import run_data_recorder from examples.report_utils import inform from zvt import init_log -from zvt.api import get_big_players, get_latest_kdata_date +from zvt.api.kdata import get_latest_kdata_date +from zvt.api.selector import get_big_players from zvt.domain import ( DragonAndTiger, Stock1dHfqKdata, ) from zvt.informer import EmailInformer -from zvt.utils import date_time_by_interval, current_date, to_pd_timestamp +from zvt.utils.recorder_utils import run_data_recorder +from zvt.utils.time_utils import date_time_by_interval, current_date, to_pd_timestamp logger = logging.getLogger(__name__) diff --git a/examples/factors/boll_factor.py b/examples/factors/boll_factor.py index 63fb01a4..aef71d36 100644 --- a/examples/factors/boll_factor.py +++ b/examples/factors/boll_factor.py @@ -4,8 +4,8 @@ import pandas as pd from ta.volatility import BollingerBands -from zvt.contract.factor import * -from zvt.factors import TechnicalFactor +from zvt.contract.factor import Transformer +from zvt.factors.technical_factor import TechnicalFactor class BollTransformer(Transformer): diff --git a/examples/factors/fundamental_selector.py b/examples/factors/fundamental_selector.py index 54d49e02..7495c825 100644 --- a/examples/factors/fundamental_selector.py +++ b/examples/factors/fundamental_selector.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from zvt.domain import BalanceSheet -from zvt.factors.fundamental import GoodCompanyFactor +from zvt.factors.fundamental.finance_factor import GoodCompanyFactor from zvt.factors.target_selector import TargetSelector diff --git a/examples/factors/tech_factor.py b/examples/factors/tech_factor.py index f51085b3..544aa4e5 100644 --- a/examples/factors/tech_factor.py +++ b/examples/factors/tech_factor.py @@ -7,7 +7,7 @@ from zvt.contract import AdjustType, TradableEntity, IntervalLevel from zvt.contract.factor import Transformer, Accumulator from zvt.domain import Stock -from zvt.factors import MacdFactor +from zvt.factors.macd.macd_factor import MacdFactor from zvt.factors.transformers import CrossMaTransformer diff --git a/examples/intent/intent.py b/examples/intent/intent.py index c00eb7f9..762df26c 100644 --- a/examples/intent/intent.py +++ b/examples/intent/intent.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from zvt.api.intent import compare -from zvt.domain import Indexus1dKdata, Index, Indexus, Index1dKdata, Currency, Currency1dKdata +from zvt.domain import Indexus1dKdata, Index, Indexus, Index1dKdata, Currency1dKdata from zvt.domain import TreasuryYield diff --git a/examples/migration.py b/examples/migration.py index 52f27d1b..0999ddd9 100644 --- a/examples/migration.py +++ b/examples/migration.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from datetime import datetime -from typing import Any, Dict +from typing import Dict -from pydantic import BaseModel, ConfigDict, Json +from pydantic import BaseModel, ConfigDict from sqlalchemy import Column, String, JSON from sqlalchemy.orm import declarative_base diff --git a/examples/query_snippet.py b/examples/query_snippet.py index 28bf598b..29950424 100644 --- a/examples/query_snippet.py +++ b/examples/query_snippet.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -from zvt.contract import Exchange +from sqlalchemy import func + from zvt.api.selector import get_entity_ids_by_filter +from zvt.contract import Exchange from zvt.domain import Stock, BlockStock from zvt.recorders.em import em_api from zvt.tag import StockTags -from sqlalchemy import func def query_json(): diff --git a/examples/report_utils.py b/examples/report_utils.py index b16ae5d2..88ed1bf8 100644 --- a/examples/report_utils.py +++ b/examples/report_utils.py @@ -6,17 +6,16 @@ from examples.tag_utils import group_stocks_by_tag, get_main_line_tags, get_main_line_hidden_tags from examples.utils import msg_group_stocks_by_topic from zvt import zvt_config -from zvt.api import get_top_volume_entities, TopType from zvt.api.kdata import get_latest_kdata_date, get_kdata_schema, default_adjust_type from zvt.api.selector import get_limit_up_stocks -from zvt.api.stats import get_top_performance_entities_by_periods +from zvt.api.stats import get_top_performance_entities_by_periods, get_top_volume_entities, TopType from zvt.contract import IntervalLevel from zvt.contract.api import get_entities, get_entity_schema from zvt.contract.factor import Factor, TargetType from zvt.domain import StockNews from zvt.informer import EmailInformer -from zvt.utils import date_time_by_interval from zvt.informer.inform_utils import add_to_eastmoney +from zvt.utils.time_utils import date_time_by_interval logger = logging.getLogger("__name__") diff --git a/examples/reports/__init__.py b/examples/reports/__init__.py index c91763f4..e41d48b0 100644 --- a/examples/reports/__init__.py +++ b/examples/reports/__init__.py @@ -6,7 +6,7 @@ from sqlalchemy import or_ -from zvt.api import float_to_pct_str +from zvt.api.utils import float_to_pct_str from zvt.contract import ActorType from zvt.domain import FinanceFactor, BalanceSheet, IncomeStatement, Stock, StockActorSummary from zvt.utils.pd_utils import pd_is_not_null diff --git a/examples/reports/report_bull.py b/examples/reports/report_bull.py index 8adc53da..3292ac24 100644 --- a/examples/reports/report_bull.py +++ b/examples/reports/report_bull.py @@ -6,7 +6,7 @@ from examples.factors.tech_factor import BullAndUpFactor from examples.report_utils import report_targets from zvt import init_log -from zvt.api import get_latest_kdata_date +from zvt.api.kdata 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 diff --git a/examples/reports/report_core_compay.py b/examples/reports/report_core_compay.py index 3e5915fd..d76b392e 100644 --- a/examples/reports/report_core_compay.py +++ b/examples/reports/report_core_compay.py @@ -10,8 +10,8 @@ from zvt.contract.api import get_entities from zvt.domain import Stock from zvt.factors.target_selector import TargetSelector -from zvt.informer.informer import EmailInformer from zvt.informer.inform_utils import add_to_eastmoney +from zvt.informer.informer import EmailInformer from zvt.utils.time_utils import now_pd_timestamp, to_time_str logger = logging.getLogger(__name__) diff --git a/examples/reports/report_tops.py b/examples/reports/report_tops.py index 069dc18a..feec5fd6 100644 --- a/examples/reports/report_tops.py +++ b/examples/reports/report_tops.py @@ -5,10 +5,10 @@ from examples.report_utils import report_top_entities, inform from zvt import init_log +from zvt.api.stats import TopType, get_latest_kdata_date from zvt.contract import AdjustType -from zvt.api import TopType, get_latest_kdata_date from zvt.domain import Block, BlockCategory -from zvt.factors.top_stocks import compute_top_stocks, get_top_stocks +from zvt.factors.top_stocks import get_top_stocks from zvt.informer import EmailInformer logger = logging.getLogger(__name__) diff --git a/examples/reports/report_vol_up.py b/examples/reports/report_vol_up.py index ad24dded..e14748b1 100644 --- a/examples/reports/report_vol_up.py +++ b/examples/reports/report_vol_up.py @@ -1,14 +1,13 @@ # -*- coding: utf-8 -*- import logging +from zvt.factors.ma import VolumeUpMaFactor from apscheduler.schedulers.background import BackgroundScheduler from examples.report_utils import report_targets, inform from zvt import init_log from zvt.api.kdata import get_latest_kdata_date -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.factors.top_stocks import get_top_stocks from zvt.informer import EmailInformer diff --git a/examples/research/top_dragon_tiger.py b/examples/research/top_dragon_tiger.py index ed1bb622..0dac4a52 100644 --- a/examples/research/top_dragon_tiger.py +++ b/examples/research/top_dragon_tiger.py @@ -3,13 +3,14 @@ import pandas as pd -from zvt.api import get_top_performance_by_month from zvt.api.selector import get_players +from zvt.api.stats import get_top_performance_by_month from zvt.contract import TradableEntity, IntervalLevel, AdjustType from zvt.contract.factor import Transformer, Accumulator from zvt.domain import Stock -from zvt.factors import TechnicalFactor -from zvt.utils import pd_is_not_null, pre_month_start_date, date_time_by_interval +from zvt.factors.technical_factor import TechnicalFactor +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import pre_month_start_date, date_time_by_interval def top_dragon_and_tiger(data_provider="em", start_timestamp="2021-01-01", end_timestamp="2022-01-01"): diff --git a/examples/research/top_tags.py b/examples/research/top_tags.py index 735874e9..8f264170 100644 --- a/examples/research/top_tags.py +++ b/examples/research/top_tags.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from zvt.api import get_top_performance_by_month +from zvt.api.stats import get_top_performance_by_month from zvt.domain import Stock1dHfqKdata -from zvt.utils import date_time_by_interval, month_end_date, is_same_date +from zvt.utils.time_utils import date_time_by_interval, month_end_date, is_same_date # 每月涨幅前30,市值90%分布在100亿以下 diff --git a/examples/tag_utils.py b/examples/tag_utils.py index 248711cb..e69158e0 100644 --- a/examples/tag_utils.py +++ b/examples/tag_utils.py @@ -3,8 +3,7 @@ import os from collections import Counter -from zvt.api import china_stock_code_to_id, get_china_exchange - +from zvt.api.utils import china_stock_code_to_id, get_china_exchange from zvt.domain import BlockStock, Block, Stock, LimitUpInfo diff --git a/examples/trader/follow_ii_trader.py b/examples/trader/follow_ii_trader.py index 96d6bf88..92661476 100644 --- a/examples/trader/follow_ii_trader.py +++ b/examples/trader/follow_ii_trader.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import pandas as pd -from zvt.api import get_recent_report_date +from zvt.api.utils import get_recent_report_date from zvt.contract import ActorType, AdjustType from zvt.domain import StockActorSummary, Stock1dKdata, Stock from zvt.trader import StockTrader diff --git a/examples/trader/keep_run_trader.py b/examples/trader/keep_run_trader.py index 39d780a1..2e0ab474 100644 --- a/examples/trader/keep_run_trader.py +++ b/examples/trader/keep_run_trader.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- import logging -from zvt.api import get_top_volume_entities from zvt.api.stats import get_top_fund_holding_stocks -from zvt.trader.trader_info_api import clear_trader +from zvt.api.stats import get_top_volume_entities from zvt.contract import IntervalLevel -from zvt.factors import GoldCrossFactor, BullFactor +from zvt.factors.macd.macd_factor import BullFactor from zvt.trader import StockTrader +from zvt.trader.trader_info_api import clear_trader from zvt.utils.time_utils import split_time_interval, date_time_by_interval logger = logging.getLogger(__name__) diff --git a/examples/trader/ma_trader.py b/examples/trader/ma_trader.py index b76acb71..a30e1259 100644 --- a/examples/trader/ma_trader.py +++ b/examples/trader/ma_trader.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from zvt.contract import IntervalLevel -from zvt.factors import CrossMaFactor -from zvt.factors.macd import BullFactor +from zvt.factors.ma.ma_factor import CrossMaFactor +from zvt.factors.macd.macd_factor import BullFactor from zvt.trader.trader import StockTrader diff --git a/examples/trader/macd_day_trader.py b/examples/trader/macd_day_trader.py index 85e1785d..9e5de408 100644 --- a/examples/trader/macd_day_trader.py +++ b/examples/trader/macd_day_trader.py @@ -5,14 +5,14 @@ from zvt.contract import IntervalLevel from zvt.contract.factor import Factor -from zvt.factors import GoldCrossFactor +from zvt.factors.macd.macd_factor import GoldCrossFactor from zvt.trader import TradingSignal from zvt.trader.trader import StockTrader # 依赖数据 # data_schema: Stock1dHfqKdata # provider: joinquant -from zvt.utils import date_time_by_interval +from zvt.utils.time_utils import date_time_by_interval class MacdDayTrader(StockTrader): diff --git a/examples/trader/macd_week_and_day_trader.py b/examples/trader/macd_week_and_day_trader.py index de834b4f..3bfb618a 100644 --- a/examples/trader/macd_week_and_day_trader.py +++ b/examples/trader/macd_week_and_day_trader.py @@ -2,7 +2,7 @@ from typing import List, Tuple from zvt.contract import IntervalLevel -from zvt.factors import GoldCrossFactor +from zvt.factors.macd.macd_factor import GoldCrossFactor from zvt.trader.trader import StockTrader diff --git a/src/zvt/__init__.py b/src/zvt/__init__.py index 0fa81023..0a821e45 100644 --- a/src/zvt/__init__.py +++ b/src/zvt/__init__.py @@ -7,6 +7,7 @@ import pprint import shutil from logging.handlers import RotatingFileHandler +from typing import List import pandas as pd import pkg_resources @@ -80,15 +81,20 @@ def init_env(zvt_home: str, **kwargs) -> dict: :param zvt_home: home path for zvt """ data_path = os.path.join(zvt_home, "data") + resource_path = os.path.join(zvt_home, "resources") tmp_path = os.path.join(zvt_home, "tmp") if not os.path.exists(data_path): os.makedirs(data_path) + if not os.path.exists(resource_path): + os.makedirs(resource_path) + if not os.path.exists(tmp_path): os.makedirs(tmp_path) zvt_env["zvt_home"] = zvt_home zvt_env["data_path"] = data_path + zvt_env["resource_path"] = resource_path zvt_env["tmp_path"] = tmp_path # path for storing ui results @@ -105,6 +111,7 @@ def init_env(zvt_home: str, **kwargs) -> dict: pprint.pprint(zvt_env) + init_resources(resource_path=resource_path) # init config init_config(current_config=zvt_config, **kwargs) # init plugin @@ -113,6 +120,18 @@ def init_env(zvt_home: str, **kwargs) -> dict: return zvt_env +def init_resources(resource_path): + package_name = "zvt" + package_dir = pkg_resources.resource_filename(package_name, "resources") + from zvt.utils.file_utils import list_all_files + + files: List[str] = list_all_files(package_dir, ext=None) + for source_file in files: + dst_file = os.path.join(resource_path, source_file[len(package_dir) + 1 :]) + if not os.path.exists(dst_file): + shutil.copyfile(source_file, dst_file) + + def init_config(pkg_name: str = None, current_config: dict = None, **kwargs) -> dict: """ init config @@ -129,12 +148,10 @@ def init_config(pkg_name: str = None, current_config: dict = None, **kwargs) -> config_path = os.path.join(zvt_env["zvt_home"], config_file) if not os.path.exists(config_path): - from shutil import copyfile - try: sample_config = pkg_resources.resource_filename(pkg_name, "config.json") if os.path.exists(sample_config): - copyfile(sample_config, config_path) + shutil.copyfile(sample_config, config_path) except Exception as e: logger.warning(f"could not load config.json from package {pkg_name}") @@ -201,16 +218,15 @@ def old_db_to_provider_dir(data_path): same = filecmp.cmp(ZVT_TEST_ZIP_DATA_PATH, DATA_SAMPLE_ZIP_PATH) if not same: - from shutil import copyfile from zvt.contract import * from zvt.utils.zip_utils import unzip - copyfile(DATA_SAMPLE_ZIP_PATH, ZVT_TEST_ZIP_DATA_PATH) + shutil.copyfile(DATA_SAMPLE_ZIP_PATH, ZVT_TEST_ZIP_DATA_PATH) unzip(ZVT_TEST_ZIP_DATA_PATH, ZVT_TEST_DATA_PATH) else: init_env(zvt_home=ZVT_HOME) -old_db_to_provider_dir(zvt_env["data_path"]) +# old_db_to_provider_dir(zvt_env["data_path"]) # register to meta import zvt.contract as zvt_contract diff --git a/src/zvt/api/__init__.py b/src/zvt/api/__init__.py index df9f9156..2686fff0 100644 --- a/src/zvt/api/__init__.py +++ b/src/zvt/api/__init__.py @@ -1,48 +1,5 @@ # -*- coding: utf-8 -*- -# the __all__ is generated -__all__ = [] - -# __init__.py structure: -# common code of the package -# export interface in __all__ which contains __all__ of its sub modules - -# import all from submodule intent -from .intent import * -from .intent import __all__ as _intent_all - -__all__ += _intent_all - -# import all from submodule selector -from .selector import * -from .selector import __all__ as _selector_all - -__all__ += _selector_all - -# import all from submodule kdata -from .kdata import * -from .kdata import __all__ as _kdata_all - -__all__ += _kdata_all -# import all from submodule utils -from .utils import * -from .utils import __all__ as _utils_all -__all__ += _utils_all - -# import all from submodule stats -from .stats import * -from .stats import __all__ as _stats_all - -__all__ += _stats_all - -# import all from submodule trader_info_api -from zvt.trader.trader_info_api import __all__ as _trader_info_api_all - -__all__ += _trader_info_api_all - -# import all from submodule portfolio -from .portfolio import * -from .portfolio import __all__ as _portfolio_all - -__all__ += _portfolio_all +# the __all__ is generated +__all__ = [] diff --git a/src/zvt/api/intent.py b/src/zvt/api/intent.py index 687dc878..046607af 100644 --- a/src/zvt/api/intent.py +++ b/src/zvt/api/intent.py @@ -6,7 +6,7 @@ from zvt.api.kdata import get_kdata_schema from zvt.contract.api import decode_entity_id from zvt.contract.drawer import Drawer, ChartType -from zvt.utils import to_pd_timestamp +from zvt.utils.time_utils import to_pd_timestamp def compare( @@ -201,5 +201,6 @@ def _group_entity_ids(entity_ids): ) composite_df(df=df) + # the __all__ is generated __all__ = ["compare", "compare_df", "distribute", "distribute_df", "composite", "composite_df", "composite_all"] diff --git a/src/zvt/api/selector.py b/src/zvt/api/selector.py index d6eeab49..967b5ed3 100644 --- a/src/zvt/api/selector.py +++ b/src/zvt/api/selector.py @@ -8,7 +8,8 @@ from zvt.contract import IntervalLevel from zvt.contract.api import get_entity_ids from zvt.domain import DragonAndTiger, Stock1dHfqKdata, Stock, LimitUpInfo -from zvt.utils import to_pd_timestamp, date_time_by_interval, current_date, pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import to_pd_timestamp, date_time_by_interval, current_date logger = logging.getLogger(__name__) @@ -306,12 +307,17 @@ def get_middle_and_big_stock(timestamp, provider="em"): # df = get_player_performance(start_timestamp="2022-01-01") # print((get_entity_ids_by_filter(ignore_new_stock=False))) print(get_limit_up_stocks(timestamp="2023-12-2")) + + # the __all__ is generated __all__ = [ + "get_entity_ids_by_filter", + "get_limit_up_stocks", "get_dragon_and_tigger_player", "get_big_players", "get_player_performance", "get_player_success_rate", + "get_players", "get_good_players", "get_entity_list_by_cap", "get_big_cap_stock", diff --git a/src/zvt/api/stats.py b/src/zvt/api/stats.py index 252b8573..2c518af9 100644 --- a/src/zvt/api/stats.py +++ b/src/zvt/api/stats.py @@ -13,8 +13,14 @@ from zvt.contract.api import decode_entity_id, get_entity_schema, get_entity_ids from zvt.contract.drawer import Drawer from zvt.domain import FundStock, StockValuation, BlockStock, Block -from zvt.utils import now_pd_timestamp, date_time_by_interval, pd_is_not_null -from zvt.utils.time_utils import month_start_end_ranges, to_time_str, is_same_date +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import ( + month_start_end_ranges, + to_time_str, + is_same_date, + now_pd_timestamp, + date_time_by_interval, +) logger = logging.getLogger(__name__) @@ -574,18 +580,22 @@ def cal_ratio(df): if __name__ == "__main__": print(get_top_performance_entities_by_periods(entity_provider="em", data_provider="em")) + # the __all__ is generated __all__ = [ "WindowMethod", "TopType", "get_top_performance_by_month", + "get_top_performance_entities_by_periods", "get_top_performance_entities", "get_top_fund_holding_stocks", "get_performance", "get_performance_stats_by_month", "get_performance_stats", "get_top_volume_entities", + "get_top_turnover_rate_entities", "get_top_entities", "show_month_performance", "show_industry_composition", + "get_change_ratio", ] diff --git a/src/zvt/api/utils.py b/src/zvt/api/utils.py index f5bbcd3e..e647d1bf 100644 --- a/src/zvt/api/utils.py +++ b/src/zvt/api/utils.py @@ -3,7 +3,7 @@ from zvt.contract import Mixin from zvt.domain import ReportPeriod -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null from zvt.utils.time_utils import to_pd_timestamp, now_pd_timestamp diff --git a/src/zvt/autocode/generator.py b/src/zvt/autocode/generator.py index d98076e3..53b6784f 100644 --- a/src/zvt/autocode/generator.py +++ b/src/zvt/autocode/generator.py @@ -5,9 +5,9 @@ from zvt.autocode.templates import all_tpls from zvt.contract import IntervalLevel, AdjustType -from zvt.utils import now_pd_timestamp from zvt.utils.file_utils import list_all_files from zvt.utils.git_utils import get_git_user_name, get_git_user_email +from zvt.utils.time_utils import now_pd_timestamp logger = logging.getLogger(__name__) @@ -102,7 +102,7 @@ def fill_package(dir_path: str): def gen_exports( dir_path="./domain", gen_flag="# the __all__ is generated", - export_from_package=True, + export_from_package=False, export_modules=None, excludes=None, export_var=False, @@ -131,6 +131,14 @@ def gen_exports( exports.append(export) line = fp.readline() print(f"{file}:{exports}") + end_empty_lines_count = 0 + for i in range(-1, -len(lines) - 1, -1): + if not lines[i].isspace(): + break + end_empty_lines_count = end_empty_lines_count + 1 + lines = lines[: len(lines) - end_empty_lines_count] + + lines.append("\n\n") lines.append(gen_flag) lines.append("\n") exports_str = f"__all__ = {exports}" diff --git a/src/zvt/autocode/templates/kdata_recorder.py.template b/src/zvt/autocode/templates/kdata_recorder.py.template index 8634a60d..cd2c6f61 100644 --- a/src/zvt/autocode/templates/kdata_recorder.py.template +++ b/src/zvt/autocode/templates/kdata_recorder.py.template @@ -3,7 +3,7 @@ # -*- coding: utf-8 -*- from zvt import IntervalLevel -from zvt.api import get_kdata_schema +from zvt.api.kdata import get_kdata_schema from zvt.contract.recorder import FixedCycleDataRecorder from ${project}.domain import ${entity_class}, ${entity_class}KdataCommon diff --git a/src/zvt/autocode/templates/setup.py.template b/src/zvt/autocode/templates/setup.py.template index 76ef1538..40c50a66 100644 --- a/src/zvt/autocode/templates/setup.py.template +++ b/src/zvt/autocode/templates/setup.py.template @@ -17,7 +17,7 @@ except ImportError: here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.md'), encoding='utf-8') as f: +with open(path.join(here, "README.md"), encoding="utf-8") as f: long_description = f.read() # Arguments marked as "Required" below must be included for upload to PyPI. @@ -31,36 +31,36 @@ except: requirements = [str(ir.requirement) for ir in install_reqs] setup( - name='${project}', - version='0.0.1', - description='unified,modular quant framework for human beings ', + name="${project}", + version="0.0.1", + description="unified,modular quant framework for human beings ", long_description=long_description, - url='https://github.com/zvtvz/${project}', - author='${user}', - author_email='${email}', + url="https://github.com/zvtvz/${project}", + author="${user}", + author_email="${email}", classifiers=[ # Optional - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'Intended Audience :: Customer Service', - 'Intended Audience :: Education', - 'Intended Audience :: Financial and Insurance Industry', - 'Topic :: Software Development :: Build Tools', - 'Topic :: Office/Business :: Financial :: Investment', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8' + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: Customer Service", + "Intended Audience :: Education", + "Intended Audience :: Financial and Insurance Industry", + "Topic :: Software Development :: Build Tools", + "Topic :: Office/Business :: Financial :: Investment", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", ], - keywords='quant stock finance fintech big-data zvt ma-analysis trading-platform pandas fundamental-analysis', - packages=find_packages(include=['${project}.*', '${project}']), - python_requires='>=3.5, <4', + keywords="quant stock finance fintech big-data zvt ma-analysis trading-platform pandas fundamental-analysis", + packages=find_packages(include=["${project}.*", "${project}"]), + python_requires=">=3.5, <4", include_package_data=True, install_requires=requirements, project_urls={ - 'Bug Reports': 'https://github.com/zvtvz/${project}/issues', - 'Funding': 'https://github.com/zvtvz/${project}', - 'Say Thanks!': 'https://saythanks.io/to/foolcage', - 'Source': 'https://github.com/zvtvz/${project}', + "Bug Reports": "https://github.com/zvtvz/${project}/issues", + "Funding": "https://github.com/zvtvz/${project}", + "Say Thanks!": "https://saythanks.io/to/foolcage", + "Source": "https://github.com/zvtvz/${project}", }, - long_description_content_type="text/markdown" + long_description_content_type="text/markdown", ) diff --git a/src/zvt/broker/__init__.py b/src/zvt/broker/__init__.py index 40a96afc..2686fff0 100644 --- a/src/zvt/broker/__init__.py +++ b/src/zvt/broker/__init__.py @@ -1 +1,5 @@ # -*- coding: utf-8 -*- + + +# the __all__ is generated +__all__ = [] diff --git a/src/zvt/broker/qmt/__init__.py b/src/zvt/broker/qmt/__init__.py index 40a96afc..2686fff0 100644 --- a/src/zvt/broker/qmt/__init__.py +++ b/src/zvt/broker/qmt/__init__.py @@ -1 +1,5 @@ # -*- coding: utf-8 -*- + + +# the __all__ is generated +__all__ = [] diff --git a/src/zvt/broker/qmt/context.py b/src/zvt/broker/qmt/context.py index 79a52151..995b035d 100644 --- a/src/zvt/broker/qmt/context.py +++ b/src/zvt/broker/qmt/context.py @@ -24,3 +24,7 @@ def init_qmt_account(qmt_mini_data_path=None, qmt_account_id=None): init_qmt_account() + + +# the __all__ is generated +__all__ = ["QmtContext", "init_qmt_account"] diff --git a/src/zvt/broker/qmt/errors.py b/src/zvt/broker/qmt/errors.py index 3c002ad1..ba5c8678 100644 --- a/src/zvt/broker/qmt/errors.py +++ b/src/zvt/broker/qmt/errors.py @@ -13,3 +13,7 @@ def __init__(self, message="qmt error"): class PositionOverflowError(TraderError): def __init__(self, message="超出仓位限制"): self.message = message + + +# the __all__ is generated +__all__ = ["TraderError", "QmtError", "PositionOverflowError"] diff --git a/src/zvt/broker/qmt/qmt_account.py b/src/zvt/broker/qmt/qmt_account.py index dbb6aa43..b734a483 100644 --- a/src/zvt/broker/qmt/qmt_account.py +++ b/src/zvt/broker/qmt/qmt_account.py @@ -7,12 +7,11 @@ from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback from xtquant.xttype import StockAccount, XtPosition - from zvt.broker.qmt.errors import QmtError, PositionOverflowError from zvt.broker.qmt.qmt_quote import _to_qmt_code from zvt.common.trading_models import BuyPositionStrategy, PositionType, SellPositionStrategy from zvt.trader import AccountService, TradingSignal, OrderType, trading_signal_type_to_order_type -from zvt.utils import now_pd_timestamp, to_pd_timestamp +from zvt.utils.time_utils import now_pd_timestamp, to_pd_timestamp logger = logging.getLogger(__name__) @@ -293,3 +292,7 @@ def buy(self, position_strategy: BuyPositionStrategy): if __name__ == "__main__": account = QmtStockAccount(path=r"D:\qmt\userdata_mini", account_id="") account.get_positions() + + +# the __all__ is generated +__all__ = ["MyXtQuantTraderCallback", "QmtStockAccount"] diff --git a/src/zvt/broker/qmt/qmt_quote.py b/src/zvt/broker/qmt/qmt_quote.py index 516540a1..eea36864 100644 --- a/src/zvt/broker/qmt/qmt_quote.py +++ b/src/zvt/broker/qmt/qmt_quote.py @@ -9,12 +9,8 @@ from zvt.contract import IntervalLevel, AdjustType from zvt.contract.api import decode_entity_id, df_to_db, get_db_session from zvt.domain import StockQuote, Stock -from zvt.utils import ( - to_time_str, - current_date, - to_pd_timestamp, - pd_is_not_null, -) +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import to_time_str, current_date, to_pd_timestamp # https://dict.thinktrader.net/nativeApi/start_now.html?id=e2M5nZ @@ -251,3 +247,14 @@ def clear_history_quote(): print(stocks) xtdata.subscribe_whole_quote(stocks, callback=tick_to_quote()) xtdata.run() + + +# the __all__ is generated +__all__ = [ + "get_qmt_stocks", + "get_entity_list", + "get_kdata", + "tick_to_quote", + "download_capital_data", + "clear_history_quote", +] diff --git a/src/zvt/common/__init__.py b/src/zvt/common/__init__.py index 40a96afc..2686fff0 100644 --- a/src/zvt/common/__init__.py +++ b/src/zvt/common/__init__.py @@ -1 +1,5 @@ # -*- coding: utf-8 -*- + + +# the __all__ is generated +__all__ = [] diff --git a/src/zvt/common/query_models.py b/src/zvt/common/query_models.py index f0627c69..d464295d 100644 --- a/src/zvt/common/query_models.py +++ b/src/zvt/common/query_models.py @@ -33,3 +33,7 @@ class RelativeTimeRage(BaseModel): class TimeRange(BaseModel): absolute_time_range: Optional[AbsoluteTimeRange] = Field(default=None) relative_time_range: Optional[RelativeTimeRage] = Field(default=None) + + +# the __all__ is generated +__all__ = ["OrderByType", "TimeUnit", "AbsoluteTimeRange", "RelativeTimeRage", "TimeRange"] diff --git a/src/zvt/common/trading_models.py b/src/zvt/common/trading_models.py index ab0384ba..8418f5af 100644 --- a/src/zvt/common/trading_models.py +++ b/src/zvt/common/trading_models.py @@ -29,3 +29,7 @@ class SellPositionStrategy(BaseModel): class TradingResult(BaseModel): success_entity_ids: Optional[List[str]] = Field(default=None) failed_entity_ids: Optional[List[str]] = Field(default=None) + + +# the __all__ is generated +__all__ = ["PositionType", "BuyPositionStrategy", "SellPositionStrategy", "TradingResult"] diff --git a/src/zvt/consts.py b/src/zvt/consts.py index 88317fa0..7d87b366 100644 --- a/src/zvt/consts.py +++ b/src/zvt/consts.py @@ -15,8 +15,7 @@ DATA_SAMPLE_ZIP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "samples", "data.zip")) # ****** setting for stocks ****** # -# 覆盖维度 银行/保险/企业/券商 创业板 中小板 主板 -SAMPLE_STOCK_CODES = ["000001", "000783", "000778", "603220", "601318", "000338", "002572", "300027"] +SAMPLE_STOCK_CODES = ["000001", "000002"] # 沪深300,证券,中证500,上证50,创业板,军工,传媒,资源 SAMPLE_ETF_CODES = ["510300", "512880", "510500", "510050", "159915", "512660", "512980", "510410"] diff --git a/src/zvt/contract/__init__.py b/src/zvt/contract/__init__.py index 7657b0a8..8cd5d7f0 100644 --- a/src/zvt/contract/__init__.py +++ b/src/zvt/contract/__init__.py @@ -257,17 +257,9 @@ def get_entity_exchanges(entity_type): zvt_context = zvt_context + # the __all__ is generated -__all__ = [ - "IntervalLevel", - "AdjustType", - "ActorType", - "TradableType", - "Exchange", - "tradable_type_map_exchanges", - "get_entity_exchanges", - "zvt_context", -] +__all__ = ["IntervalLevel", "AdjustType", "ActorType", "TradableType", "Exchange", "get_entity_exchanges"] # __init__.py structure: # common code of the package diff --git a/src/zvt/contract/api.py b/src/zvt/contract/api.py index 715fdfed..ee9e214a 100644 --- a/src/zvt/contract/api.py +++ b/src/zvt/contract/api.py @@ -9,10 +9,10 @@ from sqlalchemy import create_engine from sqlalchemy import func, exists, and_ from sqlalchemy.engine import Engine -from sqlalchemy.sql.expression import text from sqlalchemy.ext.declarative import DeclarativeMeta from sqlalchemy.orm import Query from sqlalchemy.orm import sessionmaker, Session +from sqlalchemy.sql.expression import text from zvt import zvt_env from zvt.contract import IntervalLevel @@ -680,15 +680,15 @@ def get_entity_ids( if __name__ == "__main__": print(get_entities(entity_type="block")) + + # the __all__ is generated __all__ = [ - "_get_db_name", "get_db_engine", "get_providers", "get_schemas", "get_db_session", "get_db_session_factory", - "DBSession", "get_entity_schema", "get_schema_by_name", "get_schema_columns", diff --git a/src/zvt/contract/base_service.py b/src/zvt/contract/base_service.py index d52f35b8..32212f25 100644 --- a/src/zvt/contract/base_service.py +++ b/src/zvt/contract/base_service.py @@ -4,7 +4,7 @@ from zvt.contract.api import del_data, get_db_session from zvt.contract.zvt_info import StateMixin -from zvt.utils import to_snake_str +from zvt.utils.str_utils import to_snake_str class StatefulService(object): diff --git a/src/zvt/contract/context.py b/src/zvt/contract/context.py index 775c2a3c..a91f47e3 100644 --- a/src/zvt/contract/context.py +++ b/src/zvt/contract/context.py @@ -50,5 +50,6 @@ def __init__(self) -> None: #: :class:`~.zvt.contract.context.Registry` instance zvt_context = Registry() + # the __all__ is generated -__all__ = ["Registry", "zvt_context"] +__all__ = ["Registry"] diff --git a/src/zvt/contract/drawer.py b/src/zvt/contract/drawer.py index 64178d7a..6a1ebeb6 100644 --- a/src/zvt/contract/drawer.py +++ b/src/zvt/contract/drawer.py @@ -11,7 +11,7 @@ from zvt.contract.api import decode_entity_id from zvt.contract.data_type import Bean from zvt.contract.normal_data import NormalData -from zvt.utils import to_string +from zvt.utils.decorator import to_string from zvt.utils.pd_utils import pd_is_not_null logger = logging.getLogger(__name__) diff --git a/src/zvt/contract/factor.py b/src/zvt/contract/factor.py index 249b2e58..00ade751 100644 --- a/src/zvt/contract/factor.py +++ b/src/zvt/contract/factor.py @@ -14,9 +14,9 @@ from zvt.contract.reader import DataReader, DataListener from zvt.contract.schema import Mixin, TradableEntity from zvt.contract.zvt_info import FactorState -from zvt.utils import to_pd_timestamp from zvt.utils.pd_utils import pd_is_not_null, drop_continue_duplicate, is_filter_result_df, is_score_result_df from zvt.utils.str_utils import to_snake_str +from zvt.utils.time_utils import to_pd_timestamp class TargetType(Enum): @@ -672,12 +672,4 @@ def compute_result(self): # the __all__ is generated -__all__ = [ - "Indicator", - "Transformer", - "Accumulator", - "Scorer", - "FactorMeta", - "Factor", - "ScoreFactor", -] +__all__ = ["TargetType", "Indicator", "Transformer", "Accumulator", "Scorer", "FactorMeta", "Factor", "ScoreFactor"] diff --git a/src/zvt/contract/model.py b/src/zvt/contract/model.py index 3e49204c..39a3b0eb 100644 --- a/src/zvt/contract/model.py +++ b/src/zvt/contract/model.py @@ -12,3 +12,7 @@ class MixinModel(CustomModel): id: str entity_id: str timestamp: datetime + + +# the __all__ is generated +__all__ = ["CustomModel", "MixinModel"] diff --git a/src/zvt/contract/reader.py b/src/zvt/contract/reader.py index a7828bb6..b0990b3e 100644 --- a/src/zvt/contract/reader.py +++ b/src/zvt/contract/reader.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import json import logging import time from typing import List, Union, Type, Optional @@ -284,5 +283,7 @@ def drawer_main_df(self) -> Optional[pd.DataFrame]: ) data_reader.draw(show=True) + + # the __all__ is generated __all__ = ["DataListener", "DataReader"] diff --git a/src/zvt/contract/recorder.py b/src/zvt/contract/recorder.py index ab1c894f..23cc3d37 100644 --- a/src/zvt/contract/recorder.py +++ b/src/zvt/contract/recorder.py @@ -13,7 +13,7 @@ from zvt.contract.base_service import OneStateService from zvt.contract.schema import Mixin, TradableEntity from zvt.contract.zvt_info import RecorderState -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null from zvt.utils.time_utils import ( to_pd_timestamp, TIME_FORMAT_DAY, diff --git a/src/zvt/contract/register.py b/src/zvt/contract/register.py index d1cd5515..029e511e 100644 --- a/src/zvt/contract/register.py +++ b/src/zvt/contract/register.py @@ -3,14 +3,14 @@ from typing import List import sqlalchemy -from sqlalchemy import Column, inspect, MetaData -from sqlalchemy.schema import Table +from sqlalchemy import MetaData from sqlalchemy.ext.declarative import DeclarativeMeta from sqlalchemy.sql.ddl import CreateTable from sqlalchemy.sql.expression import text + from zvt.contract import zvt_context -from zvt.contract.schema import TradableEntity, Mixin from zvt.contract.api import get_db_engine, get_db_session_factory +from zvt.contract.schema import TradableEntity, Mixin from zvt.utils.utils import add_to_map_list logger = logging.getLogger(__name__) diff --git a/src/zvt/contract/zvt_info.py b/src/zvt/contract/zvt_info.py index 1c35dd3c..7eed002e 100644 --- a/src/zvt/contract/zvt_info.py +++ b/src/zvt/contract/zvt_info.py @@ -42,5 +42,6 @@ class FactorState(ZvtInfoBase, StateMixin): register_schema(providers=["zvt"], db_name="zvt_info", schema_base=ZvtInfoBase) + # the __all__ is generated __all__ = ["StateMixin", "RecorderState", "TaggerState", "FactorState"] diff --git a/src/zvt/domain/meta/country_meta.py b/src/zvt/domain/meta/country_meta.py index 9b177973..037cd45c 100644 --- a/src/zvt/domain/meta/country_meta.py +++ b/src/zvt/domain/meta/country_meta.py @@ -3,8 +3,8 @@ from sqlalchemy import Column, String, Float from sqlalchemy.orm import declarative_base -from zvt.contract.schema import TradableEntity from zvt.contract.register import register_schema, register_entity +from zvt.contract.schema import TradableEntity CountryMetaBase = declarative_base() diff --git a/src/zvt/domain/meta/fund_meta.py b/src/zvt/domain/meta/fund_meta.py index 66c001e9..9fe6f80d 100644 --- a/src/zvt/domain/meta/fund_meta.py +++ b/src/zvt/domain/meta/fund_meta.py @@ -4,7 +4,7 @@ from zvt.contract import Portfolio, PortfolioStockHistory from zvt.contract.register import register_entity, register_schema -from zvt.utils import now_pd_timestamp +from zvt.utils.time_utils import now_pd_timestamp FundMetaBase = declarative_base() diff --git a/src/zvt/domain/quotes/stock/stock_quote.py b/src/zvt/domain/quotes/stock/stock_quote.py index 80b08633..99165977 100644 --- a/src/zvt/domain/quotes/stock/stock_quote.py +++ b/src/zvt/domain/quotes/stock/stock_quote.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from sqlalchemy import String, Column, Float, Integer, JSON, Boolean +from sqlalchemy import String, Column, Float, Integer, Boolean from sqlalchemy.orm import declarative_base from zvt.contract import Mixin diff --git a/src/zvt/factors/__init__.py b/src/zvt/factors/__init__.py index 2596ca2f..62b233ab 100644 --- a/src/zvt/factors/__init__.py +++ b/src/zvt/factors/__init__.py @@ -11,12 +11,24 @@ __all__ += _algorithm_all +# import all from submodule top_stocks +from .top_stocks import * +from .top_stocks import __all__ as _top_stocks_all + +__all__ += _top_stocks_all + # import all from submodule ma from .ma import * from .ma import __all__ as _ma_all __all__ += _ma_all +# import all from submodule transformers +from .transformers import * +from .transformers import __all__ as _transformers_all + +__all__ += _transformers_all + # import all from submodule macd from .macd import * from .macd import __all__ as _macd_all @@ -41,6 +53,18 @@ __all__ += _fundamental_all +# import all from submodule factor_service +from .factor_service import * +from .factor_service import __all__ as _factor_service_all + +__all__ += _factor_service_all + +# import all from submodule factor_models +from .factor_models import * +from .factor_models import __all__ as _factor_models_all + +__all__ += _factor_models_all + # import all from submodule target_selector from .target_selector import * from .target_selector import __all__ as _target_selector_all diff --git a/src/zvt/factors/factor_models.py b/src/zvt/factors/factor_models.py index 73aef5d8..3fc179c7 100644 --- a/src/zvt/factors/factor_models.py +++ b/src/zvt/factors/factor_models.py @@ -1,16 +1,12 @@ # -*- coding: utf-8 -*- from datetime import datetime -from typing import Dict, Union, List, Optional +from typing import List, Optional -from pydantic import BaseModel, field_validator, Field -from pydantic_core.core_schema import ValidationInfo +from pydantic import BaseModel, Field from zvt.contract import IntervalLevel, AdjustType -from zvt.contract.model import MixinModel -from zvt.tag.common import StockPoolType -from zvt.tag.tag_utils import get_main_tags, get_sub_tags, get_hidden_tags, get_stock_pool_names from zvt.trader import TradingSignalType -from zvt.utils import date_time_by_interval, current_date +from zvt.utils.time_utils import date_time_by_interval, current_date class FactorRequestModel(BaseModel): @@ -52,3 +48,7 @@ class TradingSignalModel(BaseModel): class FactorResultModel(BaseModel): entity_ids: Optional[List[str]] tag_reason: str + + +# the __all__ is generated +__all__ = ["FactorRequestModel", "KdataRequestModel", "KdataModel", "TradingSignalModel", "FactorResultModel"] diff --git a/src/zvt/factors/factor_service.py b/src/zvt/factors/factor_service.py index 8efac2ac..0da14268 100644 --- a/src/zvt/factors/factor_service.py +++ b/src/zvt/factors/factor_service.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- import pandas as pd +from zvt.api import kdata as kdata_api from zvt.contract import zvt_context from zvt.domain import Stock -from zvt.factors import TechnicalFactor +from zvt.factors.technical_factor import TechnicalFactor from zvt.factors.factor_models import FactorRequestModel, KdataRequestModel from zvt.trader import TradingSignalType -from zvt.api import kdata as kdata_api -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null def query_kdata(kdata_request_model: KdataRequestModel): @@ -74,3 +74,7 @@ def to_trading_signal(order_type): print(df) return df.to_dict(orient="records") + + +# the __all__ is generated +__all__ = ["query_kdata", "query_factor_result"] diff --git a/src/zvt/factors/fundamental/__init__.py b/src/zvt/factors/fundamental/__init__.py index fe11c5e2..509f9c6c 100644 --- a/src/zvt/factors/fundamental/__init__.py +++ b/src/zvt/factors/fundamental/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*-# + + # the __all__ is generated __all__ = [] diff --git a/src/zvt/factors/fundamental/finance_factor.py b/src/zvt/factors/fundamental/finance_factor.py index 2b2c563e..660cd514 100644 --- a/src/zvt/factors/fundamental/finance_factor.py +++ b/src/zvt/factors/fundamental/finance_factor.py @@ -224,5 +224,7 @@ def compute_result(self): col_period_threshold=None, ) print(factor2.result_df) + + # the __all__ is generated __all__ = ["FinanceBaseFactor", "GoodCompanyFactor"] diff --git a/src/zvt/factors/ma/__init__.py b/src/zvt/factors/ma/__init__.py index 75542910..69d5d8bc 100644 --- a/src/zvt/factors/ma/__init__.py +++ b/src/zvt/factors/ma/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*-# + + # the __all__ is generated __all__ = [] diff --git a/src/zvt/factors/ma/domain/__init__.py b/src/zvt/factors/ma/domain/__init__.py index 6aea5100..c12d8e36 100644 --- a/src/zvt/factors/ma/domain/__init__.py +++ b/src/zvt/factors/ma/domain/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- + + # the __all__ is generated __all__ = [] diff --git a/src/zvt/factors/ma/domain/stock_1d_ma_factor.py b/src/zvt/factors/ma/domain/stock_1d_ma_factor.py index 8aca25bd..2ba6ce29 100644 --- a/src/zvt/factors/ma/domain/stock_1d_ma_factor.py +++ b/src/zvt/factors/ma/domain/stock_1d_ma_factor.py @@ -33,5 +33,7 @@ class Stock1dMaFactor(Stock1dMaFactorBase, Mixin): register_schema(providers=["zvt"], db_name="stock_1d_ma_factor", schema_base=Stock1dMaFactorBase) + + # the __all__ is generated __all__ = ["Stock1dMaFactor"] diff --git a/src/zvt/factors/ma/domain/stock_1d_ma_stats_factor.py b/src/zvt/factors/ma/domain/stock_1d_ma_stats_factor.py index b0c1e310..72f0adb7 100644 --- a/src/zvt/factors/ma/domain/stock_1d_ma_stats_factor.py +++ b/src/zvt/factors/ma/domain/stock_1d_ma_stats_factor.py @@ -12,5 +12,7 @@ class Stock1dMaStatsFactor(Stock1dMaStatsFactorBase, MaStatsFactorCommon): register_schema(providers=["zvt"], db_name="stock_1d_ma_stats_factor", schema_base=Stock1dMaStatsFactorBase) + + # the __all__ is generated __all__ = ["Stock1dMaStatsFactor"] diff --git a/src/zvt/factors/ma/ma_factor.py b/src/zvt/factors/ma/ma_factor.py index e07d1142..0aef3996 100644 --- a/src/zvt/factors/ma/ma_factor.py +++ b/src/zvt/factors/ma/ma_factor.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -import argparse from typing import List, Union, Type import pandas as pd from zvt.contract import IntervalLevel, TradableEntity, AdjustType -from zvt.contract.api import get_entities, get_schema_by_name +from zvt.contract.api import get_schema_by_name from zvt.contract.factor import Accumulator from zvt.contract.factor import Transformer from zvt.domain import Stock @@ -259,5 +258,7 @@ def compute_result(self): ) selected = factor.get_targets(timestamp="2021-12-30") print(selected) + + # the __all__ is generated __all__ = ["get_ma_factor_schema", "MaFactor", "CrossMaFactor", "VolumeUpMaFactor", "CrossMaVolumeFactor"] diff --git a/src/zvt/factors/ma/ma_stats_factor.py b/src/zvt/factors/ma/ma_stats_factor.py index caf0aeeb..ad9b4f85 100644 --- a/src/zvt/factors/ma/ma_stats_factor.py +++ b/src/zvt/factors/ma/ma_stats_factor.py @@ -9,7 +9,7 @@ from zvt.domain import Stock from zvt.factors.algorithm import live_or_dead from zvt.factors.technical_factor import TechnicalFactor -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null def get_ma_stats_factor_schema(entity_type: str, level: Union[IntervalLevel, str] = IntervalLevel.LEVEL_1DAY): @@ -218,5 +218,6 @@ def drawer_factor_df_list(self) -> Optional[List[pd.DataFrame]]: # distribute(f.factor_df[['area']],'area') f.draw(show=True) + # the __all__ is generated __all__ = ["get_ma_stats_factor_schema", "MaStatsAccumulator", "MaStatsFactor", "TFactor"] diff --git a/src/zvt/factors/ma/top_bottom_factor.py b/src/zvt/factors/ma/top_bottom_factor.py index 3beee8a7..14c7ca72 100644 --- a/src/zvt/factors/ma/top_bottom_factor.py +++ b/src/zvt/factors/ma/top_bottom_factor.py @@ -110,5 +110,7 @@ def __init__( drawer = Drawer(main_df=data_reader1.data_df, factor_df_list=[factor.factor_df[["top", "bottom"]]]) drawer.draw_kline(show=True) + + # the __all__ is generated __all__ = ["TopBottomTransformer", "TopBottomFactor"] diff --git a/src/zvt/factors/macd/__init__.py b/src/zvt/factors/macd/__init__.py index 431c2948..76804cb8 100644 --- a/src/zvt/factors/macd/__init__.py +++ b/src/zvt/factors/macd/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- + + # the __all__ is generated __all__ = [] diff --git a/src/zvt/factors/macd/macd_factor.py b/src/zvt/factors/macd/macd_factor.py index 9dba7e6b..444b42b9 100644 --- a/src/zvt/factors/macd/macd_factor.py +++ b/src/zvt/factors/macd/macd_factor.py @@ -66,5 +66,7 @@ def compute_result(self): f.update_entity_ids(["stock_sz_000338", "stock_sh_600000"]) f.move_on() print(f.data_df) + + # the __all__ is generated __all__ = ["MacdFactor", "BullFactor", "KeepBullFactor", "LiveOrDeadFactor", "GoldCrossFactor"] diff --git a/src/zvt/factors/shape.py b/src/zvt/factors/shape.py index 58f8a590..2687c1fc 100644 --- a/src/zvt/factors/shape.py +++ b/src/zvt/factors/shape.py @@ -9,8 +9,7 @@ from zvt.contract.data_type import Bean from zvt.contract.drawer import Rect from zvt.factors.algorithm import intersect -from zvt.utils import to_time_str -from zvt.utils.time_utils import TIME_FORMAT_ISO8601 +from zvt.utils.time_utils import TIME_FORMAT_ISO8601, to_time_str logger = logging.getLogger(__name__) diff --git a/src/zvt/factors/top_stocks.py b/src/zvt/factors/top_stocks.py index 3a55cd97..d782be48 100644 --- a/src/zvt/factors/top_stocks.py +++ b/src/zvt/factors/top_stocks.py @@ -2,20 +2,31 @@ import json from typing import List -from sqlalchemy import Column, String +from sqlalchemy import Column, String, Integer from sqlalchemy.orm import declarative_base -from sqlalchemy import Column, String, Integer, DateTime, Boolean, Float -from zvt.api import get_latest_kdata_date, get_mini_and_small_stock, get_middle_and_big_stock, get_trade_dates -from zvt.api.selector import get_entity_ids_by_filter, get_limit_up_stocks +from zvt.api.kdata import get_trade_dates +from zvt.api.selector import ( + get_entity_ids_by_filter, + get_limit_up_stocks, + get_mini_and_small_stock, + get_middle_and_big_stock, +) from zvt.api.stats import get_top_performance_entities_by_periods, TopType from zvt.contract import Mixin, AdjustType from zvt.contract.api import get_db_session from zvt.contract.factor import TargetType from zvt.contract.register import register_schema -from zvt.domain import Stock, Stock1dHfqKdata, LimitUpInfo -from zvt.factors import VolumeUpMaFactor -from zvt.utils import date_time_by_interval, to_time_str, TIME_FORMAT_DAY, today, count_interval, to_pd_timestamp +from zvt.domain import Stock, Stock1dHfqKdata +from zvt.factors.ma.ma_factor import VolumeUpMaFactor +from zvt.utils.time_utils import ( + date_time_by_interval, + to_time_str, + TIME_FORMAT_DAY, + today, + count_interval, + to_pd_timestamp, +) TopStocksBase = declarative_base() @@ -266,3 +277,14 @@ def get_top_stocks(target_date, return_type="short"): # print(stocks) # stocks = get_top_stocks(target_date=target_date, return_type="big_vol_up") # print(stocks) + + +# the __all__ is generated +__all__ = [ + "TopStocks", + "get_vol_up_stocks", + "update_with_limit_up", + "update_vol_up", + "compute_top_stocks", + "get_top_stocks", +] diff --git a/src/zvt/factors/transformers.py b/src/zvt/factors/transformers.py index 4e084497..a48a9ceb 100644 --- a/src/zvt/factors/transformers.py +++ b/src/zvt/factors/transformers.py @@ -3,10 +3,10 @@ import pandas as pd from zvt.contract.factor import Transformer -from zvt.domain import Stock1dHfqKdata -from zvt.factors import MaTransformer, TechnicalFactor -from zvt.utils import to_pd_timestamp +from zvt.factors.algorithm import MaTransformer +from zvt.factors.technical_factor import TechnicalFactor from zvt.utils.pd_utils import group_by_entity_id, normalize_group_compute_result, merge_filter_result +from zvt.utils.time_utils import to_pd_timestamp def _cal_state(s, df, pre, interval, col): @@ -88,3 +88,7 @@ def transform(self, input_df: pd.DataFrame) -> pd.DataFrame: # df = FallBelowTransformer().transform(df) # print(df["filter_result"]) TechnicalFactor(transformer=SpecificTransformer(timestamp="2020-03-01")) + + +# the __all__ is generated +__all__ = ["CrossMaTransformer", "SpecificTransformer", "FallBelowTransformer"] diff --git a/src/zvt/factors/z/domain/stock_1d_z_factor.py b/src/zvt/factors/z/domain/stock_1d_z_factor.py index b66ce6c7..7a03a4fe 100644 --- a/src/zvt/factors/z/domain/stock_1d_z_factor.py +++ b/src/zvt/factors/z/domain/stock_1d_z_factor.py @@ -12,5 +12,7 @@ class Stock1dZFactor(Stock1dZFactorBase, ZFactorCommon): register_schema(providers=["zvt"], db_name="stock_1d_z_factor", schema_base=Stock1dZFactorBase, entity_type="stock") + + # the __all__ is generated __all__ = ["Stock1dZFactor"] diff --git a/src/zvt/factors/z/domain/stock_1wk_z_factor.py b/src/zvt/factors/z/domain/stock_1wk_z_factor.py index 37a3814d..9b617e34 100644 --- a/src/zvt/factors/z/domain/stock_1wk_z_factor.py +++ b/src/zvt/factors/z/domain/stock_1wk_z_factor.py @@ -12,5 +12,7 @@ class Stock1wkZFactor(Stock1wkZFactorBase, ZFactorCommon): register_schema(providers=["zvt"], db_name="stock_1wk_z_factor", schema_base=Stock1wkZFactorBase, entity_type="stock") + + # the __all__ is generated __all__ = ["Stock1wkZFactor"] diff --git a/src/zvt/factors/z/z_factor.py b/src/zvt/factors/z/z_factor.py index 2cbdd5e4..2cb5a21b 100644 --- a/src/zvt/factors/z/z_factor.py +++ b/src/zvt/factors/z/z_factor.py @@ -13,7 +13,7 @@ from zvt.contract.drawer import Rect from zvt.contract.factor import Accumulator from zvt.contract.factor import Transformer -from zvt.domain import Stock, Index, Index1dKdata +from zvt.domain import Stock from zvt.factors.shape import ( Fenxing, Direction, @@ -27,7 +27,8 @@ FactorStateEncoder, ) from zvt.factors.technical_factor import TechnicalFactor -from zvt.utils import pd_is_not_null, to_string +from zvt.utils.decorator import to_string +from zvt.utils.pd_utils import pd_is_not_null logger = logging.getLogger(__name__) @@ -552,5 +553,7 @@ def drawer_sub_df_list(self) -> Optional[List[pd.DataFrame]]: need_persist=True, ) f.draw(show=True) + + # the __all__ is generated __all__ = ["get_z_factor_schema", "ZState", "ZAccumulator", "ZFactor"] diff --git a/src/zvt/fill_project.py b/src/zvt/fill_project.py index d0a29b00..01ea03fb 100644 --- a/src/zvt/fill_project.py +++ b/src/zvt/fill_project.py @@ -87,15 +87,20 @@ def gen_kdata_schemas(): if __name__ == "__main__": - # zip_dir(ZVT_TEST_DATA_PATH, zip_file_name=DATA_SAMPLE_ZIP_PATH) - # gen_exports("contract", export_modules=["schema"]) + # gen_exports("api") + # gen_exports("broker") + # gen_exports("common") + # gen_exports("contract", export_from_package=True, export_modules=["schema"]) + # gen_exports("tag") + gen_exports("factors", export_from_package=True) + # gen_exports("trading") + # gen_exports("ml") - gen_exports("utils", export_var=True) + # gen_exports("utils", export_from_package=False, export_var=True) # gen_exports('informer') - # gen_exports("api") # gen_exports('trader') # gen_exports('autocode') - gen_exports("zhdate") - # gen_kdata_schemas() + # gen_exports("zhdate") # gen_exports("recorders") - # gen_exports("tag") + # gen_kdata_schemas() + # zip_dir(ZVT_TEST_DATA_PATH, zip_file_name=DATA_SAMPLE_ZIP_PATH) diff --git a/src/zvt/main.py b/src/zvt/main.py index 837f93c6..468f05a2 100644 --- a/src/zvt/main.py +++ b/src/zvt/main.py @@ -2,7 +2,6 @@ from dash import html from dash.dependencies import Input, Output -from zvt import init_plugins from zvt.ui import zvt_app from zvt.ui.apps import factor_app @@ -36,7 +35,7 @@ def tab_content(active_tab): def main(): - init_plugins() + # init_plugins() zvt_app.run_server(debug=True) # zvt_app.run_server() diff --git a/src/zvt/ml/ml.py b/src/zvt/ml/ml.py index b4477a5a..296e1cdd 100644 --- a/src/zvt/ml/ml.py +++ b/src/zvt/ml/ml.py @@ -7,15 +7,15 @@ from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler -from zvt.ml.lables import RelativePerformance, BehaviorCategory from zvt.api.kdata import default_adjust_type, get_kdata from zvt.contract import IntervalLevel, AdjustType from zvt.contract import TradableEntity from zvt.contract.drawer import Drawer from zvt.domain import Stock -from zvt.factors import MaTransformer -from zvt.utils import to_pd_timestamp +from zvt.factors.transformers import MaTransformer +from zvt.ml.lables import RelativePerformance, BehaviorCategory from zvt.utils.pd_utils import group_by_entity_id, normalize_group_compute_result, pd_is_not_null +from zvt.utils.time_utils import to_pd_timestamp logger = logging.getLogger(__name__) diff --git a/src/zvt/recorders/eastmoney/common.py b/src/zvt/recorders/eastmoney/common.py index 41aa938d..a80aff44 100644 --- a/src/zvt/recorders/eastmoney/common.py +++ b/src/zvt/recorders/eastmoney/common.py @@ -6,7 +6,7 @@ from zvt.contract.api import get_data_count, get_data from zvt.contract.recorder import TimestampsDataRecorder, TimeSeriesDataRecorder from zvt.domain import CompanyType -from zvt.domain.meta.stock_meta import Stock, StockDetail +from zvt.domain.meta.stock_meta import StockDetail from zvt.utils.time_utils import to_pd_timestamp logger = logging.getLogger(__name__) diff --git a/src/zvt/recorders/eastmoney/holder/eastmoney_stock_actor_recorder.py b/src/zvt/recorders/eastmoney/holder/eastmoney_stock_actor_recorder.py index 95a42f4b..20538a43 100644 --- a/src/zvt/recorders/eastmoney/holder/eastmoney_stock_actor_recorder.py +++ b/src/zvt/recorders/eastmoney/holder/eastmoney_stock_actor_recorder.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import requests -from zvt.api import get_recent_report_date +from zvt.api.utils import get_recent_report_date from zvt.contract.recorder import Recorder from zvt.domain.actor.actor_meta import ActorMeta -from zvt.utils import to_pd_timestamp +from zvt.utils.time_utils import to_pd_timestamp class EastmoneyActorRecorder(Recorder): diff --git a/src/zvt/recorders/em/actor/em_stock_actor_summary_recorder.py b/src/zvt/recorders/em/actor/em_stock_actor_summary_recorder.py index 5be23cc6..61155b94 100644 --- a/src/zvt/recorders/em/actor/em_stock_actor_summary_recorder.py +++ b/src/zvt/recorders/em/actor/em_stock_actor_summary_recorder.py @@ -10,7 +10,7 @@ from zvt.domain import Stock from zvt.domain.actor.stock_actor import StockActorSummary from zvt.recorders.em.em_api import get_ii_holder_report_dates, actor_type_to_org_type, get_ii_summary -from zvt.utils import to_pd_timestamp, to_time_str +from zvt.utils.time_utils import to_pd_timestamp, to_time_str # [{'CHANGE_RATIO': -1.045966694333, diff --git a/src/zvt/recorders/em/actor/em_stock_ii_recorder.py b/src/zvt/recorders/em/actor/em_stock_ii_recorder.py index 1b80c2a2..ccc7cf2d 100644 --- a/src/zvt/recorders/em/actor/em_stock_ii_recorder.py +++ b/src/zvt/recorders/em/actor/em_stock_ii_recorder.py @@ -10,7 +10,7 @@ from zvt.domain import Stock, ActorMeta from zvt.domain.actor.stock_actor import StockInstitutionalInvestorHolder from zvt.recorders.em.em_api import get_ii_holder_report_dates, get_ii_holder, actor_type_to_org_type -from zvt.utils import to_pd_timestamp, to_time_str +from zvt.utils.time_utils import to_pd_timestamp, to_time_str # {'END_DATE': '2021-03-31 00:00:00', diff --git a/src/zvt/recorders/em/actor/em_stock_top_ten_free_recorder.py b/src/zvt/recorders/em/actor/em_stock_top_ten_free_recorder.py index 3e2f0b5e..5ade8d64 100644 --- a/src/zvt/recorders/em/actor/em_stock_top_ten_free_recorder.py +++ b/src/zvt/recorders/em/actor/em_stock_top_ten_free_recorder.py @@ -10,7 +10,7 @@ from zvt.domain import Stock, ActorMeta from zvt.domain.actor.stock_actor import StockTopTenFreeHolder, StockInstitutionalInvestorHolder from zvt.recorders.em.em_api import get_holder_report_dates, get_free_holders -from zvt.utils import to_pd_timestamp, to_time_str +from zvt.utils.time_utils import to_pd_timestamp, to_time_str class EMStockTopTenFreeRecorder(TimestampsDataRecorder): diff --git a/src/zvt/recorders/em/actor/em_stock_top_ten_recorder.py b/src/zvt/recorders/em/actor/em_stock_top_ten_recorder.py index 30c34663..4d3d3e0c 100644 --- a/src/zvt/recorders/em/actor/em_stock_top_ten_recorder.py +++ b/src/zvt/recorders/em/actor/em_stock_top_ten_recorder.py @@ -10,7 +10,7 @@ from zvt.domain import Stock, ActorMeta from zvt.domain.actor.stock_actor import StockTopTenHolder, StockInstitutionalInvestorHolder from zvt.recorders.em.em_api import get_holder_report_dates, get_holders -from zvt.utils import to_pd_timestamp, to_time_str +from zvt.utils.time_utils import to_pd_timestamp, to_time_str class EMStockTopTenRecorder(TimestampsDataRecorder): diff --git a/src/zvt/recorders/em/em_api.py b/src/zvt/recorders/em/em_api.py index 8aa79d3a..462a6532 100644 --- a/src/zvt/recorders/em/em_api.py +++ b/src/zvt/recorders/em/em_api.py @@ -7,19 +7,19 @@ import pandas as pd import requests -from zvt.api import generate_kdata_id, value_to_pct, china_stock_code_to_id +from zvt.api.kdata import generate_kdata_id +from zvt.api.utils import value_to_pct, china_stock_code_to_id from zvt.contract import ActorType, AdjustType, IntervalLevel, Exchange, TradableType, get_entity_exchanges from zvt.contract.api import decode_entity_id from zvt.domain import BlockCategory from zvt.recorders.consts import DEFAULT_HEADER -from zvt.utils import ( +from zvt.utils.time_utils import ( to_pd_timestamp, - to_float, - json_callback_param, now_timestamp, to_time_str, current_date, ) +from zvt.utils.utils import to_float, json_callback_param logger = logging.getLogger(__name__) diff --git a/src/zvt/recorders/em/meta/em_currency_meta_recorder.py b/src/zvt/recorders/em/meta/em_currency_meta_recorder.py index 14571ba5..bfed8b0a 100644 --- a/src/zvt/recorders/em/meta/em_currency_meta_recorder.py +++ b/src/zvt/recorders/em/meta/em_currency_meta_recorder.py @@ -2,7 +2,6 @@ from zvt.contract.api import df_to_db from zvt.contract.recorder import Recorder -from zvt.domain import Future from zvt.domain.meta.currency_meta import Currency from zvt.recorders.em import em_api 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 73dac23f..7f82eed0 100644 --- a/src/zvt/recorders/em/meta/em_stock_meta_recorder.py +++ b/src/zvt/recorders/em/meta/em_stock_meta_recorder.py @@ -7,7 +7,7 @@ from zvt.contract.recorder import Recorder from zvt.domain import Stock from zvt.recorders.em import em_api -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null class EMStockRecorder(Recorder): diff --git a/src/zvt/recorders/em/misc/em_stock_news_recorder.py b/src/zvt/recorders/em/misc/em_stock_news_recorder.py index fa77d830..157d561c 100644 --- a/src/zvt/recorders/em/misc/em_stock_news_recorder.py +++ b/src/zvt/recorders/em/misc/em_stock_news_recorder.py @@ -6,7 +6,7 @@ from zvt.domain import Stock from zvt.domain.misc.stock_news import StockNews from zvt.recorders.em import em_api -from zvt.utils import to_pd_timestamp, count_interval, now_pd_timestamp +from zvt.utils.time_utils import to_pd_timestamp, count_interval, now_pd_timestamp class EMStockNewsRecorder(FixedCycleDataRecorder): diff --git a/src/zvt/recorders/em/quotes/em_kdata_recorder.py b/src/zvt/recorders/em/quotes/em_kdata_recorder.py index 1c00201b..fa78f68b 100644 --- a/src/zvt/recorders/em/quotes/em_kdata_recorder.py +++ b/src/zvt/recorders/em/quotes/em_kdata_recorder.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import requests + from zvt.api.kdata import get_kdata_schema from zvt.contract import IntervalLevel, AdjustType from zvt.contract.api import df_to_db @@ -20,11 +22,10 @@ Currency, CurrencyKdataCommon, ) -import requests from zvt.domain.meta.stockhk_meta import Stockhk from zvt.domain.meta.stockus_meta import Stockus from zvt.recorders.em.em_api import get_kdata -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null class BaseEMStockKdataRecorder(FixedCycleDataRecorder): diff --git a/src/zvt/recorders/em/trading/em_dragon_and_tiger_recorder.py b/src/zvt/recorders/em/trading/em_dragon_and_tiger_recorder.py index 7fcf4ae7..dce870a6 100644 --- a/src/zvt/recorders/em/trading/em_dragon_and_tiger_recorder.py +++ b/src/zvt/recorders/em/trading/em_dragon_and_tiger_recorder.py @@ -6,7 +6,7 @@ from zvt.contract.recorder import FixedCycleDataRecorder from zvt.domain import Stock, DragonAndTiger from zvt.recorders.em import em_api -from zvt.utils import to_pd_timestamp, to_time_str, TIME_FORMAT_DAY, date_time_by_interval +from zvt.utils.time_utils import to_pd_timestamp, to_time_str, TIME_FORMAT_DAY, date_time_by_interval { "TRADE_ID": "3066028", diff --git a/src/zvt/recorders/exchange/api/cn_index_api.py b/src/zvt/recorders/exchange/api/cn_index_api.py index 142e4033..fc18b2bb 100644 --- a/src/zvt/recorders/exchange/api/cn_index_api.py +++ b/src/zvt/recorders/exchange/api/cn_index_api.py @@ -7,7 +7,7 @@ from zvt.domain import IndexCategory from zvt.recorders.consts import DEFAULT_HEADER -from zvt.utils import to_pd_timestamp +from zvt.utils.time_utils import to_pd_timestamp logger = logging.getLogger(__name__) diff --git a/src/zvt/recorders/exchange/api/cs_index_api.py b/src/zvt/recorders/exchange/api/cs_index_api.py index 517b8f53..2c734dc0 100644 --- a/src/zvt/recorders/exchange/api/cs_index_api.py +++ b/src/zvt/recorders/exchange/api/cs_index_api.py @@ -6,7 +6,7 @@ from zvt.domain import IndexCategory from zvt.recorders.consts import DEFAULT_HEADER -from zvt.utils import to_pd_timestamp +from zvt.utils.time_utils import to_pd_timestamp logger = logging.getLogger(__name__) diff --git a/src/zvt/recorders/exchange/api/cs_index_stock_api.py b/src/zvt/recorders/exchange/api/cs_index_stock_api.py index 2fd691d5..7b6adaf7 100644 --- a/src/zvt/recorders/exchange/api/cs_index_stock_api.py +++ b/src/zvt/recorders/exchange/api/cs_index_stock_api.py @@ -5,9 +5,9 @@ import pandas as pd import requests -from zvt.api import china_stock_code_to_id +from zvt.api.utils import china_stock_code_to_id from zvt.recorders.consts import DEFAULT_HEADER -from zvt.utils import now_pd_timestamp +from zvt.utils.time_utils import now_pd_timestamp logger = logging.getLogger(__name__) diff --git a/src/zvt/recorders/exchange/exchange_index_stock_recorder.py b/src/zvt/recorders/exchange/exchange_index_stock_recorder.py index 2d3377d6..70d90b50 100644 --- a/src/zvt/recorders/exchange/exchange_index_stock_recorder.py +++ b/src/zvt/recorders/exchange/exchange_index_stock_recorder.py @@ -3,7 +3,6 @@ from typing import List import pandas as pd -import requests from zvt.contract.api import df_to_db from zvt.contract.recorder import TimestampsDataRecorder diff --git a/src/zvt/recorders/joinquant/misc/jq_index_money_flow_recorder.py b/src/zvt/recorders/joinquant/misc/jq_index_money_flow_recorder.py index 481cfc66..7deec9f5 100644 --- a/src/zvt/recorders/joinquant/misc/jq_index_money_flow_recorder.py +++ b/src/zvt/recorders/joinquant/misc/jq_index_money_flow_recorder.py @@ -5,7 +5,8 @@ from zvt.contract.api import df_to_db from zvt.contract.recorder import FixedCycleDataRecorder from zvt.domain import IndexMoneyFlow, Index, StockMoneyFlow -from zvt.utils import pd_is_not_null, to_time_str +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import to_time_str class JoinquantIndexMoneyFlowRecorder(FixedCycleDataRecorder): diff --git a/src/zvt/recorders/joinquant/misc/jq_stock_money_flow_recorder.py b/src/zvt/recorders/joinquant/misc/jq_stock_money_flow_recorder.py index 43f86e3b..c530dd0f 100644 --- a/src/zvt/recorders/joinquant/misc/jq_stock_money_flow_recorder.py +++ b/src/zvt/recorders/joinquant/misc/jq_stock_money_flow_recorder.py @@ -10,8 +10,8 @@ from zvt.domain import StockMoneyFlow, Stock from zvt.recorders.joinquant.common import to_jq_entity_id from zvt.recorders.joinquant.misc.jq_index_money_flow_recorder import JoinquantIndexMoneyFlowRecorder -from zvt.utils import pd_is_not_null, to_time_str -from zvt.utils.time_utils import TIME_FORMAT_DAY +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import TIME_FORMAT_DAY, to_time_str class JoinquantStockMoneyFlowRecorder(FixedCycleDataRecorder): diff --git a/src/zvt/recorders/jqka/emotion/JqkaEmotionRecorder.py b/src/zvt/recorders/jqka/emotion/JqkaEmotionRecorder.py index 8b5fd105..a6b84a98 100644 --- a/src/zvt/recorders/jqka/emotion/JqkaEmotionRecorder.py +++ b/src/zvt/recorders/jqka/emotion/JqkaEmotionRecorder.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- +import re from typing import List import pandas as pd -import re + from zvt.api.utils import china_stock_code_to_id -from zvt.contract.api import df_to_db, get_db_session +from zvt.contract.api import df_to_db from zvt.contract.recorder import TimestampsDataRecorder from zvt.domain import Stock from zvt.domain.emotion.emotion import LimitUpInfo, LimitDownInfo, Emotion from zvt.recorders.jqka import jqka_api -from zvt.utils import to_time_str, date_time_by_interval, current_date, to_pd_timestamp, pd_is_not_null +from zvt.utils.time_utils import to_time_str, date_time_by_interval, current_date, to_pd_timestamp def _get_high_days_count(high_days_str: str): diff --git a/src/zvt/recorders/jqka/jqka_api.py b/src/zvt/recorders/jqka/jqka_api.py index 004f555a..c494adee 100644 --- a/src/zvt/recorders/jqka/jqka_api.py +++ b/src/zvt/recorders/jqka/jqka_api.py @@ -2,7 +2,8 @@ import requests -from zvt.utils import now_timestamp, to_time_str, TIME_FORMAT_DAY1, chrome_copy_header_to_dict +from zvt.utils.time_utils import now_timestamp, to_time_str, TIME_FORMAT_DAY1 +from zvt.utils.utils import chrome_copy_header_to_dict _JKQA_HEADER = chrome_copy_header_to_dict( """ diff --git a/src/zvt/recorders/qmt/quotes/qmt_kdata_recorder.py b/src/zvt/recorders/qmt/quotes/qmt_kdata_recorder.py index 12c2dc19..7c7493e8 100644 --- a/src/zvt/recorders/qmt/quotes/qmt_kdata_recorder.py +++ b/src/zvt/recorders/qmt/quotes/qmt_kdata_recorder.py @@ -10,7 +10,7 @@ Stock, StockKdataCommon, ) -from zvt.utils import pd_is_not_null, current_date, to_time_str +from zvt.utils.pd_utils import pd_is_not_null, current_date, to_time_str class BaseQmtKdataRecorder(FixedCycleDataRecorder): diff --git a/src/zvt/recorders/wb/wb_api.py b/src/zvt/recorders/wb/wb_api.py index de943442..701c3488 100644 --- a/src/zvt/recorders/wb/wb_api.py +++ b/src/zvt/recorders/wb/wb_api.py @@ -7,7 +7,8 @@ import requests from zvt.contract.api import get_entity_code -from zvt.utils import to_pd_timestamp, normal_index_df +from zvt.utils.pd_utils import normal_index_df +from zvt.utils.time_utils import to_pd_timestamp WORLD_BANK_URL = "http://api.worldbank.org/v2" diff --git a/src/zvt/recorders/wb/wb_economy_recorder.py b/src/zvt/recorders/wb/wb_economy_recorder.py index 2357149d..8047da94 100644 --- a/src/zvt/recorders/wb/wb_economy_recorder.py +++ b/src/zvt/recorders/wb/wb_economy_recorder.py @@ -4,7 +4,7 @@ from zvt.contract.recorder import FixedCycleDataRecorder from zvt.domain import Country, Economy from zvt.recorders.wb import wb_api -from zvt.utils import current_date +from zvt.utils.time_utils import current_date class WBEconomyRecorder(FixedCycleDataRecorder): diff --git a/src/zvt/tag/concept_main_tag_mapping.json b/src/zvt/resources/concept_main_tag_mapping.json similarity index 100% rename from src/zvt/tag/concept_main_tag_mapping.json rename to src/zvt/resources/concept_main_tag_mapping.json diff --git a/src/zvt/tag/industry_main_tag_mapping.json b/src/zvt/resources/industry_main_tag_mapping.json similarity index 100% rename from src/zvt/tag/industry_main_tag_mapping.json rename to src/zvt/resources/industry_main_tag_mapping.json diff --git a/src/zvt/tag/missed_concept.json b/src/zvt/resources/missed_concept.json similarity index 100% rename from src/zvt/tag/missed_concept.json rename to src/zvt/resources/missed_concept.json diff --git a/src/zvt/tag/missed_industry.json b/src/zvt/resources/missed_industry.json similarity index 100% rename from src/zvt/tag/missed_industry.json rename to src/zvt/resources/missed_industry.json diff --git a/src/zvt/rest/data.py b/src/zvt/rest/data.py index d4b55acf..9dd2c79c 100644 --- a/src/zvt/rest/data.py +++ b/src/zvt/rest/data.py @@ -2,8 +2,8 @@ from fastapi import APIRouter from fastapi.encoders import jsonable_encoder -import zvt.contract.api as contract_api import zvt.contract as contract +import zvt.contract.api as contract_api data_router = APIRouter( prefix="/api/data", diff --git a/src/zvt/rest/trading.py b/src/zvt/rest/trading.py index c54a5e2e..ed13d2b2 100644 --- a/src/zvt/rest/trading.py +++ b/src/zvt/rest/trading.py @@ -1,25 +1,23 @@ +import platform from typing import List, Optional from fastapi import APIRouter, HTTPException from fastapi_pagination import Page +import zvt.contract.api as contract_api import zvt.trading.trading_service as trading_service from zvt.common.trading_models import BuyPositionStrategy, SellPositionStrategy, TradingResult -import platform -import zvt.contract.api as contract_api - from zvt.trading.trading_models import ( BuildTradingPlanModel, TradingPlanModel, QueryTradingPlanModel, QueryStockQuoteModel, - StockQuoteModel, StockQuoteStatsModel, QueryStockQuoteSettingModel, BuildQueryStockQuoteSettingModel, ) from zvt.trading.trading_schemas import QueryStockQuoteSetting -from zvt.utils import current_date +from zvt.utils.time_utils import current_date trading_router = APIRouter( prefix="/api/trading", diff --git a/src/zvt/rest/work.py b/src/zvt/rest/work.py index 6ac3d263..04e44d04 100644 --- a/src/zvt/rest/work.py +++ b/src/zvt/rest/work.py @@ -24,7 +24,7 @@ ActivateSubTagsModel, ) from zvt.tag.tag_schemas import StockTags, MainTagInfo, SubTagInfo, HiddenTagInfo, StockPoolInfo, StockPools -from zvt.utils import current_date, to_time_str +from zvt.utils.time_utils import current_date, to_time_str work_router = APIRouter( prefix="/api/work", diff --git a/src/zvt/samples/stock_traders.py b/src/zvt/samples/stock_traders.py index ef476ada..def97675 100644 --- a/src/zvt/samples/stock_traders.py +++ b/src/zvt/samples/stock_traders.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from zvt.contract import IntervalLevel -from zvt.factors import BullFactor from zvt.factors.ma.ma_factor import CrossMaFactor +from zvt.factors.macd.macd_factor import BullFactor from zvt.trader.trader import StockTrader diff --git a/src/zvt/server.py b/src/zvt/server.py index 40140a37..e3683e25 100644 --- a/src/zvt/server.py +++ b/src/zvt/server.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import uvicorn from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import ORJSONResponse from fastapi_pagination import add_pagination @@ -8,9 +9,6 @@ from zvt.rest.factor import factor_router from zvt.rest.trading import trading_router from zvt.rest.work import work_router -from fastapi.middleware.cors import CORSMiddleware - -from zvt.sched.sched import zvt_scheduler app = FastAPI(default_response_class=ORJSONResponse) diff --git a/src/zvt/tag/__init__.py b/src/zvt/tag/__init__.py index 801e4212..938e1239 100644 --- a/src/zvt/tag/__init__.py +++ b/src/zvt/tag/__init__.py @@ -1,48 +1,2 @@ # the __all__ is generated __all__ = [] - -# __init__.py structure: -# common code of the package -# export interface in __all__ which contains __all__ of its sub modules - -# import all from submodule tag_utils -from .tag_utils import * -from .tag_utils import __all__ as _tag_utils_all - -__all__ += _tag_utils_all - -# import all from submodule tag_models -from .tag_models import * -from .tag_models import __all__ as _tag_models_all - -__all__ += _tag_models_all - -# import all from submodule tag_service -from .tag_service import * -from .tag_service import __all__ as _tag_service_all - -__all__ += _tag_service_all - -# import all from submodule tag_stats -from .tag_stats import * -from .tag_stats import __all__ as _tag_stats_all - -__all__ += _tag_stats_all - -# import all from submodule common -from .common import * -from .common import __all__ as _common_all - -__all__ += _common_all - -# import all from submodule tagger -from .tagger import * -from .tagger import __all__ as _tagger_all - -__all__ += _tagger_all - -# import all from submodule tag_schemas -from .tag_schemas import * -from .tag_schemas import __all__ as _tag_schemas_all - -__all__ += _tag_schemas_all diff --git a/src/zvt/tag/tag_models.py b/src/zvt/tag/tag_models.py index b1d696d7..3664a1f9 100644 --- a/src/zvt/tag/tag_models.py +++ b/src/zvt/tag/tag_models.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from datetime import datetime from typing import Dict, Union, List, Optional from pydantic import BaseModel, field_validator, Field @@ -215,12 +214,17 @@ class ActivateSubTagsResultModel(BaseModel): "CreateTagInfoModel", "StockTagsModel", "SimpleStockTagsModel", + "QueryStockTagsModel", + "QuerySimpleStockTagsModel", "SetStockTagsModel", "StockPoolModel", "StockPoolInfoModel", "CreateStockPoolInfoModel", "StockPoolsModel", "CreateStockPoolsModel", - "StockTagStatsModel", + "QueryStockTagStatsModel", "StockTagDetailsModel", + "StockTagStatsModel", + "ActivateSubTagsModel", + "ActivateSubTagsResultModel", ] diff --git a/src/zvt/tag/tag_schemas.py b/src/zvt/tag/tag_schemas.py index 5e001489..b8bcb313 100644 --- a/src/zvt/tag/tag_schemas.py +++ b/src/zvt/tag/tag_schemas.py @@ -109,5 +109,16 @@ class TagStats(StockTagsBase, Mixin): register_schema(providers=["zvt"], db_name="stock_tags", schema_base=StockTagsBase) + + # the __all__ is generated -__all__ = ["MainTagInfo", "SubTagInfo", "HiddenTagInfo", "StockTags", "StockPoolInfo", "StockPools", "TagStats"] +__all__ = [ + "MainTagInfo", + "SubTagInfo", + "HiddenTagInfo", + "StockTags", + "StockSystemTags", + "StockPoolInfo", + "StockPools", + "TagStats", +] diff --git a/src/zvt/tag/tag_service.py b/src/zvt/tag/tag_service.py index 717103b1..6b225303 100644 --- a/src/zvt/tag/tag_service.py +++ b/src/zvt/tag/tag_service.py @@ -23,14 +23,8 @@ get_concept_main_tag_mapping, ) from zvt.tag.tagger import StockTagger -from zvt.utils import ( - to_time_str, - to_pd_timestamp, - compare_dicts, - flatten_list, - current_date, -) -from zvt.utils.utils import fill_dict +from zvt.utils.time_utils import to_pd_timestamp, to_time_str, current_date +from zvt.utils.utils import fill_dict, compare_dicts, flatten_list logger = logging.getLogger(__name__) @@ -493,11 +487,17 @@ def activate_main_tag_by_sub_tags(activate_sub_tags_model: ActivateSubTagsModel) # build_initial_stock_pool_info() # StockAutoTagger().tag() + # the __all__ is generated __all__ = [ "stock_tags_need_update", "build_stock_tags", "StockAutoTagger", - "build_initial_stock_pool_info", + "build_stock_pool_info", "build_stock_pool", + "query_stock_tag_stats", + "refresh_main_tag_by_sub_tag", + "refresh_all_main_tag_by_sub_tag", + "activate_main_tag_by_industry", + "activate_main_tag_by_sub_tags", ] diff --git a/src/zvt/tag/tag_stats.py b/src/zvt/tag/tag_stats.py index 97b5b848..92f343b3 100644 --- a/src/zvt/tag/tag_stats.py +++ b/src/zvt/tag/tag_stats.py @@ -8,9 +8,11 @@ from zvt.contract.api import df_to_db, get_db_session from zvt.domain import Stock1dHfqKdata from zvt.factors.top_stocks import TopStocks, get_top_stocks -from zvt.tag import CreateStockPoolsModel, build_stock_pool +from zvt.tag.tag_models import CreateStockPoolsModel from zvt.tag.tag_schemas import TagStats, StockTags, StockPools -from zvt.utils import to_pd_timestamp, pd_is_not_null, date_time_by_interval +from zvt.tag.tag_service import build_stock_pool +from zvt.utils.pd_utils import pd_is_not_null +from zvt.utils.time_utils import to_pd_timestamp, date_time_by_interval logger = logging.getLogger(__name__) @@ -158,5 +160,7 @@ def build_stock_pool_tag_stats(stock_pool_name, force_rebuild_latest=False): # build_system_stock_pools() build_stock_pool_tag_stats(stock_pool_name="main_line", force_rebuild_latest=True) # build_stock_pool_tag_stats(stock_pool_name="vol_up") + + # the __all__ is generated __all__ = ["build_system_stock_pools", "build_stock_pool_tag_stats"] diff --git a/src/zvt/tag/tag_utils.py b/src/zvt/tag/tag_utils.py index b3d841ff..16026937 100644 --- a/src/zvt/tag/tag_utils.py +++ b/src/zvt/tag/tag_utils.py @@ -5,18 +5,15 @@ import pandas as pd +from zvt import zvt_env from zvt.contract.api import df_to_db from zvt.domain import Block from zvt.tag.common import StockPoolType from zvt.tag.tag_schemas import MainTagInfo, SubTagInfo, HiddenTagInfo, StockPoolInfo -from zvt.utils import ( - to_time_str, - flatten_list, -) def get_industry_main_tag_mapping() -> Dict[str, str]: - with open(os.path.join(os.path.dirname(__file__), "industry_main_tag_mapping.json"), encoding="utf-8") as f: + with open(os.path.join(zvt_env["resource_path"], "industry_main_tag_mapping.json"), encoding="utf-8") as f: return json.load(f) @@ -30,7 +27,7 @@ def get_main_tag_industry_mapping() -> Dict[str, List[str]]: def get_concept_main_tag_mapping() -> Dict[str, str]: - with open(os.path.join(os.path.dirname(__file__), "concept_main_tag_mapping.json"), encoding="utf-8") as f: + with open(os.path.join(zvt_env["resource_path"], "concept_main_tag_mapping.json"), encoding="utf-8") as f: return json.load(f) @@ -218,13 +215,20 @@ def get_stock_pool_names(): # result[tag] = main_tag # with open("industry_main_tag_mapping.json", "w") as json_file: # json.dump(result, json_file, indent=2, ensure_ascii=False) - print(list(get_concept_main_tag_mapping().keys())) + print(list(get_industry_list())) # the __all__ is generated __all__ = [ + "get_industry_main_tag_mapping", + "get_main_tag_industry_mapping", + "get_concept_main_tag_mapping", + "get_main_tag_concept_mapping", + "get_initial_sub_tags", "get_industry_list", "get_concept_list", + "check_missed_industry", + "check_missed_concept", "get_initial_main_tag_info", "get_initial_sub_tag_info", "get_initial_stock_pool_info", diff --git a/src/zvt/trader/sim_account.py b/src/zvt/trader/sim_account.py index 4173c5f4..762091e3 100644 --- a/src/zvt/trader/sim_account.py +++ b/src/zvt/trader/sim_account.py @@ -5,11 +5,9 @@ from marshmallow_sqlalchemy import SQLAlchemyAutoSchema -from zvt.api import get_kdata, get_kdata_schema -from zvt.trader.trader_info_api import get_trader_info, clear_trader +from zvt.api.kdata import get_kdata, get_kdata_schema from zvt.contract import IntervalLevel, TradableEntity, AdjustType from zvt.contract.api import get_db_session, decode_entity_id -from zvt.trader.trader_schemas import AccountStats, Position, Order, TraderInfo from zvt.trader import TradingSignal, AccountService, OrderType, trading_signal_type_to_order_type from zvt.trader.errors import ( NotEnoughMoneyError, @@ -18,6 +16,8 @@ InvalidOrderParamError, WrongKdataError, ) +from zvt.trader.trader_info_api import get_trader_info, clear_trader +from zvt.trader.trader_schemas import AccountStats, Position, Order, TraderInfo from zvt.utils.pd_utils import pd_is_not_null from zvt.utils.time_utils import to_pd_timestamp, to_time_str, TIME_FORMAT_ISO8601, is_same_date from zvt.utils.utils import fill_domain_from_dict diff --git a/src/zvt/trader/trader.py b/src/zvt/trader/trader.py index 77f28255..f75a3434 100644 --- a/src/zvt/trader/trader.py +++ b/src/zvt/trader/trader.py @@ -5,15 +5,15 @@ import pandas as pd -from zvt.domain import Stock -from zvt.trader.trader_info_api import AccountStatsReader from zvt.contract import IntervalLevel, TradableEntity, AdjustType from zvt.contract.drawer import Drawer from zvt.contract.factor import Factor, TargetType from zvt.contract.normal_data import NormalData -from zvt.trader.trader_schemas import AccountStats, Position +from zvt.domain import Stock from zvt.trader import TradingSignal, TradingSignalType, TradingListener from zvt.trader.sim_account import SimAccountService +from zvt.trader.trader_info_api import AccountStatsReader +from zvt.trader.trader_schemas import AccountStats, Position from zvt.utils.time_utils import to_pd_timestamp, now_pd_timestamp, to_time_str, is_same_date, date_time_by_interval diff --git a/src/zvt/trader/trader_info_api.py b/src/zvt/trader/trader_info_api.py index 383bf114..94b996bc 100644 --- a/src/zvt/trader/trader_info_api.py +++ b/src/zvt/trader/trader_info_api.py @@ -5,10 +5,10 @@ from zvt.contract import IntervalLevel from zvt.contract.api import get_data, get_db_session +from zvt.contract.drawer import Drawer from zvt.contract.normal_data import NormalData from zvt.contract.reader import DataReader from zvt.trader.trader_schemas import AccountStats, Order, TraderInfo, Position -from zvt.contract.drawer import Drawer def clear_trader(trader_name, session=None): diff --git a/src/zvt/trader/trader_schemas.py b/src/zvt/trader/trader_schemas.py index 2ceec4ed..db01b83f 100644 --- a/src/zvt/trader/trader_schemas.py +++ b/src/zvt/trader/trader_schemas.py @@ -5,7 +5,7 @@ from zvt.contract import Mixin from zvt.contract.register import register_schema -from zvt.utils import to_string +from zvt.utils.decorator import to_string TraderBase = declarative_base() diff --git a/src/zvt/trading/__init__.py b/src/zvt/trading/__init__.py index 40a96afc..2686fff0 100644 --- a/src/zvt/trading/__init__.py +++ b/src/zvt/trading/__init__.py @@ -1 +1,5 @@ # -*- coding: utf-8 -*- + + +# the __all__ is generated +__all__ = [] diff --git a/src/zvt/trading/common.py b/src/zvt/trading/common.py index f3d7c73e..c5e88439 100644 --- a/src/zvt/trading/common.py +++ b/src/zvt/trading/common.py @@ -6,3 +6,7 @@ class ExecutionStatus(Enum): init = "init" success = "success" failed = "failed" + + +# the __all__ is generated +__all__ = ["ExecutionStatus"] diff --git a/src/zvt/trading/trading_models.py b/src/zvt/trading/trading_models.py index 1147d4fc..41d20d66 100644 --- a/src/zvt/trading/trading_models.py +++ b/src/zvt/trading/trading_models.py @@ -1,18 +1,15 @@ # -*- coding: utf-8 -*- from datetime import datetime -from typing import Dict, Union, List, Optional +from typing import Union, List, Optional from pydantic import BaseModel, field_validator, Field -from pydantic_core.core_schema import ValidationInfo from zvt.common.query_models import TimeRange, OrderByType -from zvt.contract import IntervalLevel, AdjustType from zvt.contract.model import MixinModel, CustomModel -from zvt.tag.common import StockPoolType -from zvt.tag.tag_utils import get_main_tags, get_sub_tags, get_hidden_tags, get_stock_pool_names +from zvt.tag.tag_utils import get_stock_pool_names from zvt.trader import TradingSignalType from zvt.trading.common import ExecutionStatus -from zvt.utils import date_time_by_interval, current_date, tomorrow_date, to_pd_timestamp +from zvt.utils.time_utils import tomorrow_date, to_pd_timestamp class QueryStockQuoteSettingModel(CustomModel): @@ -81,11 +78,17 @@ class StockQuoteModel(MixinModel): class StockQuoteStatsModel(CustomModel): + #: 涨停数 limit_up_count: int + #: 跌停数 limit_down_count: int + #: 上涨数 up_count: int + #: 下跌数 down_count: int + #: 涨幅 change_pct: float + #: 成交额 turnover: float quotes: List[StockQuoteModel] @@ -134,3 +137,16 @@ def trading_date_must_be_future(cls, v: str) -> str: class QueryTradingPlanModel(BaseModel): time_range: TimeRange + + +# the __all__ is generated +__all__ = [ + "QueryStockQuoteSettingModel", + "BuildQueryStockQuoteSettingModel", + "QueryStockQuoteModel", + "StockQuoteModel", + "StockQuoteStatsModel", + "TradingPlanModel", + "BuildTradingPlanModel", + "QueryTradingPlanModel", +] diff --git a/src/zvt/trading/trading_schemas.py b/src/zvt/trading/trading_schemas.py index d2b8d269..d4f97b94 100644 --- a/src/zvt/trading/trading_schemas.py +++ b/src/zvt/trading/trading_schemas.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -from sqlalchemy import Column, String, DateTime, Boolean, Float, Integer, ForeignKey, func, JSON +from sqlalchemy import Column, Float, DateTime +from sqlalchemy import String, JSON from sqlalchemy.orm import declarative_base -from sqlalchemy.orm import relationship from zvt.contract import Mixin from zvt.contract.register import register_schema -from sqlalchemy import Column, Integer, Float, DateTime, ForeignKey -from sqlalchemy.orm import declarative_base, relationship TradingBase = declarative_base() @@ -38,3 +36,7 @@ class QueryStockQuoteSetting(TradingBase, Mixin): register_schema(providers=["zvt"], db_name="stock_trading", schema_base=TradingBase) + + +# the __all__ is generated +__all__ = ["TradingPlan", "QueryStockQuoteSetting"] diff --git a/src/zvt/trading/trading_service.py b/src/zvt/trading/trading_service.py index cff41bdf..03b84379 100644 --- a/src/zvt/trading/trading_service.py +++ b/src/zvt/trading/trading_service.py @@ -1,28 +1,22 @@ # -*- coding: utf-8 -*- -import json import logging -from typing import List, Union +from typing import List -import numpy as np import pandas as pd from fastapi_pagination.ext.sqlalchemy import paginate import zvt.contract.api as contract_api -from zvt.contract import IntervalLevel, AdjustType from zvt.domain import Stock, StockQuote -from zvt.tag import StockTags, StockPools -from zvt.trader import StockTrader +from zvt.tag.tag_schemas import StockTags, StockPools from zvt.trading.common import ExecutionStatus from zvt.trading.trading_models import ( BuildTradingPlanModel, QueryTradingPlanModel, QueryStockQuoteModel, - StockQuoteStatsModel, - StockQuoteModel, BuildQueryStockQuoteSettingModel, ) from zvt.trading.trading_schemas import TradingPlan, QueryStockQuoteSetting -from zvt.utils import to_time_str, to_pd_timestamp, now_pd_timestamp, date_time_by_interval, current_date +from zvt.utils.time_utils import to_time_str, to_pd_timestamp, now_pd_timestamp, date_time_by_interval, current_date logger = logging.getLogger(__name__) @@ -204,3 +198,17 @@ def build_query_stock_quote_setting(build_query_stock_quote_setting_model: Build session.commit() session.refresh(stock_pool_info) return stock_pool_info + + +# the __all__ is generated +__all__ = [ + "build_trading_plan", + "query_trading_plan", + "get_current_trading_plan", + "get_future_trading_plan", + "check_trading_plan", + "query_stock_quotes", + "buy_stocks", + "sell_stocks", + "build_query_stock_quote_setting", +] diff --git a/src/zvt/ui/apps/factor_app.py b/src/zvt/ui/apps/factor_app.py index b9446312..eb6a836c 100644 --- a/src/zvt/ui/apps/factor_app.py +++ b/src/zvt/ui/apps/factor_app.py @@ -1,22 +1,22 @@ # -*- coding: utf-8 -*- from typing import List -from dash import dcc import dash_daq as daq -from dash import html from dash import dash +from dash import dcc +from dash import html from dash.dependencies import Input, Output, State -from zvt.trader.trader_info_api import AccountStatsReader, OrderReader, get_order_securities -from zvt.trader.trader_info_api import get_trader_info from zvt.contract import Mixin from zvt.contract import zvt_context, IntervalLevel from zvt.contract.api import get_entities, get_schema_by_name, get_schema_columns from zvt.contract.drawer import StackedDrawer -from zvt.domain import TraderInfo +from zvt.trader.trader_info_api import AccountStatsReader, OrderReader, get_order_securities +from zvt.trader.trader_info_api import get_trader_info +from zvt.trader.trader_schemas import TraderInfo from zvt.ui import zvt_app from zvt.ui.components.dcc_components import get_account_stats_figure -from zvt.utils import pd_is_not_null +from zvt.utils.pd_utils import pd_is_not_null account_readers = [] order_readers = [] diff --git a/src/zvt/ui/assets/base.css b/src/zvt/ui/assets/base.css index 4c1fa9ff..a4fd4963 100644 --- a/src/zvt/ui/assets/base.css +++ b/src/zvt/ui/assets/base.css @@ -35,86 +35,177 @@ /* Grid –––––––––––––––––––––––––––––––––––––––––––––––––– */ .container { - position: relative; - width: 100%; - max-width: 960px; - margin: 0 auto; - padding: 0 20px; - box-sizing: border-box; } + position: relative; + width: 100%; + max-width: 960px; + margin: 0 auto; + padding: 0 20px; + box-sizing: border-box; +} + .column, .columns { - width: 100%; - float: left; - box-sizing: border-box; } + width: 100%; + float: left; + box-sizing: border-box; +} /* For devices larger than 400px */ @media (min-width: 400px) { - .container { - width: 85%; - padding: 0; } + .container { + width: 85%; + padding: 0; + } } /* For devices larger than 550px */ @media (min-width: 550px) { - .container { - width: 80%; } - .column, - .columns { - margin-left: 4%; } - .column:first-child, - .columns:first-child { - margin-left: 0; } - - .one.column, - .one.columns { width: 4.66666666667%; } - .two.columns { width: 13.3333333333%; } - .three.columns { width: 22%; } - .four.columns { width: 30.6666666667%; } - .five.columns { width: 39.3333333333%; } - .six.columns { width: 48%; } - .seven.columns { width: 56.6666666667%; } - .eight.columns { width: 65.3333333333%; } - .nine.columns { width: 74.0%; } - .ten.columns { width: 82.6666666667%; } - .eleven.columns { width: 91.3333333333%; } - .twelve.columns { width: 100%; margin-left: 0; } - - .one-third.column { width: 30.6666666667%; } - .two-thirds.column { width: 65.3333333333%; } - - .one-half.column { width: 48%; } - - /* Offsets */ - .offset-by-one.column, - .offset-by-one.columns { margin-left: 8.66666666667%; } - .offset-by-two.column, - .offset-by-two.columns { margin-left: 17.3333333333%; } - .offset-by-three.column, - .offset-by-three.columns { margin-left: 26%; } - .offset-by-four.column, - .offset-by-four.columns { margin-left: 34.6666666667%; } - .offset-by-five.column, - .offset-by-five.columns { margin-left: 43.3333333333%; } - .offset-by-six.column, - .offset-by-six.columns { margin-left: 52%; } - .offset-by-seven.column, - .offset-by-seven.columns { margin-left: 60.6666666667%; } - .offset-by-eight.column, - .offset-by-eight.columns { margin-left: 69.3333333333%; } - .offset-by-nine.column, - .offset-by-nine.columns { margin-left: 78.0%; } - .offset-by-ten.column, - .offset-by-ten.columns { margin-left: 86.6666666667%; } - .offset-by-eleven.column, - .offset-by-eleven.columns { margin-left: 95.3333333333%; } - - .offset-by-one-third.column, - .offset-by-one-third.columns { margin-left: 34.6666666667%; } - .offset-by-two-thirds.column, - .offset-by-two-thirds.columns { margin-left: 69.3333333333%; } - - .offset-by-one-half.column, - .offset-by-one-half.columns { margin-left: 52%; } + .container { + width: 80%; + } + + .column, + .columns { + margin-left: 4%; + } + + .column:first-child, + .columns:first-child { + margin-left: 0; + } + + .one.column, + .one.columns { + width: 4.66666666667%; + } + + .two.columns { + width: 13.3333333333%; + } + + .three.columns { + width: 22%; + } + + .four.columns { + width: 30.6666666667%; + } + + .five.columns { + width: 39.3333333333%; + } + + .six.columns { + width: 48%; + } + + .seven.columns { + width: 56.6666666667%; + } + + .eight.columns { + width: 65.3333333333%; + } + + .nine.columns { + width: 74.0%; + } + + .ten.columns { + width: 82.6666666667%; + } + + .eleven.columns { + width: 91.3333333333%; + } + + .twelve.columns { + width: 100%; + margin-left: 0; + } + + .one-third.column { + width: 30.6666666667%; + } + + .two-thirds.column { + width: 65.3333333333%; + } + + .one-half.column { + width: 48%; + } + + /* Offsets */ + .offset-by-one.column, + .offset-by-one.columns { + margin-left: 8.66666666667%; + } + + .offset-by-two.column, + .offset-by-two.columns { + margin-left: 17.3333333333%; + } + + .offset-by-three.column, + .offset-by-three.columns { + margin-left: 26%; + } + + .offset-by-four.column, + .offset-by-four.columns { + margin-left: 34.6666666667%; + } + + .offset-by-five.column, + .offset-by-five.columns { + margin-left: 43.3333333333%; + } + + .offset-by-six.column, + .offset-by-six.columns { + margin-left: 52%; + } + + .offset-by-seven.column, + .offset-by-seven.columns { + margin-left: 60.6666666667%; + } + + .offset-by-eight.column, + .offset-by-eight.columns { + margin-left: 69.3333333333%; + } + + .offset-by-nine.column, + .offset-by-nine.columns { + margin-left: 78.0%; + } + + .offset-by-ten.column, + .offset-by-ten.columns { + margin-left: 86.6666666667%; + } + + .offset-by-eleven.column, + .offset-by-eleven.columns { + margin-left: 95.3333333333%; + } + + .offset-by-one-third.column, + .offset-by-one-third.columns { + margin-left: 34.6666666667%; + } + + .offset-by-two-thirds.column, + .offset-by-two-thirds.columns { + margin-left: 69.3333333333%; + } + + .offset-by-one-half.column, + .offset-by-one-half.columns { + margin-left: 52%; + } } @@ -125,51 +216,100 @@ html is set to 62.5% so that all the REM measurements throughout Skeleton are based on 10px sizing. So basically 1.5rem = 15px :) */ html { - font-size: 62.5%; } + font-size: 62.5%; +} + body { - font-size: 1.5em; /* currently ems cause chrome bug misinterpreting rems on body element */ - line-height: 1.6; - font-weight: 400; - font-family: "Open Sans", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif; - color: rgb(50, 50, 50); } + font-size: 1.5em; /* currently ems cause chrome bug misinterpreting rems on body element */ + line-height: 1.6; + font-weight: 400; + font-family: "Open Sans", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif; + color: rgb(50, 50, 50); +} /* Typography –––––––––––––––––––––––––––––––––––––––––––––––––– */ h1, h2, h3, h4, h5, h6 { - margin-top: 0; - margin-bottom: 0; - font-weight: 300; } -h1 { font-size: 4.5rem; line-height: 1.2; letter-spacing: -.1rem; margin-bottom: 2rem; } -h2 { font-size: 3.6rem; line-height: 1.25; letter-spacing: -.1rem; margin-bottom: 1.8rem; margin-top: 1.8rem;} -h3 { font-size: 3.0rem; line-height: 1.3; letter-spacing: -.1rem; margin-bottom: 1.5rem; margin-top: 1.5rem;} -h4 { font-size: 2.6rem; line-height: 1.35; letter-spacing: -.08rem; margin-bottom: 1.2rem; margin-top: 1.2rem;} -h5 { font-size: 2.2rem; line-height: 1.5; letter-spacing: -.05rem; margin-bottom: 0.6rem; margin-top: 0.6rem;} -h6 { font-size: 2.0rem; line-height: 1.6; letter-spacing: 0; margin-bottom: 0.75rem; margin-top: 0.75rem;} + margin-top: 0; + margin-bottom: 0; + font-weight: 300; +} + +h1 { + font-size: 4.5rem; + line-height: 1.2; + letter-spacing: -.1rem; + margin-bottom: 2rem; +} + +h2 { + font-size: 3.6rem; + line-height: 1.25; + letter-spacing: -.1rem; + margin-bottom: 1.8rem; + margin-top: 1.8rem; +} + +h3 { + font-size: 3.0rem; + line-height: 1.3; + letter-spacing: -.1rem; + margin-bottom: 1.5rem; + margin-top: 1.5rem; +} + +h4 { + font-size: 2.6rem; + line-height: 1.35; + letter-spacing: -.08rem; + margin-bottom: 1.2rem; + margin-top: 1.2rem; +} + +h5 { + font-size: 2.2rem; + line-height: 1.5; + letter-spacing: -.05rem; + margin-bottom: 0.6rem; + margin-top: 0.6rem; +} + +h6 { + font-size: 2.0rem; + line-height: 1.6; + letter-spacing: 0; + margin-bottom: 0.75rem; + margin-top: 0.75rem; +} p { - margin-top: 0; } + margin-top: 0; +} /* Blockquotes –––––––––––––––––––––––––––––––––––––––––––––––––– */ blockquote { - border-left: 4px lightgrey solid; - padding-left: 1rem; - margin-top: 2rem; - margin-bottom: 2rem; - margin-left: 0rem; + border-left: 4px lightgrey solid; + padding-left: 1rem; + margin-top: 2rem; + margin-bottom: 2rem; + margin-left: 0rem; } /* Links –––––––––––––––––––––––––––––––––––––––––––––––––– */ a { - color: #1EAEDB; - text-decoration: underline; - cursor: pointer;} + color: #1EAEDB; + text-decoration: underline; + cursor: pointer; +} + a:hover { - color: #0FA0CE; } + color: #0FA0CE; +} /* Buttons @@ -179,23 +319,25 @@ button, input[type="submit"], input[type="reset"], input[type="button"] { - display: inline-block; - height: 38px; - padding: 0 30px; - color: #555; - text-align: center; - font-size: 11px; - font-weight: 600; - line-height: 38px; - letter-spacing: .1rem; - text-transform: uppercase; - text-decoration: none; - white-space: nowrap; - background-color: transparent; - border-radius: 4px; - border: 1px solid #bbb; - cursor: pointer; - box-sizing: border-box; } + display: inline-block; + height: 38px; + padding: 0 30px; + color: #555; + text-align: center; + font-size: 11px; + font-weight: 600; + line-height: 38px; + letter-spacing: .1rem; + text-transform: uppercase; + text-decoration: none; + white-space: nowrap; + background-color: transparent; + border-radius: 4px; + border: 1px solid #bbb; + cursor: pointer; + box-sizing: border-box; +} + .button:hover, button:hover, input[type="submit"]:hover, @@ -206,17 +348,21 @@ button:focus, input[type="submit"]:focus, input[type="reset"]:focus, input[type="button"]:focus { - color: #333; - border-color: #888; - outline: 0; } + color: #333; + border-color: #888; + outline: 0; +} + .button.button-primary, button.button-primary, input[type="submit"].button-primary, input[type="reset"].button-primary, input[type="button"].button-primary { - color: #FFF; - background-color: #33C3F0; - border-color: #33C3F0; } + color: #FFF; + background-color: #33C3F0; + border-color: #33C3F0; +} + .button.button-primary:hover, button.button-primary:hover, input[type="submit"].button-primary:hover, @@ -227,9 +373,10 @@ button.button-primary:focus, input[type="submit"].button-primary:focus, input[type="reset"].button-primary:focus, input[type="button"].button-primary:focus { - color: #FFF; - background-color: #1EAEDB; - border-color: #1EAEDB; } + color: #FFF; + background-color: #1EAEDB; + border-color: #1EAEDB; +} /* Forms @@ -243,15 +390,17 @@ input[type="url"], input[type="password"], textarea, select { - height: 38px; - padding: 6px 10px; /* The 6px vertically centers text on FF, ignored by Webkit */ - background-color: #fff; - border: 1px solid #D1D1D1; - border-radius: 4px; - box-shadow: none; - box-sizing: border-box; - font-family: inherit; - font-size: inherit; /*https://stackoverflow.com/questions/6080413/why-doesnt-input-inherit-the-font-from-body*/} + height: 38px; + padding: 6px 10px; /* The 6px vertically centers text on FF, ignored by Webkit */ + background-color: #fff; + border: 1px solid #D1D1D1; + border-radius: 4px; + box-shadow: none; + box-sizing: border-box; + font-family: inherit; + font-size: inherit; /*https://stackoverflow.com/questions/6080413/why-doesnt-input-inherit-the-font-from-body*/ +} + /* Removes awkward default styles on some inputs for iOS */ input[type="email"], input[type="number"], @@ -261,13 +410,17 @@ input[type="tel"], input[type="url"], input[type="password"], textarea { - -webkit-appearance: none; - -moz-appearance: none; - appearance: none; } + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; +} + textarea { - min-height: 65px; - padding-top: 6px; - padding-bottom: 6px; } + min-height: 65px; + padding-top: 6px; + padding-bottom: 6px; +} + input[type="email"]:focus, input[type="number"]:focus, input[type="search"]:focus, @@ -277,103 +430,142 @@ input[type="url"]:focus, input[type="password"]:focus, textarea:focus, select:focus { - border: 1px solid #33C3F0; - outline: 0; } + border: 1px solid #33C3F0; + outline: 0; +} + label, legend { - display: block; - margin-bottom: 0px; } + display: block; + margin-bottom: 0px; +} + fieldset { - padding: 0; - border-width: 0; } + padding: 0; + border-width: 0; +} + input[type="checkbox"], input[type="radio"] { - display: inline; } + display: inline; +} + label > .label-body { - display: inline-block; - margin-left: .5rem; - font-weight: normal; } + display: inline-block; + margin-left: .5rem; + font-weight: normal; +} /* Lists –––––––––––––––––––––––––––––––––––––––––––––––––– */ ul { - list-style: circle inside; } + list-style: circle inside; +} + ol { - list-style: decimal inside; } + list-style: decimal inside; +} + ol, ul { - padding-left: 0; - margin-top: 0; } + padding-left: 0; + margin-top: 0; +} + ul ul, ul ol, ol ol, ol ul { - margin: 1.5rem 0 1.5rem 3rem; - font-size: 90%; } + margin: 1.5rem 0 1.5rem 3rem; + font-size: 90%; +} + li { - margin-bottom: 1rem; } + margin-bottom: 1rem; +} /* Tables –––––––––––––––––––––––––––––––––––––––––––––––––– */ table { - border-collapse: collapse; + border-collapse: collapse; } + th, td { - padding: 12px 15px; - text-align: left; - border-bottom: 1px solid #E1E1E1; } + padding: 12px 15px; + text-align: left; + border-bottom: 1px solid #E1E1E1; +} + th:first-child, td:first-child { - padding-left: 0; } + padding-left: 0; +} + th:last-child, td:last-child { - padding-right: 0; } + padding-right: 0; +} /* Spacing –––––––––––––––––––––––––––––––––––––––––––––––––– */ button, .button { - margin-bottom: 0rem; } + margin-bottom: 0rem; +} + input, textarea, select, fieldset { - margin-bottom: 0rem; } + margin-bottom: 0rem; +} + pre, dl, figure, table, form { - margin-bottom: 0rem; } + margin-bottom: 0rem; +} + p, ul, ol { - margin-bottom: 0.75rem; } + margin-bottom: 0.75rem; +} /* Utilities –––––––––––––––––––––––––––––––––––––––––––––––––– */ .u-full-width { - width: 100%; - box-sizing: border-box; } + width: 100%; + box-sizing: border-box; +} + .u-max-full-width { - max-width: 100%; - box-sizing: border-box; } + max-width: 100%; + box-sizing: border-box; +} + .u-pull-right { - float: right; } + float: right; +} + .u-pull-left { - float: left; } + float: left; +} /* Misc –––––––––––––––––––––––––––––––––––––––––––––––––– */ hr { - margin-top: 3rem; - margin-bottom: 3.5rem; - border-width: 0; - border-top: 1px solid #E1E1E1; } + margin-top: 3rem; + margin-bottom: 3.5rem; + border-width: 0; + border-top: 1px solid #E1E1E1; +} /* Clearing @@ -383,9 +575,10 @@ hr { .container:after, .row:after, .u-cf { - content: ""; - display: table; - clear: both; } + content: ""; + display: table; + clear: both; +} /* Media Queries @@ -399,16 +592,21 @@ there. /* Larger than mobile */ -@media (min-width: 400px) {} +@media (min-width: 400px) { +} /* Larger than phablet (also point when grid becomes active) */ -@media (min-width: 550px) {} +@media (min-width: 550px) { +} /* Larger than tablet */ -@media (min-width: 750px) {} +@media (min-width: 750px) { +} /* Larger than desktop */ -@media (min-width: 1000px) {} +@media (min-width: 1000px) { +} /* Larger than Desktop HD */ -@media (min-width: 1200px) {} \ No newline at end of file +@media (min-width: 1200px) { +} \ No newline at end of file diff --git a/src/zvt/ui/components/dcc_components.py b/src/zvt/ui/components/dcc_components.py index ee4995c3..a877c533 100644 --- a/src/zvt/ui/components/dcc_components.py +++ b/src/zvt/ui/components/dcc_components.py @@ -3,11 +3,11 @@ from dash import dcc from zvt.api.kdata import get_kdata_schema -from zvt.trader.trader_info_api import OrderReader, AccountStatsReader +from zvt.contract import zvt_context from zvt.contract.api import decode_entity_id from zvt.contract.drawer import Drawer from zvt.contract.reader import DataReader -from zvt.contract import zvt_context +from zvt.trader.trader_info_api import OrderReader, AccountStatsReader from zvt.utils.pd_utils import pd_is_not_null diff --git a/src/zvt/utils/__init__.py b/src/zvt/utils/__init__.py index 7e3d1fe1..938e1239 100644 --- a/src/zvt/utils/__init__.py +++ b/src/zvt/utils/__init__.py @@ -1,61 +1,2 @@ -# -*- coding: utf-8 -*- # the __all__ is generated __all__ = [] - -# __init__.py structure: -# common code of the package -# export interface in __all__ which contains __all__ of its sub modules - -# import all from submodule model_utils -from .model_utils import * -from .model_utils import __all__ as _model_utils_all - -__all__ += _model_utils_all - -# import all from submodule str_utils -from .str_utils import * -from .str_utils import __all__ as _str_utils_all - -__all__ += _str_utils_all - -# import all from submodule decorator -from .decorator import * -from .decorator import __all__ as _decorator_all - -__all__ += _decorator_all - -# import all from submodule time_utils -from .time_utils import * -from .time_utils import __all__ as _time_utils_all - -__all__ += _time_utils_all - -# import all from submodule utils -from .utils import * -from .utils import __all__ as _utils_all - -__all__ += _utils_all - -# import all from submodule file_utils -from .file_utils import * -from .file_utils import __all__ as _file_utils_all - -__all__ += _file_utils_all - -# import all from submodule zip_utils -from .zip_utils import * -from .zip_utils import __all__ as _zip_utils_all - -__all__ += _zip_utils_all - -# import all from submodule git_utils -from .git_utils import * -from .git_utils import __all__ as _git_utils_all - -__all__ += _git_utils_all - -# import all from submodule pd_utils -from .pd_utils import * -from .pd_utils import __all__ as _pd_utils_all - -__all__ += _pd_utils_all diff --git a/src/zvt/utils/file_utils.py b/src/zvt/utils/file_utils.py index db163311..a8299659 100644 --- a/src/zvt/utils/file_utils.py +++ b/src/zvt/utils/file_utils.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import os -from typing import List +from typing import List, Optional def list_all_files( - dir_path: str = "./domain", ext: str = ".py", excludes=None, includes=None, return_base_name=False + dir_path: str = "./domain", ext: Optional[str] = ".py", excludes=None, includes=None, return_base_name=False ) -> List[str]: """ list all files with extension in specific directory recursively diff --git a/src/zvt/utils/utils.py b/src/zvt/utils/utils.py index 12f48025..4c3bce82 100644 --- a/src/zvt/utils/utils.py +++ b/src/zvt/utils/utils.py @@ -293,6 +293,7 @@ def fill_dict(src, dst): # the __all__ is generated __all__ = [ + "getcontext().prec", "none_values", "zero_values", "first_item_to_float", diff --git a/src/zvt/zhdate/__init__.py b/src/zvt/zhdate/__init__.py index 88f55c4e..d1a487dd 100644 --- a/src/zvt/zhdate/__init__.py +++ b/src/zvt/zhdate/__init__.py @@ -1,25 +1,3 @@ # -*- coding: utf-8 -*- # the __all__ is generated __all__ = [] - -# __init__.py structure: -# common code of the package -# export interface in __all__ which contains __all__ of its sub modules - -# import all from submodule constants -from .constants import * -from .constants import __all__ as _constants_all - -__all__ += _constants_all - -# import all from submodule ztime -from .ztime import * -from .ztime import __all__ as _ztime_all - -__all__ += _ztime_all - -# import all from submodule zhdate -from .zhdate import * -from .zhdate import __all__ as _zhdate_all - -__all__ += _zhdate_all diff --git a/src/zvt/zhdate/ztime.py b/src/zvt/zhdate/ztime.py index 365e754e..81fda83a 100644 --- a/src/zvt/zhdate/ztime.py +++ b/src/zvt/zhdate/ztime.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from zvt.utils import to_pd_timestamp, current_date, count_interval +from zvt.utils.time_utils import to_pd_timestamp, current_date, count_interval from zvt.zhdate.zhdate import ZhDate diff --git a/tests/api/test_common.py b/tests/api/test_common.py index 0f02426d..ac1b53b0 100644 --- a/tests/api/test_common.py +++ b/tests/api/test_common.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- +from zvt.api.utils import get_recent_report_date from zvt.contract import IntervalLevel -from zvt.api import get_kdata -from zvt.api import to_high_level_kdata, get_recent_report_date +from zvt.api.kdata import get_kdata, to_high_level_kdata from ..context import init_test_context init_test_context() diff --git a/tests/api/test_intent.py b/tests/api/test_intent.py index 97233e5e..999befcb 100644 --- a/tests/api/test_intent.py +++ b/tests/api/test_intent.py @@ -2,7 +2,7 @@ from zvt.api.intent import compare, distribute, composite, composite_all from zvt.contract.drawer import ChartType from zvt.domain import FinanceFactor, CashFlowStatement, BalanceSheet, Stock1dKdata -from zvt.utils import to_pd_timestamp +from zvt.utils.time_utils import to_pd_timestamp def test_compare_kdata(): diff --git a/tests/api/test_joinquant_quotes.py b/tests/api/test_joinquant_quotes.py index cc06c70b..bc18ef36 100644 --- a/tests/api/test_joinquant_quotes.py +++ b/tests/api/test_joinquant_quotes.py @@ -1,4 +1,4 @@ -from zvt.api import get_kdata +from zvt.api.kdata import get_kdata from zvt.contract import IntervalLevel from zvt.contract.api import get_db_session from ..context import init_test_context diff --git a/tests/api/test_kdata.py b/tests/api/test_kdata.py index b0ea3a7a..bde95cc7 100644 --- a/tests/api/test_kdata.py +++ b/tests/api/test_kdata.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from zvt.api import get_kdata +from zvt.api.kdata import get_kdata from zvt.api.kdata import get_latest_kdata_date from zvt.contract import IntervalLevel, AdjustType diff --git a/tests/factors/test_factor_select_targets.py b/tests/factors/test_factor_select_targets.py index c047f38e..a06095df 100644 --- a/tests/factors/test_factor_select_targets.py +++ b/tests/factors/test_factor_select_targets.py @@ -3,7 +3,7 @@ from zvt.factors.ma.ma_factor import CrossMaFactor from zvt.contract.factor import TargetType -from zvt.factors import BullFactor +from zvt.factors.macd.macd_factor import BullFactor from ..context import init_test_context init_test_context() diff --git a/tests/factors/test_factors.py b/tests/factors/test_factors.py index e02b06e6..4fd9de46 100644 --- a/tests/factors/test_factors.py +++ b/tests/factors/test_factors.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from zvt.factors import ZFactor +from zvt.factors.z.z_factor import ZFactor def test_z_factor(): diff --git a/tests/factors/test_transformers.py b/tests/factors/test_transformers.py index 1e0cffc0..39ce2bc0 100644 --- a/tests/factors/test_transformers.py +++ b/tests/factors/test_transformers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from zvt.api import get_kdata +from zvt.api.kdata import get_kdata from zvt.factors.algorithm import MaTransformer, MacdTransformer diff --git a/tests/trader/test_trader.py b/tests/trader/test_trader.py index 457324cd..21a79c76 100644 --- a/tests/trader/test_trader.py +++ b/tests/trader/test_trader.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -from zvt.api import get_kdata +from zvt.api.kdata import get_kdata from zvt.contract import IntervalLevel, AdjustType from zvt.samples import MyBullTrader, StockTrader -from zvt.utils import is_same_date +from zvt.utils.time_utils import is_same_date buy_timestamp = "2019-05-29" sell_timestamp = "2020-01-06" diff --git a/tests/utils/test_pd_utils.py b/tests/utils/test_pd_utils.py index 906acf39..865b2e35 100644 --- a/tests/utils/test_pd_utils.py +++ b/tests/utils/test_pd_utils.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import pandas as pd -from zvt.utils import drop_continue_duplicate +from zvt.utils.pd_utils import drop_continue_duplicate def test_drop_continue_duplicate():