feat: configurable ticker window for market stats (1h, 4h, 1d)

- Replace hardcoded ticker_24h with ticker_stats supporting configurable window
- Add -w/--window flag to `market tickers` (choices: 1h, 4h, 1d, default 1d)
- Update TUI title and JSON output to include window field
- Keep opportunity/pf service on 1d default
- Sync tests and doc comments

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-20 11:11:11 +08:00
parent cf26a3dd3a
commit 4312b16288
7 changed files with 37 additions and 24 deletions

View File

@@ -48,10 +48,10 @@ class KlineView:
quote_volume: float
def get_tickers(config: dict[str, Any], symbols: list[str], *, spot_client: Any) -> dict[str, Any]:
def get_tickers(config: dict[str, Any], symbols: list[str], *, spot_client: Any, window: str = "1d") -> dict[str, Any]:
normalized = normalize_symbols(symbols)
rows = []
for ticker in spot_client.ticker_24h(normalized):
for ticker in spot_client.ticker_stats(normalized, window=window):
rows.append(
asdict(
TickerView(
@@ -64,7 +64,7 @@ def get_tickers(config: dict[str, Any], symbols: list[str], *, spot_client: Any)
)
)
)
return {"tickers": rows}
return {"tickers": rows, "window": window}
def get_klines(
@@ -103,6 +103,7 @@ def get_scan_universe(
*,
spot_client: Any,
symbols: list[str] | None = None,
window: str = "1d",
) -> list[dict[str, Any]]:
market_config = config.get("market", {})
opportunity_config = config.get("opportunity", {})
@@ -116,7 +117,7 @@ def get_scan_universe(
status_map = {normalize_symbol(item["symbol"]): item.get("status", "") for item in exchange_info.get("symbols", [])}
rows: list[dict[str, Any]] = []
for ticker in spot_client.ticker_24h(list(requested) if requested else None):
for ticker in spot_client.ticker_stats(list(requested) if requested else None, window=window):
symbol = normalize_symbol(ticker["symbol"])
if not symbol.endswith(quote):
continue

View File

@@ -104,7 +104,7 @@ def analyze_portfolio(config: dict[str, Any], *, spot_client: Any) -> dict[str,
klines = spot_client.klines(symbol=symbol, interval="1h", limit=24)
closes = [float(item[4]) for item in klines]
volumes = [float(item[5]) for item in klines]
tickers = spot_client.ticker_24h([symbol])
tickers = spot_client.ticker_stats([symbol], window="1d")
ticker = tickers[0] if tickers else {"priceChangePercent": "0"}
concentration = position["notional_usdt"] / total_notional
score, metrics = _score_candidate(