mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-08-08 02:07:43 +00:00
auto: sync 2026-06-02 15:35
This commit is contained in:
+18
-21
@@ -5,7 +5,7 @@ import cpiOverridesRaw from "@/data/cpi_overrides.json";
|
||||
import rateDecisionsRaw from "@/data/rate_decisions.json";
|
||||
import { fetchFFThisWeek, fetchFFEvents } from "@/lib/forexfactory";
|
||||
import type { FFEvent } from "@/lib/forexfactory";
|
||||
import { fetchTECoreInflation, fetchTEMoMInflation, fetchTEInflationYoY, fetchTECoreCPIMoM, fetchTECPIIndex, fetchTECoreConsumerPricesIndex } from "@/lib/tecpi";
|
||||
import { fetchTECoreInflation, fetchTEMoMInflation, fetchTEInflationYoY, fetchTECoreCPIMoM, fetchTECoreConsumerPricesIndex, fetchTEPPIMoM } from "@/lib/tecpi";
|
||||
import { fetchTEInflationForecasts } from "@/lib/tradingeconomics";
|
||||
|
||||
const FRED_BASE = "https://api.stlouisfed.org/fred/series/observations";
|
||||
@@ -1020,15 +1020,15 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
// ── TE CPI override (priorité maximale — données du jour, toutes devises) ───
|
||||
// Remplace séries FRED stale/erronées.
|
||||
// Nouvelles données : cpiYoY headline, cpiCoreMoM (pages individuelles), cpiIndex MoM%
|
||||
// Nouvelles données : cpiYoY headline, cpiCoreMoM (pages individuelles), ppiMoM
|
||||
{
|
||||
const [teCoreMap, teMoMMap, teYoYMap, teCoreMoMMap, teIdxMap, teCoreIdxMap] = await Promise.all([
|
||||
const [teCoreMap, teMoMMap, teYoYMap, teCoreMoMMap, teCoreIdxMap, tePPIMap] = await Promise.all([
|
||||
fetchTECoreInflation(),
|
||||
fetchTEMoMInflation(),
|
||||
fetchTEInflationYoY(),
|
||||
fetchTECoreCPIMoM(),
|
||||
fetchTECPIIndex(),
|
||||
fetchTECoreConsumerPricesIndex(),
|
||||
fetchTEPPIMoM(),
|
||||
]);
|
||||
|
||||
const teCore = teCoreMap[currency];
|
||||
@@ -1086,27 +1086,24 @@ export async function GET(req: NextRequest) {
|
||||
};
|
||||
}
|
||||
|
||||
// CPI Index → MoM% (avec rawValues pour tooltip)
|
||||
const teIdx = teIdxMap[currency];
|
||||
if (teIdx) {
|
||||
const surprise = parseFloat((teIdx.momPct - (teIdxMap[currency]?.rawPrev ?? 0)).toFixed(3));
|
||||
indicators.cpiIndex = {
|
||||
value: teIdx.momPct,
|
||||
prev: null,
|
||||
surprise: null,
|
||||
trend: teIdx.momPct > 0 ? "up" : teIdx.momPct < 0 ? "down" : "flat",
|
||||
lastUpdated: teIdx.refMonth,
|
||||
// PPI MoM
|
||||
const tePPI = tePPIMap[currency];
|
||||
if (tePPI) {
|
||||
const surprise = tePPI.prev !== null
|
||||
? parseFloat((tePPI.value - tePPI.prev).toFixed(3))
|
||||
: null;
|
||||
indicators.ppiMoM = {
|
||||
value: tePPI.value,
|
||||
prev: tePPI.prev,
|
||||
surprise,
|
||||
trend: tePPI.value > 0 ? "up" : tePPI.value < 0 ? "down" : "flat",
|
||||
lastUpdated: tePPI.refMonth,
|
||||
};
|
||||
}
|
||||
|
||||
// Raw index values for tooltips (CPI + Core CPI)
|
||||
// Raw Core CPI index values for tooltip on cpiCoreMoM
|
||||
const teRawCore = teCoreIdxMap[currency];
|
||||
// Stored in the response as rawCpiIndex and rawCoreIndex
|
||||
const rawCpiIndex = teIdx ? { last: teIdx.rawLast, prev: teIdx.rawPrev, refMonth: teIdx.refMonth } : null;
|
||||
const rawCoreIndex = teRawCore ? { last: teRawCore.rawLast, prev: teRawCore.rawPrev, refMonth: teRawCore.refMonth } : null;
|
||||
|
||||
// Attach raw values to indicators for tooltip access
|
||||
if (indicators.cpiIndex && rawCpiIndex) (indicators.cpiIndex as Record<string,unknown>)["_raw"] = rawCpiIndex;
|
||||
const rawCoreIndex = teRawCore ? { last: teRawCore.rawLast, prev: teRawCore.rawPrev, refMonth: teRawCore.refMonth } : null;
|
||||
if (indicators.cpiCoreMoM && rawCoreIndex) (indicators.cpiCoreMoM as Record<string,unknown>)["_raw"] = rawCoreIndex;
|
||||
}
|
||||
|
||||
|
||||
+47
-29
@@ -135,8 +135,9 @@ export default function CurrencyCard({ currency, expectations, yields, sentiment
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [rateExp, setRateExp] = useState<RateExpectation | null>(null);
|
||||
const [fromCache, setFromCache] = useState(false);
|
||||
const [cacheAge, setCacheAge] = useState<string | null>(null);
|
||||
const [fromCache, setFromCache] = useState(false);
|
||||
const [cacheAge, setCacheAge] = useState<string | null>(null);
|
||||
const [inflFilter, setInflFilter] = useState<"all" | "mom" | "yoy">("mom");
|
||||
|
||||
// Single fetch — server batches all FRED calls
|
||||
const load = useCallback(async () => {
|
||||
@@ -346,7 +347,7 @@ export default function CurrencyCard({ currency, expectations, yields, sentiment
|
||||
<SectionHeader label="Politique monétaire" />
|
||||
<Row label="Taux directeur" ind={inds?.policyRate ?? null} unit="%" consensus={rateConsensus} />
|
||||
<div className="flex items-center justify-between py-1.5 text-xs border-b border-gray-50">
|
||||
<span className="text-gray-500 text-xs">10Y Yield</span>
|
||||
<span className="text-gray-500 text-xs pl-5">10Y Yield</span>
|
||||
<span className="font-semibold text-gray-800 tabular-nums text-xs">
|
||||
{yield10Y !== null ? `${yield10Y.toFixed(2)}%` : "—"}
|
||||
{spread10Y !== null && (
|
||||
@@ -358,32 +359,49 @@ export default function CurrencyCard({ currency, expectations, yields, sentiment
|
||||
</div>
|
||||
|
||||
{/* ── INFLATION ───────────────────────────────────────────────────── */}
|
||||
<SectionHeader label="Inflation" />
|
||||
<Row label="CPI Core YoY" ind={inds?.cpiCore ?? null} unit="%" consensus={fc?.cpiCore ?? fc?.cpi ?? null} surpriseVsCons={fc?.cpiSurprise ?? null} />
|
||||
<Row
|
||||
label={(() => {
|
||||
const isQoQ = (inds?.cpiCoreMoM as (Ind & { isQoQ?: boolean }) | null)?.isQoQ;
|
||||
return isQoQ ? "Core CPI QoQ" : "Core CPI MoM";
|
||||
})()}
|
||||
ind={inds?.cpiCoreMoM ?? null}
|
||||
unit="%"
|
||||
tooltip={(() => {
|
||||
const raw = (inds?.cpiCoreMoM as (Ind & { _raw?: { last: number; prev: number; refMonth: string } }) | null)?._raw;
|
||||
const base = "=Core Inflation Rate MoM";
|
||||
return raw ? `${base} — Index: last=${raw.last} prev=${raw.prev} ref=${raw.refMonth}` : base;
|
||||
})()}
|
||||
/>
|
||||
<Row label="Inflation YoY" ind={inds?.cpiYoY ?? null} unit="%" />
|
||||
<Row label="CPI MoM" ind={inds?.cpiMoM ?? null} unit="%" consensus={fc?.cpiMoM ?? null} />
|
||||
<Row
|
||||
label="CPI Index MoM%"
|
||||
ind={inds?.cpiIndex ?? null}
|
||||
unit="%"
|
||||
tooltip={(() => {
|
||||
const raw = (inds?.cpiIndex as (Ind & { _raw?: { last: number; prev: number; refMonth: string } }) | null)?._raw;
|
||||
return raw ? `Index: last=${raw.last} prev=${raw.prev} ref=${raw.refMonth}` : null;
|
||||
})()}
|
||||
/>
|
||||
<div className="flex items-center justify-between mt-2 mb-0.5">
|
||||
<span className="text-[8px] font-bold text-gray-300 uppercase tracking-widest">Inflation</span>
|
||||
<div className="flex gap-0.5">
|
||||
{(["all", "mom", "yoy"] as const).map((v) => (
|
||||
<button
|
||||
key={v}
|
||||
onClick={() => setInflFilter(v)}
|
||||
className={`text-[8px] px-1.5 py-0.5 rounded font-semibold uppercase tracking-wide transition-colors ${
|
||||
inflFilter === v
|
||||
? "bg-gray-700 text-white"
|
||||
: "text-gray-400 hover:text-gray-600"
|
||||
}`}
|
||||
>
|
||||
{v === "all" ? "Tout" : v.toUpperCase()}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{(inflFilter === "all" || inflFilter === "mom") && (
|
||||
<>
|
||||
<Row label="PPI MoM" ind={inds?.ppiMoM ?? null} unit="%" />
|
||||
<Row label="CPI MoM" ind={inds?.cpiMoM ?? null} unit="%" consensus={fc?.cpiMoM ?? null} />
|
||||
<Row
|
||||
label={(() => {
|
||||
const isQoQ = (inds?.cpiCoreMoM as (Ind & { isQoQ?: boolean }) | null)?.isQoQ;
|
||||
return isQoQ ? "Core CPI QoQ" : "Core CPI MoM";
|
||||
})()}
|
||||
ind={inds?.cpiCoreMoM ?? null}
|
||||
unit="%"
|
||||
tooltip={(() => {
|
||||
const raw = (inds?.cpiCoreMoM as (Ind & { _raw?: { last: number; prev: number; refMonth: string } }) | null)?._raw;
|
||||
const base = "=Core Inflation Rate MoM";
|
||||
return raw ? `${base} — Index: last=${raw.last} prev=${raw.prev} ref=${raw.refMonth}` : base;
|
||||
})()}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{(inflFilter === "all" || inflFilter === "yoy") && (
|
||||
<>
|
||||
<Row label="Core CPI YoY" ind={inds?.cpiCore ?? null} unit="%" consensus={fc?.cpiCore ?? fc?.cpi ?? null} surpriseVsCons={fc?.cpiSurprise ?? null} />
|
||||
<Row label="Inflation Rate YoY" ind={inds?.cpiYoY ?? null} unit="%" />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── CROISSANCE ──────────────────────────────────────────────────── */}
|
||||
<SectionHeader label="Croissance" />
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user