Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Immo·Ka9# File : immoka/mortgage/providers/eq_bank.py10# Module : immoka11# Repository : https://git.spboucher.ai/immo-ka12# Created : 2026-08-2413# Last Modified : 2026-08-2414#15# =============================================================================16# AUTHOR & PROFESSIONAL AFFILIATION17# =============================================================================18#19# Author : Simon-Pierre Boucher20# Position : Professor of Finance21# Institution : Université du Québec en Outaouais (UQO)22# Department : Département des sciences administratives23# Organization : SP Boucher24#25# Website : https://spboucher.ai26# Git : https://git.spboucher.ai27#28# =============================================================================29# OFFICIAL CONTACT DIRECTORY30# =============================================================================31#32# General : info@spboucher.ai33# Professional : contact@spboucher.ai34# Direct : simon@spboucher.ai35# Research : research@spboucher.ai36# Development : dev@spboucher.ai37# Support : support@spboucher.ai38# Security/Admin : admin@spboucher.ai39# Notifications : notifications@spboucher.ai40#41# Preferred Contact: contact@spboucher.ai42#43# =============================================================================44# COPYRIGHT & INTELLECTUAL PROPERTY45# =============================================================================46#47# Copyright (c) 202648# Simon-Pierre Boucher49#50# All rights reserved where applicable.51#52# This file is governed by the applicable project license,53# copyright notices, institutional agreements and relevant law.54#55# Unless expressly authorized by the applicable license or56# rights holder, copying, redistribution, sublicensing,57# publication and commercial exploitation are not permitted.58#59# Existing third-party rights and notices remain unaffected.60#61# =============================================================================62# CONFIDENTIALITY & SECURITY63# =============================================================================64#65# Classification : Public66# Distribution : Public repository; use is governed by the project license67# Security Contact : admin@spboucher.ai68#69# Access to this source does not independently grant permission70# to redistribute or disclose confidential materials.71#72# Do not embed credentials, private keys, access tokens,73# certificates or confidential personal information.74#75# =============================================================================76# LICENSE & MAINTENANCE77# =============================================================================78#79# License : None specified (no license file in this repository)80# Maintainer : Simon-Pierre Boucher81# Technical Contact: dev@spboucher.ai82#83# =============================================================================84# END OF SP BOUCHER SOURCE HEADER85# =============================================================================8687# -----------------------------------------------------------------------------88# Immo-Ka — Agrégateur de maisons à vendre (province de Québec)89# Auteur : Simon-Pierre Boucher — contact@spboucher.ai90# mortgage/providers/eq_bank.py : Banque EQ / Équitable — dictionnaire JSON91# global embarqué dans le payload Next.js de la page des taux (marqueur92# \"rates\":{ échappé). Clés CMS stables ; les clés « Adjustable » sont des93# ÉCARTS vs prime (jamais interprétées comme des taux).94# -----------------------------------------------------------------------------95from __future__ import annotations9697import json9899from .base import RateProvider100101# clé CMS -> (rate_type, terme mois, kind, nom, clé APR éventuelle)102KEY_MAP: dict[str, tuple] = {103 "mortgage-rate-fixed-5-year": ("fixed", 60, "special",104 "Fixe 5 ans (vitrine EQ)",105 "mortgage-rate-fixed-5-year-APR"),106 "mortgage-rate-variable-5-year": ("variable", 60, "special",107 "Variable 5 ans (vitrine EQ)",108 "mortgage-rate-variable-5-year-APR"),109 "es-fixed-12-month": ("fixed", 12, "special", "Evolution Suite — fixe 1 an", None),110 "es-fixed-24-month": ("fixed", 24, "special", "Evolution Suite — fixe 2 ans", None),111 "es-fixed-36-month": ("fixed", 36, "special", "Evolution Suite — fixe 3 ans", None),112 "es-fixed-48-month": ("fixed", 48, "special", "Evolution Suite — fixe 4 ans", None),113 "es-fixed-60-month": ("fixed", 60, "special", "Evolution Suite — fixe 5 ans", None),114 "Standard-Mortgage-Rate-1-Year-Fixed": ("fixed", 12, "posted", "Fixe affiché 1 an", None),115 "Standard-Mortgage-Rate-2-Year-Fixed": ("fixed", 24, "posted", "Fixe affiché 2 ans", None),116 "Standard-Mortgage-Rate-3-Year-Fixed": ("fixed", 36, "posted", "Fixe affiché 3 ans", None),117 "Standard-Mortgage-Rate-4-Year-Fixed": ("fixed", 48, "posted", "Fixe affiché 4 ans", None),118 "Standard-Mortgage-Rate-5-Year-Fixed": ("fixed", 60, "posted", "Fixe affiché 5 ans", None),119}120PRIME_KEY = "equitable-prime-rate"121122123def extract_rates_blob(html: str) -> dict:124 """Isole le dictionnaire {clé: {name, rate}} du payload Next.js.125 Le JSON est échappé dans le HTML (\\\" -> \")."""126 marker = '\\"rates\\":{'127 i = html.find(marker)128 if i < 0:129 marker = '"rates":{'130 i = html.find(marker)131 if i < 0:132 raise ValueError("marqueur rates introuvable (structure changée)")133 seg = html[i:i + 400_000].replace('\\"', '"')134 start = seg.find("{")135 depth = 0136 for j, ch in enumerate(seg[start:], start):137 if ch == "{":138 depth += 1139 elif ch == "}":140 depth -= 1141 if depth == 0:142 return json.loads(seg[start:j + 1])143 raise ValueError("JSON rates non équilibré (structure changée)")144145146class EqBankProvider(RateProvider):147 provider_id = "eq_bank"148 institution = "Banque EQ"149 source_url = "https://www.eqbank.ca/residential/mortgage-rates"150 request_delay = 1.0151152 def fetch(self) -> list[dict]:153 return self.parse(self.get(self.source_url).text)154155 def parse(self, payload: str) -> list[dict]:156 rates = extract_rates_blob(payload)157158 def val(key: str) -> float | None:159 cell = rates.get(key)160 if isinstance(cell, dict) and isinstance(cell.get("rate"), (int, float)):161 return float(cell["rate"])162 return None163164 out: list[dict] = []165 for key, (rtype, term, kind, name, apr_key) in KEY_MAP.items():166 rate = val(key)167 if rate is None:168 continue # clé absente : produit omis, jamais deviné169 apr = val(apr_key) if apr_key else None170 out.append(self.make_product(171 rate=rate, rate_type=rtype, term_months=term, kind=kind,172 product_name=name, apr=apr,173 raw={"key": key, "rate": rate, "apr": apr}))174 prime = val(PRIME_KEY)175 if prime is not None:176 out.append(self.make_product(177 rate=prime, rate_type="other", term_months=12, kind="posted",178 product_name="Taux préférentiel Banque Équitable",179 purpose="unknown", raw={"key": PRIME_KEY, "rate": prime}))180 return out181