๐ฎ๐น Borsa Italiana Provider (borsa_italiana)
The Borsa Italiana provider fetches financial data from borsaitaliana.it using the borsa-italiana-scraping library. It supports stocks, bonds (including BTP), and ETFs listed on Borsa Italiana markets (MTA, MOT, ETFPlus).
โ๏ธ How it Works
- Identifier: An ISIN code (e.g.,
IT0003128367for ENEL S.p.A.). - Identifier Types: Only
ISINis accepted. provider_params: Optionallanguagefield ("en"or"it", default"en"). Controls the language of asset names, metadata descriptions, and the provider URL.
๐ฑ Currency
All data is returned in EUR โ Borsa Italiana is an Italian exchange.
๐ฐ Current Value (get_current_value)
- Uses
ottieni_prezzo_corrente(isin)from the scraping library. - Strategy (fastest first):
- Fetches the latest point from the historical API (1M period).
- Falls back to scraping the instrument page (
ottieni_scheda).
- Returns
PrezzoCorrentewith price, date, currency, and source ("api"or"scraping").
๐ Historical Data (get_history_value)
- Uses
ottieni_storico(isin, periodo)from thegrafici.borsaitaliana.itJSON API. - Returns full OHLCV data (open, high, low, close, volume) for each trading day.
- Period selection: The API uses fixed windows (
1M,3M,6M,1Y,3Y,5Y,MAX). The provider automatically selects the smallest period that covers the requestedstart_date..end_daterange. - Results are filtered in-memory to the exact requested date range.
- The core handles gap filling (weekends, holidays) โ the plugin returns only actual trading days.
๐ Search (search)
- Uses
cerca(query)โ the internal JSON search engine of borsaitaliana.it. - Searches across all instrument types: stocks, bonds, ETFs, ETC/ETN.
- Dual-language results: emits two entries per ISIN (๐ฌ๐ง English + ๐ฎ๐น Italiano) with flag emojis in
display_name. Each result carriesprovider_params: {language: "en"|"it"}so the user's selection is propagated on assignment. - Results are deduplicated by
(ISIN, language)pair.
๐ Metadata (fetch_asset_metadata)
- Uses
ottieni_scheda(isin, lingua)โ scrapes the instrument detail page in the configured language. - Extracts:
- Name: from
<h1>tag on the page, appended with language flag emoji (e.g.,"ENEL S.p.A. ๐ฌ๐ง"). - Type: mapped from instrument type field (e.g.,
obbligazioneโ BOND,azioneโ STOCK,etfโ ETF). - Currency: negotiation currency (default EUR).
- Description: assembled from page description, market, issuer, maturity date, coupon rate, structure, tipology, coupon frequency.
- Ticker: if available on the page (mainly for stocks).
- Geographic Area: inferred from issuer name (e.g., "Republic of Italy" โ
ITA). - Sector: inferred from
settore(stocks) ortipologia(bonds) fields.
- Name: from
- Bond-specific fields available in the raw data:
cedola_annua,scadenza,emittente,rendimento_lordo,struttura_bond,frequenza_cedola.
๐ get_asset_url
Returns https://www.borsaitaliana.it/borsa/search/scheda.html?code={ISIN}&lang={language} โ the lang parameter follows the user's provider_params.language selection (default en).
๐ Technical Details
HTTP Session
The provider maintains a shared Sessione instance across all calls:
- WAF handling: The library manages Imperva WAF cookies automatically.
- JWT token: Extracted from the interactive chart page (required for the
grafici.borsaitaliana.itAPI). - Rate limiting: Built-in minimum pause between requests (0.5s default).
- Shutdown: The session is closed via
shutdown()at app teardown.
params_schema (Dynamic UI Form)
The provider exposes one optional parameter via params_schema:
| Key | Type | Options | Default | Description |
|---|---|---|---|---|
language |
select |
en (๐ฌ๐ง English), it (๐ฎ๐น Italiano) |
en |
Language for names and metadata |
Uses option_labels for human-readable display in the frontend dropdown.
Error Handling
| Library Exception | Mapped Error Code | Meaning |
|---|---|---|
StrumentoNonTrovato |
NOT_FOUND |
ISIN not recognized |
DatiNonDisponibili |
NO_DATA |
No data available (market closed, delisted) |
RicercaNonDisponibile |
FETCH_ERROR |
Search endpoint down |
BorsaItalianaErrore |
FETCH_ERROR |
Generic library error |
Dependencies
Transitive: httpx, beautifulsoup4, lxml.
๐งช Test Cases
| Identifier | Type | Description |
|---|---|---|
IT0003128367 |
ISIN | ENEL S.p.A. (stock) |
Search test query: "ENEL".
๐ Related Documentation
- ๐๏ธ Asset Architecture โ Sync pipeline and caching
- ๐ Asset Providers Overview โ All providers comparison
- ๐ Asset Plugin Guide โ How to create a new provider