Files
Chan/web/services/runtime/__init__.py
jackyu66gitandCursor df27b4dde8 refactor: ECR-002 拆分 runtime 包并加深 analyze 契约(已审)
将 web/services/runtime.py 拆为 runtime/ 子模块并保持门面兼容;补齐 ESS 文档、门面/契约/TF_DF 测试与 CODE_REVIEW Approve。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 18:15:23 +08:00

96 lines
2.5 KiB
Python

"""runtime 门面:保持 `from services.runtime import *` 与 `import services.runtime as R` 兼容。"""
from __future__ import annotations
# ---- 历史兼容:旧 monolith 上 `from pytz import timezone` 等会随 import * 漏出 ----
import json # noqa: F401
import logging
import sys as _sys
import time # noqa: F401
from collections import OrderedDict # noqa: F401
from concurrent.futures import ThreadPoolExecutor, as_completed # noqa: F401
import numpy as np # noqa: F401
from pytz import timezone # noqa: F401
from chanlun.analysis.ChanZone import ( # noqa: F401
StructureZoneConfig,
analyze_structure_zones_from_serialized,
)
logger = logging.getLogger("services.runtime")
from .state import ( # noqa: F401
TRADE_POINT_TYPE,
macd_fast_period,
macd_slow_period,
macd_signal_period,
exchange,
china_stock,
_zone_cache,
DEFAULT_TIMEFRAME_LABELS,
DEFAULT_SYMBOLS,
TIMEFRAMES,
SYMBOLS,
DATA_SERVICE_AVAILABLE,
SERVICE_METADATA_LAST_REFRESH,
)
from .timeframes import ( # noqa: F401
_zone_cache_ttl,
timeframe_to_minutes,
format_timeframe_label,
build_timeframe_labels,
compute_timeframe_defaults,
is_smaller_timeframe,
is_smaller_or_equal_timeframe,
)
from .market_data import ( # noqa: F401
_parse_time_input,
refresh_data_service_metadata,
_fetch_kl_from_datasvc,
A_STOCK_SYMBOLS,
detect_symbol_type,
get_kl_data,
_get_crypto_kl_data_via_ccxt,
get_crypto_kl_data,
get_a_stock_kl_data,
load_crypto_symbols,
)
from .indicators import ( # noqa: F401
add_indicators,
calculate_macd,
)
from .analyze import ( # noqa: F401
analyze_chan,
classify_trend_stage,
)
from .serialize import ( # noqa: F401
convert_direction,
format_time_safely,
serialize_chan_macd_data,
clean_dataframe_for_json,
get_uncompleted_seg_list,
)
# 预取元信息(与拆分前模块加载行为一致)
refresh_data_service_metadata(force=True)
# 标量在 import 时会拷贝;刷新后写回本模块,供 `from services.runtime import *` 读到最新值
from . import state as _state
_mod = _sys.modules[__name__]
_mod.DATA_SERVICE_AVAILABLE = _state.DATA_SERVICE_AVAILABLE
_mod.SERVICE_METADATA_LAST_REFRESH = _state.SERVICE_METADATA_LAST_REFRESH
_mod.macd_fast_period = _state.macd_fast_period
_mod.macd_slow_period = _state.macd_slow_period
_mod.macd_signal_period = _state.macd_signal_period
def __getattr__(name: str):
if hasattr(_state, name):
return getattr(_state, name)
raise AttributeError(name)
def __dir__():
return sorted(set(globals()) | set(dir(_state)))