feat: add hlz watch command — price alerts with shell command triggers#2
Closed
feat: add hlz watch command — price alerts with shell command triggers#2
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Owner
Author
|
Closing for rework - will open fresh PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Changes
src/cli/args.zigWatchArgsstruct withcoin,above,below,cmd,repeatfieldswatchvariant toCommandunion andHelpTopicenumparseWatch()function requiring at least one of--above/--belowsrc/cli/commands.zigwatch()function that subscribes toallMidsWS channelextractMidPrice()extractMidPricehelpersrc/cli/main.zigwatchcommand in main switchOutput Format
⚡ BTC hit 100,234.50 (was watching: --above 100000){"coin":"BTC","price":"100234.50","condition":"above","threshold":"100000","timestamp":1710000000000}Validation
zig build test— all tests pass (including new extractMidPrice tests)zig build hlz— builds successfullyzig build hlz-terminal— builds successfullyhlz help watch— shows correct help textCloses SYM-9