mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-07-27 20:37:45 +00:00
eb416be780
Calendrier économique - Nouvelles sources : TE HTML scraping (483 events/2 sem.) + Investing.com en co-primaires - Dédupe déterministe par clé currency+category+date (±1j pour policy_rate) - Filtre catégorie "other", filtre discours CB (fix doublon TE vs Investing) - CHF/Switzerland via page séparée TE (hors G20) - Fenêtre 14 jours avec ?startDate=&endDate= passés à TE - ForexFactory+FRED en secours uniquement si les deux scrapers tombent à vide Probabilités OIS - rateprobability.com (7 CBs : FED/ECB/BOJ/BOE/BOC/RBA/RBNZ) - investinglive.com (Dellamotta) : scan URL-date 14 jours → couvre SNB/CHF manquant - SNB : 3% probabilité hausse au 19 juin 2026 (source : IL article 2026-05-29) - rate_expectations.json MAJ : RBNZ 79% hike (corrigé depuis 70% no-change stale) - Dédup ±1 jour pour policy_rate (fix doublon SNB TE-18/06 vs IL-19/06) Taux directeurs - USD : scrapeTeRate() = 3.75% (fin midpoint FRED 3.625%) - AUD prev : 4.10% (corrigé depuis 4.60%) - NZD/CHF/JPY/CAD : cohérents avec TE officiel Yields 10Y souverains - Nouvelle lib lib/tebonds.ts : scrape TE bonds, données du jour, cache 1h - Remplace FRED IRLTLT01XXM156N mensuel (JPY/CHF/AUD/NZD avaient 1 mois de retard) - 8 devises + spread vs USD calculé automatiquement - /api/yields et /api/drivers utilisent la même lib Drivers globaux - BTC : ticker/price Binance (plus précis que 24hr lastPrice) - HY Spread cache : 86400s → 3600s (données FRED du jour) - DriversBar : suppression affichage direct US 10Y, tooltip Crb 2-10 affiche US10Y+US2Y Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
// lib/tebonds.ts
|
|
// Scrape tradingeconomics.com/bonds pour les rendements 10Y souverains des 8 devises.
|
|
// Source : HTML statique de la page (données du jour, pas de Socket.IO nécessaire)
|
|
// EUR benchmark = Allemagne (Bund 10Y)
|
|
// Cache : 1h (la page TE est mise à jour en continu mais le cache évite l'abus)
|
|
|
|
import type { Currency } from "./types";
|
|
|
|
const TE_BOND_COUNTRIES: Record<Currency, string> = {
|
|
USD: "United States",
|
|
EUR: "Germany",
|
|
GBP: "United Kingdom",
|
|
JPY: "Japan",
|
|
AUD: "Australia",
|
|
CAD: "Canada",
|
|
CHF: "Switzerland",
|
|
NZD: "New Zealand",
|
|
};
|
|
|
|
export interface BondYield {
|
|
yield10y: number; // rendement 10Y en %
|
|
dayDelta: number; // variation journalière en points
|
|
}
|
|
|
|
export type BondYields = Partial<Record<Currency, BondYield>>;
|
|
|
|
export async function fetchTEBondYields(): Promise<BondYields> {
|
|
try {
|
|
const res = await fetch("https://tradingeconomics.com/bonds", {
|
|
next: { revalidate: 3600 },
|
|
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("[tebonds] HTTP", res.status);
|
|
return {};
|
|
}
|
|
const html = await res.text();
|
|
return parseBondsHTML(html);
|
|
} catch (err) {
|
|
console.error("[tebonds] error:", err);
|
|
return {};
|
|
}
|
|
}
|
|
|
|
function parseBondsHTML(html: string): BondYields {
|
|
const result: BondYields = {};
|
|
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_BOND_COUNTRIES) as [Currency, string][]) {
|
|
if (seen.has(ccy)) continue;
|
|
if (!text.startsWith(country)) continue;
|
|
|
|
// Ligne format : "Country Yield DayDelta WeekPct ..."
|
|
// On cherche les deux premiers nombres avec 3+ décimales
|
|
const nums = text.match(/(\d+\.\d{3,4})/g);
|
|
if (nums && nums.length >= 2) {
|
|
result[ccy] = {
|
|
yield10y: parseFloat(nums[0]),
|
|
dayDelta: parseFloat(nums[1]),
|
|
};
|
|
seen.add(ccy);
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (seen.size === 8) break; // toutes les devises trouvées
|
|
}
|
|
|
|
return result;
|
|
}
|