feat(cli): trex-core slots 에 --symbol/--slot-id 필터 + 필터 시 상세 출력
운영자 CLI 의 slots 조회 편의: --symbol, --slot-id 클라이언트 측 필터(--status 와 조합 가능) 추가. 두 필터 중 하나라도 주면 한 줄 요약 대신 슬롯 상세 블록 (status/symbol/portfolio_id/qty/avg_price/limit/allocated_capital/strategy_id/ sell_strategy_id/forced_close_at/universe_detached, holding 이면 watchdog)으로 출력. 필터 없으면 기존 terse 테이블 유지(무회귀). 구조/계약/런타임 흐름 영향 없는 표시 기능. tests/runtime/test_cli_operator.py 필터 4건 추가(24 passed), ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -140,19 +140,62 @@ def _cmd_slots(args, cfg, rpc) -> int:
|
||||
if s.get("status") == "inactive" and not s.get("universe_detached")]
|
||||
elif status == "pending":
|
||||
slots = [s for s in slots if s.get("status") in ("pending_buy", "pending_sell")]
|
||||
# --symbol / --slot-id: client-side filters (composable with --status).
|
||||
if args.symbol:
|
||||
slots = [s for s in slots if s.get("symbol") == args.symbol]
|
||||
if args.slot_id:
|
||||
slots = [s for s in slots if s.get("slot_id") == args.slot_id]
|
||||
# dcy-017: holding-slot watchdog state (strategy-absent ownership).
|
||||
owned = {w.get("portfolio_id") for w in resp.get("watchdog", []) if w.get("expired")}
|
||||
wd_by_slot = {w.get("slot_id"): w for w in resp.get("watchdog", [])}
|
||||
if args.json:
|
||||
_emit({"instance": instance, "status": status, "slots": slots}, as_json=True)
|
||||
else:
|
||||
print(f"instance={instance} status={status} count={len(slots)} "
|
||||
header = f"instance={instance} status={status}"
|
||||
if args.symbol:
|
||||
header += f" symbol={args.symbol}"
|
||||
if args.slot_id:
|
||||
header += f" slot_id={args.slot_id}"
|
||||
print(f"{header} count={len(slots)} "
|
||||
f"watchdog_owned={len([s for s in slots if s.get('portfolio_id') in owned])}")
|
||||
for s in slots:
|
||||
pid = s.get("portfolio_id")
|
||||
tag = " [WATCHDOG-OWNED: strategy absent]" if pid in owned else ""
|
||||
print(f" {s.get('slot_id')}\t{s.get('status')}\t{s.get('symbol')}\t"
|
||||
f"qty={s.get('qty')}\tlimit={s.get('entry_price')}\t"
|
||||
f"avg={s.get('avg_price')}\tpid={s.get('portfolio_id')}{tag}")
|
||||
# When filtered (--symbol / --slot-id), print a detailed per-slot block;
|
||||
# otherwise the terse one-line table.
|
||||
if args.symbol or args.slot_id:
|
||||
for s in slots:
|
||||
_print_slot_detail(s, wd_by_slot.get(s.get("slot_id")))
|
||||
else:
|
||||
for s in slots:
|
||||
pid = s.get("portfolio_id")
|
||||
tag = " [WATCHDOG-OWNED: strategy absent]" if pid in owned else ""
|
||||
print(f" {s.get('slot_id')}\t{s.get('status')}\t{s.get('symbol')}\t"
|
||||
f"qty={s.get('qty')}\tlimit={s.get('entry_price')}\t"
|
||||
f"avg={s.get('avg_price')}\tpid={s.get('portfolio_id')}{tag}")
|
||||
return 0
|
||||
|
||||
|
||||
def _print_slot_detail(s: dict, wd: dict | None) -> None:
|
||||
"""Verbose per-slot block used when `slots` is filtered (e.g. --symbol)."""
|
||||
fields = [
|
||||
("status", s.get("status")),
|
||||
("symbol", s.get("symbol")),
|
||||
("portfolio_id", s.get("portfolio_id")),
|
||||
("qty", s.get("qty")),
|
||||
("avg_price", s.get("avg_price")),
|
||||
("entry_price (limit)", s.get("entry_price")),
|
||||
("allocated_capital", s.get("allocated_capital")),
|
||||
("strategy_id", s.get("strategy_id")),
|
||||
("sell_strategy_id", s.get("sell_strategy_id")),
|
||||
("forced_close_at", s.get("forced_close_at")),
|
||||
("universe_detached", s.get("universe_detached")),
|
||||
]
|
||||
if wd is not None:
|
||||
fields.append((
|
||||
"watchdog",
|
||||
f"expired={wd.get('expired')} last_seen={wd.get('last_seen')}",
|
||||
))
|
||||
print(f"slot {s.get('slot_id')}")
|
||||
for label, value in fields:
|
||||
print(f" {label:<20}: {value}")
|
||||
return 0
|
||||
|
||||
|
||||
@@ -290,6 +333,10 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
p_slots = sub.add_parser("slots", help="List positions (snapshot RPC)")
|
||||
p_slots.add_argument("--status", choices=["all", "held", "holding", "buyable", "pending"],
|
||||
default="all")
|
||||
p_slots.add_argument("--symbol", default=None,
|
||||
help="show only the slot(s) bound to this symbol")
|
||||
p_slots.add_argument("--slot-id", dest="slot_id", default=None,
|
||||
help="show only the slot with this slot_id")
|
||||
_add_common(p_slots)
|
||||
|
||||
p_enter = sub.add_parser("enter", help="Submit a buy intent (intent RPC)")
|
||||
|
||||
Reference in New Issue
Block a user