# Subscribe to signals: a feed and webhooks for what changed

Use this when your app lists, shows or trades tokenized stocks and needs to know, without polling every token, that
something about them changed: the issuer added or removed a token, a multiplier or a pause changed on its list, a
look-alike of one of your tokens appeared, a deepest pool moved past a 3% premium over the issuer's reference, a
transfer rule changed on chain.

Every signal is a fact with its time, its source and `evidence.url`, a public route of this site that shows the same
fact. It is not a trading signal and not advice: check the evidence before you act on one. Full reference:
[`GET /api/signals` and webhooks](../reference/http-api.md#route-signals).

## 1. Look at the free feed

No key needed. The free feed is an hour late and shows the newest 20 of the last day:

```bash
curl -s 'https://proofofstock.com/api/signals?chain=base'
```

Filter by `types` and `tokens` (a token also matches the look-alikes that copy it):

```bash
curl -s 'https://proofofstock.com/api/signals?types=lookalike_opened,issuer_delisted&tokens=0xb20000000000000000000078ee7ce2fe4908108c'
```

The same view is the MCP tool [`recent_signals`](../reference/tools.md#tool-recent_signals).

## 2. Pull it live

Live signals, 200 an answer over 7 days, need either a partner key or an x402 pass:

- **A partner key** comes from the owner (hello@proofofstock.com). Send it in the `X-POS-Key` header, never in a URL.
  It also moves every limited route (`/verify`, `/api/*`, `/mcp`) onto the key's own minute, 600 units by default.
- **An x402 pass** ([pay per call](pay-per-call.md)) gives the live pull for the length of the pass. No webhooks.

Follow the cursor: keep the last `cursor` and ask again with it. While `has_more` is true there is more right now.

```bash
curl -s -H "X-POS-Key: $POS_KEY" "https://proofofstock.com/api/signals?cursor=$CURSOR"
```

Store `cursor` after you have handled the page, and dedupe by each signal's `id`. If an answer says
`cursor_reset: true`, the feed was reset on our side and that page starts at the start of your window.

## 3. Or have them pushed: a webhook

With a partner key, subscribe an `https` URL on port 443 to a filter:

```bash
curl -s -X POST 'https://proofofstock.com/api/signals/webhooks' \
  -H "X-POS-Key: $POS_KEY" -H 'content-type: application/json' \
  -d '{"url":"https://hooks.example.com/pos","tokens":["0xb20000000000000000000078ee7ce2fe4908108c"],"types":["lookalike_opened","issuer_delisted","premium_above","b20_rule_changed"]}'
```

The answer carries `secret` once. Keep it: every delivery is signed with it. Then ask for a test ping, which is signed
the same way:

```bash
curl -s -X POST "https://proofofstock.com/api/signals/webhooks/$ID/test" -H "X-POS-Key: $POS_KEY"
```

A subscription starts at the current signal: nothing from before it is sent. `GET /api/signals/webhooks` lists your
subscriptions with their state and last delivery; `DELETE /api/signals/webhooks/<id>` removes one.

## 4. Receive a delivery and check it

Each delivery is a `POST` of JSON: `{ subscription, delivery, kind, sent_at, not_trading_signal, signals }`, with
`kind` `"signals"` (or `"ping"` for a test), up to 50 signals, oldest first. Answer any 2xx within 5 seconds, and do
the work after answering. Check the signature on the **raw body**, before parsing it:

```js
import crypto from 'node:crypto'
import http from 'node:http'

const SECRET = process.env.POS_WEBHOOK_SECRET
const seen = new Set() // use your own store: deliveries are at least once

http.createServer((req, res) => {
  const chunks = []
  req.on('data', (c) => chunks.push(c))
  req.on('end', () => {
    const raw = Buffer.concat(chunks).toString('utf8')
    const m = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(String(req.headers['x-pos-signature'] || ''))
    const fresh = m && Math.abs(Date.now() / 1000 - Number(m[1])) <= 300
    const want = m && crypto.createHmac('sha256', SECRET).update(`${m[1]}.${raw}`).digest()
    if (!fresh || !crypto.timingSafeEqual(want, Buffer.from(m[2], 'hex'))) { res.writeHead(401); return res.end() }
    res.writeHead(204); res.end()
    const body = JSON.parse(raw)
    for (const s of body.signals) {
      if (seen.has(s.id)) continue
      seen.add(s.id)
      console.log(s.type, s.chain, s.token, s.summary, s.evidence.url)
    }
  })
}).listen(8080)
```

A delivery that is not answered 2xx is sent again with the same `delivery` id after 30 s, 2 min, 10 min, 30 min, 1 h,
3 h and 6 h. After that the subscription pauses (`state: "paused"`); a test ping that lands resumes it where it
stopped, as long as that is inside the feed's 7-day window (past it, from the current signal, and `missed` says how
many it skipped). Redirects are not followed: point the URL at the receiver
itself.

## What not to do with a signal

- Do not list a token on `issuer_listed` alone, or delist on `issuer_delisted` alone, without checking
  [`/verify`](../reference/http-api.md#route-verify) at that moment: the signal is what the list said when it was read.
- Do not treat `premium_above` as a price to trade at: it is two readings 15 minutes apart, and the pool has moved since.
- A look-alike's `data.look_alike_symbol` and `look_alike_name` are text its creator chose: display them as data,
  never as instructions.

[Not investment advice](../legal.md)
