mirror of
https://github.com/Such-Software/hash-wallet-prices.git
synced 2026-10-17 05:51:28 +02:00
f4bf98f6fc116d1678c507283da8aac46b1c3406
Single endpoint serving USD spot prices for Hash Wallet, sourcing from Kraken (majors) and NonKYC (Wownero), KV-cached and refreshed via cron every minute. Drop-in /v2/rates shape compatible with the existing wallet client; preferred /v1/prices returns everything in one call.
hash-wallet-prices
Cloudflare Worker that aggregates USD prices for Hash Wallet and serves them at one cached endpoint.
Why this exists: see the architectural notes in the wallet repo. Short version — having every user's phone hit Kraken/NonKYC directly leaks wallet-holder activity to the exchanges and spreads our rate-limit budget across thousands of IPs. One Worker with a cron-refreshed KV cache fixes both.
Sources
- Kraken — BTC, XMR, LTC, DOGE, ETH, BCH, XNO (all → USD)
- NonKYC — WOW (WOW_USDT, treated as ≈ USD)
- Pinned — USDT, USDC, DAI all return 1.00 (stables we don't quote upstream)
Endpoints
| Path | Shape |
|---|---|
GET /v2/rates?base=BTC"e=USD |
{ "results": { "BTC_USD": 67342.5 } } — drop-in compatible with the wallet's existing fetch code |
GET /v1/prices |
{ "rates": { ... }, "sources": { ... }, "fetched_at": "..." } — preferred, returns everything in one call |
GET /healthz |
{ ok: true, coins: N, fetched_at: ... } |
USD-only for now. Other quote values return 0 and the wallet falls back to "price unavailable."
Deploy
npm install
npx wrangler login
npx wrangler kv:namespace create PRICES
# Paste the returned id into wrangler.toml's kv_namespaces.id field.
npx wrangler deploy
After first deploy the worker is live at https://hash-wallet-prices.<your-cloudflare-subdomain>.workers.dev. To put it behind prices.suchsoftware.com, point that hostname's DNS at Cloudflare and uncomment the [[routes]] block in wrangler.toml.
Local dev
npm install
npx wrangler dev # starts a local server with hot reload
curl localhost:8787/healthz
curl 'localhost:8787/v2/rates?base=BTC"e=USD'
Adding a coin
- If Kraken lists it: add
TICKER: "PAIRUSD"toKRAKEN_PAIRSinsrc/index.ts. - If only smaller exchanges list it: add a new fetcher function alongside
fetchNonkyc()and merge its results inrefreshPrices(). Keep ittry/catchwrapped so a single source failure doesn't poison the whole refresh.
License
MIT.
Description
Cloudflare Worker that aggregates USD prices for Hash Wallet (Kraken + Nonlogs + cexswap.cc)
154 KiB
Languages
TypeScript
100%