mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-08-24 01:48:06 +00:00
auto: sync 2026-06-01 23:56
This commit is contained in:
+28
-14
@@ -5,7 +5,7 @@ import cpiOverridesRaw from "@/data/cpi_overrides.json";
|
|||||||
import rateDecisionsRaw from "@/data/rate_decisions.json";
|
import rateDecisionsRaw from "@/data/rate_decisions.json";
|
||||||
import { fetchFFThisWeek, fetchFFEvents } from "@/lib/forexfactory";
|
import { fetchFFThisWeek, fetchFFEvents } from "@/lib/forexfactory";
|
||||||
import type { FFEvent } from "@/lib/forexfactory";
|
import type { FFEvent } from "@/lib/forexfactory";
|
||||||
import { fetchTECoreInflation } from "@/lib/tecpi";
|
import { fetchTECoreInflation, fetchTEMoMInflation } from "@/lib/tecpi";
|
||||||
|
|
||||||
const FRED_BASE = "https://api.stlouisfed.org/fred/series/observations";
|
const FRED_BASE = "https://api.stlouisfed.org/fred/series/observations";
|
||||||
const REVALIDATE = 86400; // cache 24h
|
const REVALIDATE = 86400; // cache 24h
|
||||||
@@ -1003,23 +1003,37 @@ export async function GET(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── TE Core CPI (priorité maximale — données du jour, toutes devises) ────────
|
// ── TE CPI override (priorité maximale — données du jour, toutes devises) ───
|
||||||
// Remplace les séries FRED erronées :
|
// Deux pages TE en parallèle : core YoY + MoM
|
||||||
// GBP GBRCPIALLMINMEI = All Items (headline), pas core → écart ~1%
|
// Remplace séries FRED stale/erronées (GBP headline au lieu de core,
|
||||||
// JPY PCPI total (3.6%) ≠ core (1.4%) → erreur massive
|
// JPY PCPI total ≠ core, CHF/CAD/AUD/NZD retard 1–18 mois)
|
||||||
// USD CPILFESL retard 1 mois → écart 0.2%
|
|
||||||
// AUD/NZD trimestriels → retard jusqu'à 3 mois
|
|
||||||
{
|
{
|
||||||
const teCpi = await fetchTECoreInflation();
|
const [teCoreMap, teMoMMap] = await Promise.all([
|
||||||
const te = teCpi[currency];
|
fetchTECoreInflation(),
|
||||||
if (te) {
|
fetchTEMoMInflation(),
|
||||||
const surprise = parseFloat((te.value - te.prev).toFixed(3));
|
]);
|
||||||
|
|
||||||
|
const teCore = teCoreMap[currency];
|
||||||
|
if (teCore) {
|
||||||
|
const surprise = parseFloat((teCore.value - teCore.prev).toFixed(3));
|
||||||
indicators.cpiCore = {
|
indicators.cpiCore = {
|
||||||
value: te.value,
|
value: teCore.value,
|
||||||
prev: te.prev,
|
prev: teCore.prev,
|
||||||
surprise,
|
surprise,
|
||||||
trend: surprise > 0 ? "up" : surprise < 0 ? "down" : "flat",
|
trend: surprise > 0 ? "up" : surprise < 0 ? "down" : "flat",
|
||||||
lastUpdated: te.refMonth,
|
lastUpdated: teCore.refMonth,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const teMoM = teMoMMap[currency];
|
||||||
|
if (teMoM) {
|
||||||
|
const surprise = parseFloat((teMoM.value - teMoM.prev).toFixed(3));
|
||||||
|
indicators.cpiMoM = {
|
||||||
|
value: teMoM.value,
|
||||||
|
prev: teMoM.prev,
|
||||||
|
surprise,
|
||||||
|
trend: surprise > 0 ? "up" : surprise < 0 ? "down" : "flat",
|
||||||
|
lastUpdated: teMoM.refMonth,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,63 @@ export async function fetchTECoreInflation(): Promise<CoreCPIMap> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── MoM inflation rate ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function fetchTEMoMInflation(): Promise<MoMCPIMap> {
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
"https://tradingeconomics.com/country-list/inflation-rate-mom?continent=world",
|
||||||
|
{
|
||||||
|
next: { revalidate: 21600 },
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0.0.0 Safari/537.36",
|
||||||
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||||
|
"Accept-Language": "en-US,en;q=0.9",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!res.ok) { console.warn("[tecpi-mom] HTTP", res.status); return {}; }
|
||||||
|
const html = await res.text();
|
||||||
|
return parseMoMHTML(html);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[tecpi-mom] error:", err);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseMoMHTML(html: string): MoMCPIMap {
|
||||||
|
const result: MoMCPIMap = {};
|
||||||
|
const seen = new Set<Currency>();
|
||||||
|
const rowPattern = /<tr[^>]*>([\s\S]*?)<\/tr>/g;
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
|
||||||
|
while ((m = rowPattern.exec(html)) !== null) {
|
||||||
|
const text = m[1].replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
||||||
|
|
||||||
|
for (const [ccy, country] of Object.entries(TE_COUNTRY_CPI) as [Currency, string][]) {
|
||||||
|
if (seen.has(ccy)) continue;
|
||||||
|
if (!text.startsWith(country)) continue;
|
||||||
|
|
||||||
|
const nums = text.match(/-?\d+\.?\d*/g);
|
||||||
|
const dateMatch = text.match(/([A-Za-z]{3}\/\d{2})/);
|
||||||
|
|
||||||
|
if (nums && nums.length >= 2) {
|
||||||
|
result[ccy] = {
|
||||||
|
value: parseFloat(nums[0]),
|
||||||
|
prev: parseFloat(nums[1]),
|
||||||
|
refMonth: dateMatch ? parseRefDate(dateMatch[1]) : "",
|
||||||
|
};
|
||||||
|
seen.add(ccy);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (seen.size === 8) break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Core YoY ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function parseCoreInflationHTML(html: string): CoreCPIMap {
|
function parseCoreInflationHTML(html: string): CoreCPIMap {
|
||||||
const result: CoreCPIMap = {};
|
const result: CoreCPIMap = {};
|
||||||
const seen = new Set<Currency>();
|
const seen = new Set<Currency>();
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user