Price Alerts (Keon)
How Keon Wallet registers price alerts and verifies the signed push when one fires
Keon Wallet can alert the user when a token crosses a price. The alert lives in the wallet. The wallet registers a copy here so the backend can watch prices and send a push when it fires. The push only says "this alert fired". The wallet checks the signature, matches it to its own local alert, gets a fresh quote and opens a normal swap review. Nothing is ever signed or sent on the user's behalf.
Mainnet only. On the Sepolia API, POST returns 400 "price alerts are mainnet-only" and /pairs/ reports available: false. The two price sources aren't reliable on testnet: Pragma's Sepolia feed is stale and Dexscreener has no testnet prices.
Authentication and limits
Send your api-key header. Going over a limit returns 429 with a Retry-After header.
| Limit | Applies to |
|---|---|
| 60 per hour per client IP | Every price-alert request. Checked first. |
| 30 per hour per device token | Creates, updates and token refreshes. |
| 50 live alerts per device | Creating a 51st returns 409. |
The backend stores the device's FCM token, the pair, the threshold and the times. It stores no account address.
GET /api/keon/price-alerts/pairs/
The tokens alerts can use. Any two different tokens from the list make a pair. Fetch this rather than hard-coding it.
1{2 "available": true,3 "network": "mainnet",4 "tokens": [5 {"symbol": "STRK", "address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"},6 {"symbol": "ETH", "address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"},7 {"symbol": "WBTC", "address": "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"},8 {"symbol": "USDC", "address": "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb"},9 {"symbol": "LORDS", "address": "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"}10 ],11 "web_push_public_key": "BKx…base64url…"12}A token is listed only if both sources can price it: Pragma has its USD pair, and Dexscreener prices it as a pool's base token. WBTC uses Pragma's BTC/USD.
POST /api/keon/price-alerts/
Register an alert. Posting the same alert_id again from the same device updates it and re-arms it.
1{2 "alert_id": "0d9f4f0e-0a3b-4f63-9a59-2f7e3c1c8b52",3 "device_token": "<FCM registration token>",4 "platform": "android",5 "chain_id": "SN_MAIN",6 "base_token": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",7 "quote_token": "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",8 "direction": "above",9 "threshold_e8": 5000000,10 "repeat": false,11 "expires_at": "2026-11-08T12:00:00Z"12}| Field | Required | Rules |
|---|---|---|
alert_id | yes | A UUID the wallet generates. It's also the alert's id in the push. |
device_token | yes | Android: the device's FCM registration token. Extension: a random secret (20+ characters) the extension generates once and keeps; it's what DELETE and fired/ check. |
platform | yes | android or extension. |
web_push | no | Extension only: the browser's PushSubscription as toJSON() gives it ({endpoint, keys: {p256dh, auth}}, https endpoint). Leave it out where the browser has no Web Push (Firefox, Safari); that extension polls fired/ instead. |
chain_id | yes | SN_MAIN. |
base_token, quote_token | yes | Two different tokens from /pairs/, in any hex form. |
direction | yes | above or below. |
threshold_e8 | yes | The price of base_token in quote_token, times 10^8, as a positive integer (or a string of digits). For example, 0.05 USDC per STRK is 5000000. |
repeat | no | true re-arms after firing (see below). Defaults to false. |
expires_at | yes | An ISO 8601 time with a timezone, in the future, at most 90 days away. |
Any other field returns 400.
| Status | When |
|---|---|
201 | Created: {"server_id": "<id>"}. |
200 | Updated and re-armed: {"server_id": "<id>"}. |
400 | Invalid body, an unsupported pair, or a non-mainnet API. |
409 | The alert_id belongs to another device, or the device already has 50 live alerts. |
429 | Rate limit. |
DELETE /api/keon/price-alerts/{alert_id}/
Send the alert's device_token in the X-Device-Token header. The response is 204 when the alert was deleted. It's 404 when the alert doesn't exist or the token doesn't match, so the endpoint never reveals whether an alert id exists.
POST /api/keon/price-alerts/device-token/
FCM rotated the device's token. This moves every alert from the old token to the new one.
1{"old_token": "<previous FCM token>", "new_token": "<new FCM token>"}Returns {"updated": <number of alerts moved>}. A token FCM reports as unregistered is cleaned up automatically, and so are its alerts. A browser subscription that's gone is dropped; that extension keeps its alerts and polls fired/.
GET /api/keon/price-alerts/fired/
Every fire is stored for 7 days, exactly as pushed, so a device that missed a push (offline, app force-stopped, browser closed) catches up when it next opens. Extensions without Web Push poll this.
Send X-Device-Token (404 if missing or malformed) and the last cursor you got (start with 0).
1curl 'https://api.tokenkithq.io/api/keon/price-alerts/fired/?cursor=0' \2 -H 'api-key: YOUR_API_KEY' -H 'X-Device-Token: <device_token>'1{"fires": [ { "v": "1", "kind": "price_alert", "...": "...", "sig": "..." } ], "cursor": 1842, "more": false}Only this device's fires after cursor come back, oldest first, at most 100 (more: true means fetch again with the new cursor). Each item is a signed payload: verify it exactly like a push (below).
When an alert fires
The backend checks prices every 15 seconds on two independent sources: Pragma's on-chain median (counted only if it's under 30 minutes old) and Dexscreener. An alert fires when all of these hold continuously for 60 seconds:
- Both sources price the pair on the alert's side of
threshold_e8. - The two sources agree within 2%. If they diverge, the 60 seconds start over.
A missing or stale price also restarts the 60 seconds.
After firing, a one-off alert is done. A repeat alert re-arms only after the price has gone back to the other side of the threshold on both sources, and it never fires twice within 15 minutes. Expired alerts stop being watched and are deleted 30 days later, along with fired ones.
The push
The same signed body goes out two ways, both with a 1 hour TTL (held while the device is offline):
- Android: a data-only FCM message (high priority, no
notificationblock). Keon's native receiver verifies it and writes the notification text itself, so the server never chooses what appears on the lock screen. - Extension: a silent Web Push (VAPID) to the browser's subscription; the service worker verifies it and shows the notification.
GET /pairs/returns the VAPID public key asweb_push_public_key(theapplicationServerKey), ornulluntil Web Push is set up.
Every value is a string:
1{2 "v": "1",3 "kind": "price_alert",4 "kid": "2026-11",5 "alert_id": "0d9f4f0e-0a3b-4f63-9a59-2f7e3c1c8b52",6 "fired_at": "1793620800",7 "pair": "STRK/USDC",8 "price_e8": "5012000",9 "sig": "<base64url Ed25519 signature>"10}pairis base and quote symbols, never addresses.price_e8is the less extreme of the two sources' prices: the lower forabove, the higher forbelow. So it's past the threshold by both sources' account.kindistestfor pushes sent with thesend_test_price_pushcommand. The wallet should verify atestpush and never act on it.
Verifying a push
- Pick the pinned public key named by
kid. The app pins two keys (current and next) so the signing key can be rotated without an app release. An unknownkidmeans drop the push. - Remove
sig. Serialise the remaining fields as canonical JSON: keys sorted, no whitespace, ASCII only. In Python that'sjson.dumps(data, sort_keys=True, separators=(",", ":"), ensure_ascii=True); in JS, sort the keys and thenJSON.stringify. - Verify
sig(base64url without padding) as an Ed25519 signature over those bytes. - Check that
alert_idis a live local alert, thatfired_atis within the last hour (the push TTL; an older fire fromfired/is shown as "fired while you were away", never acted on as if current), and thatprice_e8is on the right side of the local threshold. Then open the swap with a fresh quote. Never use amounts or tokens from the push itself.