fix(market-data): 完善 Tushare 全量同步配置

This commit is contained in:
yuxuanhui
2026-08-06 22:45:18 +08:00
parent afdc5ca909
commit 039a81fe57
6 changed files with 119 additions and 7 deletions
@@ -24,7 +24,8 @@ def normalize_decimal(value: object | None) -> Decimal | None:
Tushare may return a float, a decimal, a string, or ``None`` depending on
the transport. Decimal constructed from the textual representation keeps
those variants from changing snapshot fingerprints.
those variants from changing snapshot fingerprints. NaN representations
are treated as missing, while other non-finite values remain invalid.
"""
if value is None or str(value).strip() == "":
@@ -33,6 +34,8 @@ def normalize_decimal(value: object | None) -> Decimal | None:
result = Decimal(str(value).strip())
except (InvalidOperation, ValueError) as exc:
raise ValueError(f"invalid numeric value: {value!r}") from exc
if result.is_nan():
return None
if not result.is_finite():
raise ValueError(f"numeric value must be finite: {value!r}")
return Decimal(0) if result == 0 else result.normalize()
@@ -57,13 +57,18 @@ class TushareAdapter:
raise ValueError("ZHIXING_TUSHARE_TOKEN is required for market sync")
import tushare as ts # pyright: ignore[reportMissingTypeStubs]
pro_bar_function = cast(
client = cast(object, ts.pro_api(token))
pro_bar = cast(
Callable[..., object],
ts.pro_bar, # pyright: ignore[reportUnknownMemberType]
)
def pro_bar_with_client(**kwargs: object) -> object:
return pro_bar(api=client, **kwargs)
return cls(
cast(object, ts.pro_api(token)),
pro_bar=pro_bar_function,
client,
pro_bar=pro_bar_with_client,
max_retries=max_retries,
backoff_seconds=backoff_seconds,
request_interval_seconds=request_interval_seconds,