@@ -228,6 +228,120 @@ backend/ # TypeScript API server
228228
229229---
230230
231+ ## 🔌 Backend API
232+
233+ Base URL: ` http://127.0.0.1:3001 `
234+
235+ ### GET /api/get-adaprice
236+ Returns the current ADA/USD price from Pyth Lazer.
237+
238+ ```
239+ GET /api/get-adaprice
240+ ```
241+
242+ ** Response 200**
243+ ``` json
244+ {
245+ "symbol" : " ADA/USD" ,
246+ "price" : 0.25446211 ,
247+ "confidence" : 0.00003405 ,
248+ "publishers" : 12 ,
249+ "timestamp" : " 2026-03-22T14:30:00.000Z" ,
250+ "leEcdsaPayload" : " 0x1a2b3c..."
251+ }
252+ ```
253+
254+ ---
255+
256+ ### GET /api/get-adaprice-history
257+ Returns the ADA/USD price at a specific past timestamp.
258+
259+ ```
260+ GET /api/get-adaprice-history?timestamp={unix_seconds}
261+ ```
262+
263+ | Parameter | Type | Required | Description |
264+ | ---| ---| ---| ---|
265+ | ` timestamp ` | number | ✅ | Unix timestamp in seconds |
266+
267+ ** Response 200**
268+ ``` json
269+ {
270+ "symbol" : " ADA/USD" ,
271+ "price" : 0.25312000 ,
272+ "confidence" : 0.00003100 ,
273+ "publishers" : 12 ,
274+ "timestamp_requested" : " 2026-03-22T10:00:00.000Z" ,
275+ "timestamp_actual" : " 2026-03-22T10:00:00.200Z" ,
276+ "leEcdsaPayload" : " 0x1a2b3c..."
277+ }
278+ ```
279+
280+ | Status | Description |
281+ | ---| ---|
282+ | 400 | Missing ` timestamp ` parameter |
283+ | 404 | No data for that timestamp |
284+ | 429 | Rate limit exceeded |
285+ | 500 | Internal error |
286+
287+ ---
288+
289+ ### GET /api/get-adaprice-range
290+ Returns a price series between two timestamps. Compatible with TradingView Lightweight Charts.
291+
292+ ```
293+ GET /api/get-adaprice-range?from={unix_seconds}&to={unix_seconds}&interval={seconds}
294+ ```
295+
296+ | Parameter | Type | Required | Default | Description |
297+ | ---| ---| ---| ---| ---|
298+ | ` from ` | number | ✅ | — | Range start (Unix seconds) |
299+ | ` to ` | number | ✅ | — | Range end (Unix seconds) |
300+ | ` interval ` | number | ❌ | ` 60 ` | Seconds between each data point |
301+
302+ > Maximum 500 points per request. If exceeded, returns 400 with suggested interval.
303+
304+ ** Recommended intervals**
305+
306+ | Range | Suggested interval | Approx points |
307+ | ---| ---| ---|
308+ | 1 hour | ` 15 ` (15 sec) | 240 |
309+ | 2 hours | ` 300 ` (5 min) | 24 |
310+ | 24 hours | ` 3600 ` (1 hour) | 24 |
311+ | 7 days | ` 86400 ` (1 day) | 7 |
312+
313+ ** Response 200**
314+ ``` json
315+ {
316+ "symbol" : " ADA/USD" ,
317+ "from" : " 2026-03-22T10:00:00.000Z" ,
318+ "to" : " 2026-03-22T12:00:00.000Z" ,
319+ "intervalSec" : 300 ,
320+ "points" : 24 ,
321+ "data" : [
322+ { "time" : 1742641800 , "value" : 0.25446211 , "confidence" : 0.00003405 },
323+ { "time" : 1742642100 , "value" : 0.25512000 , "confidence" : 0.00003100 }
324+ ]
325+ }
326+ ```
327+
328+ > ` time ` is in Unix seconds — directly compatible with TradingView Lightweight Charts.
329+
330+ | Status | Description |
331+ | ---| ---|
332+ | 400 | Missing ` from ` /` to ` , or 500-point limit exceeded |
333+ | 500 | Internal error / all Pyth endpoints failed |
334+
335+ ---
336+
337+ ### API Notes
338+ - All prices in ** USD**
339+ - ` leEcdsaPayload ` is the signed binary payload for on-chain verification in Aiken/Cardano contracts
340+ - Real price = ` mantissa × 10^exponent ` (already applied in the response)
341+ - Backend has ** automatic fallback** across 3 Pyth endpoints — if one fails, it tries the next
342+
343+ ---
344+
231345✅ Quality Checklist
232346
233347- [x] Make it beautiful: Clean hierarchy and formatting.
0 commit comments