From d3386c3d840c5260f33f4f03d9d65d1530f77d12 Mon Sep 17 00:00:00 2001 From: 6figpsolseeker <6figpsolseeker@gmail.com> Date: Thu, 9 Apr 2026 15:43:28 -0400 Subject: [PATCH] fix(open-interest): return OI history in ascending order for charts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /open-interest/:slab endpoint returned oi_history rows in descending order (newest first). Chart consumers using lightweight-charts require strictly ascending timestamps for setData() — the same issue that was fixed in prices.ts (where DESC caused aggregateCandles to produce DESC-ordered candles and lightweight-charts silently failed). Switch to ascending: true so the history array can be fed directly into the chart component without a client-side reversal. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/routes/open-interest.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/routes/open-interest.ts b/src/routes/open-interest.ts index e0bbd91..e1f1751 100644 --- a/src/routes/open-interest.ts +++ b/src/routes/open-interest.ts @@ -77,12 +77,15 @@ export function openInterestRoutes(): Hono { }, 404); } - // Fetch historical OI data + // Fetch historical OI data in ascending order (oldest→newest) so chart + // components can feed the series directly into lightweight-charts setData(), + // which requires strictly ascending timestamps. Previously returned DESC + // (newest first) — same issue that was fixed in prices.ts (see GH#xxx). const { data: history, error: historyError } = await getSupabase() .from("oi_history") .select("timestamp, total_oi, net_lp_pos") .eq("market_slab", slab) - .order("timestamp", { ascending: false }) + .order("timestamp", { ascending: true }) .limit(100); if (historyError) {