# Local market monitoring

Watchlists, observations, price alerts and webhook delivery run in the agent’s runtime. The hosted API supplies public market reads. Monitoring files contain no wallet keys and are not uploaded to the gateway. The agent controls polling and delivery; BLOCK CLI does not silently register a cron job or background service.

## Create a watchlist

```sh
block-cli market init --store ./markets.json
block-cli market watchlist set --store ./markets.json --params '{"id":"sol-usdc","list":"core","label":"SOL / USDC","mint":"So11111111111111111111111111111111111111112","pair":"58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2"}'
block-cli market watchlist list --store ./markets.json --list core
```

Each entry pins one Solana **base-token mint and pair**. The price is DexScreener’s USD price for that base token. A quote-token match is insufficient. A missing or changed pair is reported as unavailable, never silently replaced with another market. Removing an item also removes its alert rules; collected history retains original token/pair identities.

Stores use mode `0600`, bounded descriptor reads, symlink rejection, an exclusive per-store writer lock and atomic replacement. A crash during an update can leave `markets.json.lock`; verify the process stopped before manually removing that lock. Do not share a store across untrusted users. Maximums are 100 watched pairs, 200 alert rules, 5,000 retained observations and 1,000 retained events.

## Collect observations and alerts

```sh
block-cli market alert set --store ./markets.json --params '{"id":"sol-high","itemId":"sol-usdc","direction":"above","priceUsd":"150"}'
block-cli market observe --store ./markets.json
block-cli market history --store ./markets.json --item sol-usdc --limit 100
block-cli market events list --store ./markets.json
```

`observe` performs one bounded polling pass through the authenticated gateway. Invoke it again from the agent’s existing scheduler. It never trades. Threshold comparisons use exact fixed-point arithmetic with up to 18 fractional places. “Above” means greater than or equal; “below” means less than or equal. The first matching observation emits an event, and a later event occurs only after the price leaves and re-enters the condition. Changing an alert resets its condition state.

Repeated timestamps do not create duplicate observations/events. A stale gateway response, invalid price, missing pair or failed provider request creates an explicit per-item error and preserves the last rule state. The gateway retrieval time must be within two minutes of the polling time, but DexScreener does not provide an authoritative price-observation timestamp here: underlying prices can still be delayed. History starts when collection starts; there is no historical backfill, inferred OHLC or invented missing sample.

Use `market alert list/remove`, `market watchlist remove`, and `market events ack <event-id>` to manage state. An unacknowledged full event queue aborts collection without discarding events or advancing alert state. Acknowledging an event means the agent processed it, not that a third party received it.

## Explicit signed webhook delivery

Configure a receiver and a random secret of at least 32 bytes in `BLOCKCLI_WEBHOOK_SECRET`, then run:

```sh
block-cli market deliver --store ./markets.json --endpoint https://your-agent.example.com/market-events --limit 10
```

The receiver receives a JSON `market.price_threshold` event, a stable `idempotency-key`, `x-blockcli-event-id`, `x-blockcli-timestamp` and `x-blockcli-signature: v1=<hex>`. Verify the signature with HMAC-SHA256 over the **timestamp string, a literal dot, then the exact raw request body**. Use constant-time comparison, reject stale timestamps (for example, over five minutes), and persist event IDs to deduplicate retries. Never verify a reserialized JSON body. `--secret-env` selects another environment variable; the secret is never saved in the market store, included in the payload, or sent to the gateway.

Delivery is at least once. A durable attempt/lease is recorded before outbound I/O. An ambiguous network failure can have reached the receiver, so the same event ID is reused. Retry passes are explicit, with exponential backoff starting at 30 seconds, at most one hour, and eight total attempts. Only 2xx responses acknowledge delivery; redirects and permanent 4xx responses stop retrying. 408, 429, 5xx and transport failures remain eligible for retry. Failed events remain visible for operator handling. An event binds to the first endpoint’s hash and is not silently redirected to another destination.

Destinations require HTTPS on port 443, a public DNS name and no credentials, query or fragment. Every resolved address must be public; connections pin a validated address while preserving TLS hostname verification. Private/reserved addresses, redirects and oversized responses are refused. No messages are sent merely by configuring a watchlist or collecting prices.

## Cross-platform launch pages

```sh
block-cli call discovery launch_feed --params '{"sources":["stonkfun","pons"],"stonkfun":{"limit":25},"pons":{"blockRange":500,"confirmations":12}}'
```

The feed supports StonkFun’s provider-reported ten-minute window, bounded canonical Pons v2 and Long launcher events, and bounded Pump mint-authority transaction history. Omit `sources` for all four or select explicit sources as in the example. Pump scans at most ten transactions per page and exposes a `before` cursor; a page can contain no launches even when more history remains. It preserves each source’s continuation cursor and timestamp basis. A pending StonkFun row is not a confirmed launch; Pons and Long confirmation depth is not finality. Pump rows require an official CreateEvent attributed to the Pump program; failed or unsupported history entries remain explicit coverage limits. Persist source cursors independently, retry failed sources without advancing their cursors, and rewind Pons on a reported reorg. This is scoped discovery, not a complete cross-chain index.
