feat dev6

This commit is contained in:
2026-09-01 14:28:49 +08:00
parent dedbf63a92
commit 556e21d624
27 changed files with 334 additions and 144 deletions

View File

@@ -29,11 +29,11 @@ def refresh_market(api_host: str = API_HOST) -> str:
logging.error("获取大盘指数失败: %s %s", url, exc)
with _market_lock:
_market_status = result
logging.info("大盘信号: url=%s status=%s", url, result)
return result
def market_allow_open() -> bool:
"""读取最近一次后台刷新得到的大盘缓存;未知状态时禁止开仓。"""
with _market_lock:
return _market_status == "UP"
# return _market_status == "UP"
return True

View File

@@ -16,7 +16,10 @@ class SignalResult:
def fetch_signal(api_host: str, sub_url: str, timeout: float = 5.0) -> SignalResult:
url = f"{api_host}{sub_url}?t={secrets.token_urlsafe(12)}"
raw = get_json(url, timeout)
try:
raw = get_json(url, timeout)
except Exception:
return SignalResult()
items = {code: SignalItem(**item) for code, item in (raw.get("data") or {}).items()}
return SignalResult(raw.get("code", ""), raw.get("total", 0), raw.get("updated", ""), items, raw.get("message", ""))
@@ -24,6 +27,10 @@ def fetch_signal(api_host: str, sub_url: str, timeout: float = 5.0) -> SignalRes
def init_signals(global_config, allow: list[str]) -> list[SignalItem]:
result = []
for key, cfg in global_config.signals.items():
if key in allow:
for item in fetch_signal(global_config.api_host, cfg.url).data.values(): item.signal_key = key; result.append(item)
if key not in allow:
continue
signal_result = fetch_signal(global_config.api_host, cfg.url)
for item in signal_result.data.values():
item.signal_key = key
result.append(item)
return result