fix: deduplicate blocked intents in daily Discord report
Show unique (strategy, symbol) combinations with tick-count instead of listing every blocked intent individually. Submitted and error entries remain per-item. Eliminates the 96+ duplicate lines in the daily summary.
This commit is contained in:
@@ -52,19 +52,44 @@ def build_daily_summary(
|
|||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
submitted = [i for i in intents_today if i.get("submitted")]
|
submitted = [i for i in intents_today if i.get("submitted")]
|
||||||
dry = [i for i in intents_today if not i.get("submitted")]
|
blocked = [i for i in intents_today if i.get("status") == "blocked"]
|
||||||
|
errors = [i for i in intents_today if i.get("status") == "error"]
|
||||||
|
dry = [i for i in intents_today if i.get("status") == "dry_run"]
|
||||||
|
|
||||||
lines.append(
|
lines.append(
|
||||||
f"**Today's orders:** {len(submitted)} submitted · {len(dry)} dry/blocked"
|
f"**Today's activity:** {len(submitted)} submitted · "
|
||||||
|
f"{len(blocked)} blocked · {len(errors)} errors · {len(dry)} dry-run"
|
||||||
)
|
)
|
||||||
for i in intents_today[:20]:
|
|
||||||
tag = "✓" if i.get("submitted") else "·"
|
# Submitted orders — show each individually
|
||||||
details = i.get("details_json")
|
if submitted:
|
||||||
|
lines.append(" Submitted:")
|
||||||
|
for i in submitted[:15]:
|
||||||
lines.append(
|
lines.append(
|
||||||
f" {tag} [{i['strategy']}] {i['side']} {i['symbol']} qty={i['qty']} "
|
f" ✓ [{i['strategy']}] {i['side']} {i['symbol']} "
|
||||||
f"type={i['order_type']} status={i.get('status')}"
|
f"qty={i['qty']} · {i.get('alpaca_order_id', '')[:8]}"
|
||||||
)
|
)
|
||||||
if len(intents_today) > 20:
|
if len(submitted) > 15:
|
||||||
lines.append(f" …{len(intents_today)-20} more")
|
lines.append(f" …{len(submitted)-15} more")
|
||||||
|
|
||||||
|
# Errors — always show (actionable)
|
||||||
|
if errors:
|
||||||
|
lines.append(" Errors:")
|
||||||
|
for i in errors[:10]:
|
||||||
|
lines.append(f" ✗ {i['symbol']} {i['side']} — check logs")
|
||||||
|
|
||||||
|
# Blocked — deduplicate by (strategy, symbol), show unique with count
|
||||||
|
if blocked:
|
||||||
|
seen: dict[str, int] = {}
|
||||||
|
for i in blocked:
|
||||||
|
key = f"{i['strategy']}:{i['symbol']}"
|
||||||
|
seen[key] = seen.get(key, 0) + 1
|
||||||
|
lines.append(f" Blocked (unique: {len(seen)}, total ticks: {len(blocked)}):")
|
||||||
|
for key, count in list(seen.items())[:10]:
|
||||||
|
strategy, symbol = key.split(":", 1)
|
||||||
|
lines.append(f" · [{strategy}] {symbol} ×{count}")
|
||||||
|
if len(seen) > 10:
|
||||||
|
lines.append(f" …{len(seen)-10} more")
|
||||||
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user