Skip to content

feat: add hlz watch command — price alerts with shell command triggers#2

Closed
dzmbs wants to merge 2 commits intomainfrom
sym-9/add-watch-command
Closed

feat: add hlz watch command — price alerts with shell command triggers#2
dzmbs wants to merge 2 commits intomainfrom
sym-9/add-watch-command

Conversation

@dzmbs
Copy link
Copy Markdown
Owner

@dzmbs dzmbs commented Mar 14, 2026

Summary

Add hlz watch — a WebSocket-based price watcher that monitors a coin's mid price and optionally executes a shell command when a price condition is met.

Usage

# Alert only (prints + exits)
hlz watch BTC --above 100000
hlz watch ETH --below 3000

# Execute command on trigger
hlz watch BTC --above 100000 --cmd 'hlz sell BTC 0.1'
hlz watch ETH --below 3000 --cmd 'hlz cancel ETH --all'

# Cross-asset: watch one, act on another
hlz watch ETH --above 4000 --cmd 'hlz buy BTC 0.5'

# Keep watching after trigger
hlz watch BTC --above 100000 --cmd 'echo triggered' --repeat

# JSON output for piping
hlz watch BTC --above 0 --json | jq .price

Changes

src/cli/args.zig

  • Add WatchArgs struct with coin, above, below, cmd, repeat fields
  • Add watch variant to Command union and HelpTopic enum
  • Add parseWatch() function requiring at least one of --above/--below

src/cli/commands.zig

  • Add watch() function that subscribes to allMids WS channel
  • Extract target coin mid price from each update via extractMidPrice()
  • On trigger: print TTY alert or JSON event, spawn shell cmd if provided
  • SIGINT handling reuses existing stream command pattern
  • Unit tests for extractMidPrice helper

src/cli/main.zig

  • Wire watch command in main switch
  • Add to STREAMING & ALERTS help section
  • Add command-specific help text

Output Format

  • TTY: ⚡ BTC hit 100,234.50 (was watching: --above 100000)
  • Piped/JSON: {"coin":"BTC","price":"100234.50","condition":"above","threshold":"100000","timestamp":1710000000000}
  • Exit code: 0 on trigger, 1 on error, 2 on usage, 4 on network failure

Validation

  • zig build test — all tests pass (including new extractMidPrice tests)
  • zig build hlz — builds successfully
  • zig build hlz-terminal — builds successfully
  • hlz help watch — shows correct help text
  • Error handling: missing args, missing conditions both return proper exit codes

Closes SYM-9

Adds hlz watch - a WebSocket-based price watcher that monitors a coin
mid price and triggers alerts with optional shell command execution.

- Subscribe to allMids WS channel for real-time price monitoring
- --above/--below threshold conditions
- --cmd spawns shell commands via /bin/sh -c on trigger
- --repeat keeps watching after first trigger (default: exit)
- Pipe-aware JSON output when piped or with --json
- SIGINT handling for graceful shutdown
- Unit tests for extractMidPrice helper

Closes SYM-9
@dzmbs dzmbs added the symphony label Mar 14, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hlz Ready Ready Preview, Comment Mar 14, 2026 10:12pm

Address two review findings for hlz watch:

1. (high) Add reconnect loop on WebSocket disconnect/error. The watch
   function now wraps the read loop in an outer reconnect loop with
   exponential backoff (2s sleep, max 10 retries). On connection loss,
   it reconnects and resubscribes automatically. Extracted inner read
   loop to watchReadLoop() returning bool for exit vs reconnect.

2. (medium) Reject --above and --below used together. parseWatch() now
   returns null (MissingArgument) when both flags are provided, since
   silently ignoring one condition while arming --cmd is unsafe.
@dzmbs
Copy link
Copy Markdown
Owner Author

dzmbs commented Mar 14, 2026

Closing for rework - will open fresh PR

@dzmbs dzmbs closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant