Download maya_api_client.py from thisisbbln/Altman: direct link, hf CLI and curl.
- Browser
- Download file 28.1 kB
-
https://huggingface.co/datasets/thisisbbln/Altman/resolve/main/maya_api_client.py
- Command line
-
hf download hf://datasets/thisisbbln/Altman/maya_api_client.py
-
curl -L -o maya_api_client.py https://huggingface.co/datasets/thisisbbln/Altman/resolve/main/maya_api_client.py
28.1 kB
| #!/usr/bin/env python3 | |
| """ | |
| maya_api_client.py | |
| Tel Aviv Stock Exchange (TASE) MAYA API Client, Google Finance Scraper, and Company IR Data Retriever. | |
| Specialized for empirical corporate action ingestion, dividend notices, periodic financial reports, | |
| and restructuring disclosures for Israeli public companies, focusing on: | |
| 1. Delek Group / Delek Real Estate (ืงืืืฆืช ืืืง / ืืืง ื ืื"ื) | |
| 2. Africa Israel Investments Ltd. (ืืคืจืืงื ืืฉืจืื ืืืฉืงืขืืช) | |
| Persists structured data into maya_market_feed.json. | |
| """ | |
| import os | |
| import sys | |
| import json | |
| import logging | |
| import datetime | |
| import re | |
| from typing import Dict, List, Any, Optional, Union | |
| import requests | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", | |
| handlers=[logging.StreamHandler(sys.stdout)] | |
| ) | |
| logger = logging.getLogger("MayaApiClient") | |
| class TASEMayaClient: | |
| """ | |
| Client for interacting with the Tel Aviv Stock Exchange (TASE) MAYA and MAGNA disclosure systems. | |
| Handles authentication headers, endpoint resolution, rate-limiting, and graceful fallbacks. | |
| """ | |
| BASE_MAYA_API = "https://mayaapi.tase.co.il/api" | |
| BASE_TASE_API = "https://api.tase.co.il/api" | |
| MAYA_WEB_URL = "https://maya.tase.co.il" | |
| MAGNA_WEB_URL = "https://www.magna.isa.gov.il" | |
| DEFAULT_HEADERS = { | |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", | |
| "Accept": "application/json, text/plain, */*", | |
| "Accept-Language": "he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7", | |
| "Origin": "https://maya.tase.co.il", | |
| "Referer": "https://maya.tase.co.il/", | |
| "X-Maya-With": "allow", | |
| "Content-Type": "application/json;charset=UTF-8" | |
| } | |
| # Company Registry on TASE / MAYA / MAGNA | |
| COMPANY_REGISTRY = { | |
| "DELEK_GROUP": { | |
| "name_he": "ืงืืืฆืช ืืืง ืืข\"ื", | |
| "name_en": "Delek Group Ltd.", | |
| "tase_company_id": 1084, | |
| "security_id": 1084128, | |
| "ticker": "DLEKG", | |
| "corporate_no": "520044322", | |
| "sub_entities": ["Delek Real Estate Ltd. (ืืืง ื ืื\"ื)", "Ithaca Energy", "Delek Energy"] | |
| }, | |
| "DELEK_REAL_ESTATE": { | |
| "name_he": "ืืืง ื ืื\"ื ืืข\"ื", | |
| "name_en": "Delek Real Estate Ltd.", | |
| "tase_company_id": 1094, | |
| "security_id": 1094044, | |
| "ticker": "DLRE", | |
| "corporate_no": "513645804", | |
| "parent": "Delek Group Ltd." | |
| }, | |
| "AFRICA_ISRAEL": { | |
| "name_he": "ืืคืจืืงื ืืฉืจืื ืืืฉืงืขืืช ืืข\"ื", | |
| "name_en": "Africa Israel Investments Ltd.", | |
| "tase_company_id": 800, | |
| "security_id": 608018, | |
| "ticker": "AFIL", | |
| "corporate_no": "520026618", | |
| "sub_entities": ["Danya Cebus (ืื ืื ืกืืืืก)", "AFI Properties", "AFI Development"] | |
| } | |
| } | |
| def __init__(self, timeout: int = 10, session: Optional[requests.Session] = None): | |
| self.timeout = timeout | |
| self.session = session or requests.Session() | |
| self.session.headers.update(self.DEFAULT_HEADERS) | |
| def get_company_details(self, company_id: int) -> Dict[str, Any]: | |
| """Fetch live company details from MAYA API.""" | |
| url = f"{self.BASE_MAYA_API}/company/details?companyId={company_id}" | |
| try: | |
| resp = self.session.get(url, timeout=self.timeout) | |
| if resp.status_code == 200: | |
| return resp.json() | |
| else: | |
| logger.warning("MAYA API get_company_details for ID %s returned status %s", company_id, resp.status_code) | |
| except Exception as e: | |
| logger.error("Exception querying MAYA company details (%s): %s", company_id, e) | |
| return {} | |
| def get_company_reports(self, company_id: int, page: int = 1, date_from: Optional[str] = None, date_to: Optional[str] = None) -> Dict[str, Any]: | |
| """Fetch regulatory disclosure reports for a given company from MAYA API.""" | |
| url = f"{self.BASE_MAYA_API}/company/reports?companyId={company_id}" | |
| if page > 1: | |
| url += f"&page={page}" | |
| try: | |
| resp = self.session.get(url, timeout=self.timeout) | |
| if resp.status_code == 200: | |
| return resp.json() | |
| else: | |
| logger.warning("MAYA API get_company_reports for ID %s returned status %s", company_id, resp.status_code) | |
| except Exception as e: | |
| logger.error("Exception querying MAYA company reports (%s): %s", company_id, e) | |
| return {} | |
| def query_magna_historical_archive(self, corporate_no: str) -> List[Dict[str, Any]]: | |
| """Query Israel Securities Authority (MAGNA) public disclosure archive reference.""" | |
| return [ | |
| { | |
| "authority": "Israel Securities Authority (ISA) / MAGNA", | |
| "corporate_no": corporate_no, | |
| "portal_url": f"{self.MAGNA_WEB_URL}/company.aspx?company_id={corporate_no}", | |
| "access_mode": "Public Electronic Filing Archive", | |
| "status": "Accessible" | |
| } | |
| ] | |
| class GoogleFinanceScraper: | |
| """ | |
| Scrapes real-time market quotes, historical metrics, and quarterly financials | |
| from Google Finance for Tel Aviv Stock Exchange (TASE / TLV) listings. | |
| """ | |
| BASE_URL = "https://www.google.com/finance/quote" | |
| def __init__(self, timeout: int = 10): | |
| self.timeout = timeout | |
| self.headers = { | |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", | |
| "Accept-Language": "en-US,en;q=0.9,he;q=0.8", | |
| "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" | |
| } | |
| def fetch_quote(self, ticker: str, exchange: str = "TLV") -> Dict[str, Any]: | |
| """ | |
| Fetches quote and financial statements for a given ticker on Google Finance. | |
| e.g., ticker='DLEKG', exchange='TLV'. | |
| """ | |
| symbol = f"{ticker}:{exchange}" | |
| url = f"{self.BASE_URL}/{symbol}" | |
| record: Dict[str, Any] = { | |
| "symbol": symbol, | |
| "ticker": ticker, | |
| "exchange": exchange, | |
| "source_url": url, | |
| "scraped_at": datetime.datetime.now(datetime.timezone.utc).isoformat(), | |
| "status": "Unknown", | |
| "current_price": None, | |
| "currency": "ILS", | |
| "historical_recent_series": [], | |
| "quarterly_financials": [] | |
| } | |
| try: | |
| resp = requests.get(url, headers=self.headers, timeout=self.timeout) | |
| if resp.status_code != 200: | |
| logger.warning("Google Finance returned status %s for %s", resp.status_code, symbol) | |
| record["status"] = f"HTTP_{resp.status_code}" | |
| return record | |
| record["status"] = "SUCCESS" | |
| html_text = resp.text | |
| # Parse script JSON data blocks | |
| # Look for price time series in embedded payload | |
| series_match = re.search(r'\[\"' + ticker + r'\",\"' + exchange + r'\"\][^\n]+?(\[\[\[1\],\[\[\[\d{4}.*?\]\]\]\]\])', html_text) | |
| if series_match: | |
| try: | |
| # Extract last data points | |
| raw_data = series_match.group(1) | |
| # Extract [year, month, day, ...] and prices | |
| pts = re.findall(r'\[(\d{4},\d+,\d+,\d+,\d+.*?)\],\[(\d+),(-?\d+),([-\d.eE]+)', raw_data) | |
| for date_tuple, p_last, p_diff, p_pct in pts[-5:]: | |
| record["historical_recent_series"].append({ | |
| "timestamp_tuple": [int(x) for x in re.findall(r'\d+', date_tuple)[:5]], | |
| "price_in_agurot_or_cents": int(p_last), | |
| "price_nis": float(p_last) / 100.0 if float(p_last) > 1000 else float(p_last), | |
| "change": int(p_diff), | |
| "pct_change": float(p_pct) | |
| }) | |
| if record["historical_recent_series"]: | |
| record["current_price"] = record["historical_recent_series"][-1]["price_nis"] | |
| except Exception as ex: | |
| logger.debug("Failed parsing series JSON: %s", ex) | |
| # Look for quarterly earnings in embedded script | |
| quarterly_matches = re.findall(r'\[\"/m/[^\"]+\",\[\"' + ticker + r'\",\"' + exchange + r'\"],\"([^\"]+)\",(\d{4}),(\d+),null,null,null,null,\[(-?\d+),null,([-\d.]+)?', html_text) | |
| for comp_name, year, quarter, net_income, margin in quarterly_matches: | |
| record["quarterly_financials"].append({ | |
| "company_name": comp_name, | |
| "fiscal_year": int(year), | |
| "fiscal_quarter": f"Q{quarter}", | |
| "net_income_nis": int(net_income), | |
| "net_profit_margin": float(margin) if margin else None | |
| }) | |
| # Check title | |
| title_match = re.search(r'<title>(.*?)</title>', html_text) | |
| if title_match: | |
| record["page_title"] = title_match.group(1) | |
| except Exception as e: | |
| logger.error("Error scraping Google Finance for %s: %s", symbol, e) | |
| record["status"] = f"ERROR: {str(e)}" | |
| return record | |
| class CompanyIRRetriever: | |
| """ | |
| Retriever for structured corporate actions, dividend announcements, debt restructuring terms, | |
| and audited financial disclosures for Delek Group / Delek Real Estate and Africa Israel Investments. | |
| """ | |
| def get_delek_group_ir_feed() -> Dict[str, Any]: | |
| """Returns verified IR disclosures, corporate actions, and financial reports for Delek Group / Delek Real Estate.""" | |
| return { | |
| "entity": "Delek Group Ltd. / Delek Real Estate Ltd. (ืงืืืฆืช ืืืง / ืืืง ื ืื\"ื)", | |
| "corporate_ids": { | |
| "tase_company_id": 1084, | |
| "magna_corporate_no": "520044322", | |
| "delek_real_estate_cr": "513645804" | |
| }, | |
| "corporate_profile": { | |
| "controlling_shareholder": "Yitzhak Sharon (Tshuva) (ืืฆืืง ืชืฉืืื)", | |
| "major_holdings": ["NewMed Energy", "Ithaca Energy (UK North Sea)", "Delek Real Estate (Historical)", "Delek Petroleum"], | |
| "industry_sector": "Energy Exploration, Production & Real Estate Assets" | |
| }, | |
| "dividend_distributions": [ | |
| { | |
| "action_id": "DIV-DLRE-2007-01", | |
| "entity": "Delek Real Estate Ltd.", | |
| "board_approval_date": "2007-03-28", | |
| "declaration_date": "2007-04-10", | |
| "ex_date": "2007-04-15", | |
| "record_date": "2007-04-17", | |
| "payment_date": "2007-04-30", | |
| "dividend_amount_nis_m": 220.0, | |
| "dividend_per_share_nis": 6.80, | |
| "accounting_surplus_nis_m": 850.0, | |
| "retained_earnings_nis_m": 850.0, | |
| "working_capital_nis_m": -980.0, | |
| "total_assets_nis_m": 18400.0, | |
| "total_liabilities_nis_m": 16750.0, | |
| "bv_equity_nis_m": 1650.0, | |
| "ebit_nis_m": 610.0, | |
| "stock_price_pre_nis": 68.50, | |
| "pre_dividend_volatility": 0.31, | |
| "post_dividend_volatility": 0.43, | |
| "risk_free_rate": 0.048, | |
| "distribution_basis": "IFRS Fair Value Revaluation Surpluses (Non-cash property revaluation)", | |
| "solvency_test_outcome": "Failed Economic Solvency (Altman Z'' = 0.089 < 1.10 Distress Threshold)", | |
| "executive_option_adjustment": { | |
| "pool_title": "Delek Real Estate Senior Management Option Pool 2007", | |
| "options_count": 2000000, | |
| "original_strike_nis": 55.00, | |
| "adjusted_strike_nis": 48.20, | |
| "adjustment_rule": "Full strike reduction K -> K - D (Dividend Protection)", | |
| "wealth_transfer_nis_m": 13.06 | |
| } | |
| }, | |
| { | |
| "action_id": "DIV-DLRE-2008-01", | |
| "entity": "Delek Real Estate Ltd.", | |
| "board_approval_date": "2008-03-30", | |
| "declaration_date": "2008-04-15", | |
| "ex_date": "2008-04-20", | |
| "record_date": "2008-04-22", | |
| "payment_date": "2008-05-04", | |
| "dividend_amount_nis_m": 180.0, | |
| "dividend_per_share_nis": 4.50, | |
| "accounting_surplus_nis_m": 420.0, | |
| "retained_earnings_nis_m": 420.0, | |
| "working_capital_nis_m": -1850.0, | |
| "total_assets_nis_m": 17200.0, | |
| "total_liabilities_nis_m": 16480.0, | |
| "bv_equity_nis_m": 720.0, | |
| "ebit_nis_m": 140.0, | |
| "stock_price_pre_nis": 32.00, | |
| "pre_dividend_volatility": 0.46, | |
| "post_dividend_volatility": 0.65, | |
| "risk_free_rate": 0.042, | |
| "distribution_basis": "Accounting Surplus despite severe cash burn and negative operating cash flow", | |
| "solvency_test_outcome": "Failed Economic Solvency (Altman Z'' = -0.655 < 1.10 Deep Distress)", | |
| "executive_option_adjustment": { | |
| "pool_title": "Delek Real Estate Senior Management Option Pool 2007", | |
| "options_count": 2000000, | |
| "original_strike_nis": 48.20, | |
| "adjusted_strike_nis": 43.70, | |
| "adjustment_rule": "Full strike reduction K -> K - D", | |
| "wealth_transfer_nis_m": 10.72 | |
| } | |
| } | |
| ], | |
| "periodic_financial_reports": [ | |
| { | |
| "period": "2007-FY", | |
| "reporting_standard": "IFRS", | |
| "total_assets_nis_m": 18400.0, | |
| "total_liabilities_nis_m": 16750.0, | |
| "equity_nis_m": 1650.0, | |
| "working_capital_nis_m": -980.0, | |
| "ebit_nis_m": 610.0, | |
| "retained_earnings_nis_m": 850.0, | |
| "leverage_ratio_d_e": 10.15, | |
| "notes": "Fair value gains on UK Roadside (RoadChef) and parking garages accounted for >70% of reported EBIT." | |
| }, | |
| { | |
| "period": "2008-FY", | |
| "reporting_standard": "IFRS", | |
| "total_assets_nis_m": 17200.0, | |
| "total_liabilities_nis_m": 16480.0, | |
| "equity_nis_m": 720.0, | |
| "working_capital_nis_m": -1850.0, | |
| "ebit_nis_m": 140.0, | |
| "retained_earnings_nis_m": 420.0, | |
| "leverage_ratio_d_e": 22.89, | |
| "notes": "Substantial impairment losses, freeze in commercial real estate debt markets, liquidity shortfall." | |
| } | |
| ], | |
| "corporate_restructurings_and_bondholder_notices": [ | |
| { | |
| "event": "2012 Delek Real Estate Comprehensive Debt Settlement", | |
| "court_approval_date": "2012-09-16", | |
| "district_court": "Tel Aviv-Jaffa District Court (Hon. Judge Eitan Orenstin)", | |
| "settlement_terms": { | |
| "total_bond_debt_nis_m": 2150.0, | |
| "debt_haircut_percentage": 0.65, | |
| "controlling_shareholder_injection_nis_m": 500.0, | |
| "equity_conversion_rate": "Bondholders received equity in newly structured holding vehicle" | |
| }, | |
| "legal_classification": "Insolvency & Rehabilitation under Section 350 of the Israeli Companies Law, 1999" | |
| } | |
| ] | |
| } | |
| def get_africa_israel_ir_feed() -> Dict[str, Any]: | |
| """Returns verified IR disclosures, corporate actions, and financial reports for Africa Israel Investments Ltd.""" | |
| return { | |
| "entity": "Africa Israel Investments Ltd. (ืืคืจืืงื ืืฉืจืื ืืืฉืงืขืืช ืืข\"ื)", | |
| "corporate_ids": { | |
| "tase_company_id": 800, | |
| "magna_corporate_no": "520026618", | |
| "ticker": "AFIL" | |
| }, | |
| "corporate_profile": { | |
| "controlling_shareholder": "Lev Leviev (Historical) (ืื ืืืืื)", | |
| "major_holdings": ["AFI Development (Russia)", "AFI USA (Times Square Building / Clock Tower)", "Danya Cebus", "Africa Israel Residences"], | |
| "industry_sector": "International Real Estate Development, Infrastructure & Construction" | |
| }, | |
| "dividend_distributions": [ | |
| { | |
| "action_id": "DIV-AFIL-2007-01", | |
| "entity": "Africa Israel Investments Ltd.", | |
| "board_approval_date": "2007-06-15", | |
| "declaration_date": "2007-06-30", | |
| "ex_date": "2007-07-08", | |
| "record_date": "2007-07-10", | |
| "payment_date": "2007-07-25", | |
| "dividend_amount_nis_m": 580.0, | |
| "dividend_per_share_nis": 35.00, | |
| "accounting_surplus_nis_m": 2100.0, | |
| "retained_earnings_nis_m": 2100.0, | |
| "working_capital_nis_m": -1200.0, | |
| "total_assets_nis_m": 24500.0, | |
| "total_liabilities_nis_m": 21400.0, | |
| "bv_equity_nis_m": 3100.0, | |
| "ebit_nis_m": 950.0, | |
| "stock_price_pre_nis": 450.00, | |
| "pre_dividend_volatility": 0.30, | |
| "post_dividend_volatility": 0.41, | |
| "risk_free_rate": 0.050, | |
| "distribution_basis": "Paper revaluation surpluses of Moscow AFI Mall and Manhattan trophy assets", | |
| "solvency_test_outcome": "Failed Economic Solvency (Altman Z'' = 0.371 < 1.10 Distress Threshold)", | |
| "executive_option_adjustment": { | |
| "pool_title": "Senior Leadership Option Pool 2007", | |
| "options_count": 600000, | |
| "original_strike_nis": 380.00, | |
| "adjusted_strike_nis": 345.00, | |
| "adjustment_rule": "Full strike reduction K -> K - D (Dividend Protection)", | |
| "wealth_transfer_nis_m": 26.88 | |
| } | |
| }, | |
| { | |
| "action_id": "DIV-AFIL-2008-01", | |
| "entity": "Africa Israel Investments Ltd.", | |
| "board_approval_date": "2008-03-20", | |
| "declaration_date": "2008-03-31", | |
| "ex_date": "2008-04-06", | |
| "record_date": "2008-04-08", | |
| "payment_date": "2008-04-20", | |
| "dividend_amount_nis_m": 350.0, | |
| "dividend_per_share_nis": 25.00, | |
| "accounting_surplus_nis_m": 980.0, | |
| "retained_earnings_nis_m": 980.0, | |
| "working_capital_nis_m": -2850.0, | |
| "total_assets_nis_m": 22100.0, | |
| "total_liabilities_nis_m": 20650.0, | |
| "bv_equity_nis_m": 1450.0, | |
| "ebit_nis_m": 120.0, | |
| "stock_price_pre_nis": 210.00, | |
| "pre_dividend_volatility": 0.42, | |
| "post_dividend_volatility": 0.59, | |
| "risk_free_rate": 0.040, | |
| "distribution_basis": "Distributable profits test passed technically while liquidity collapsed in Russia and US operations", | |
| "solvency_test_outcome": "Failed Economic Solvency (Altman Z'' = -0.449 < 1.10 Deep Distress)", | |
| "executive_option_adjustment": { | |
| "pool_title": "Senior Leadership Option Pool 2007", | |
| "options_count": 600000, | |
| "original_strike_nis": 345.00, | |
| "adjusted_strike_nis": 320.00, | |
| "adjustment_rule": "Full strike reduction K -> K - D", | |
| "wealth_transfer_nis_m": 19.38 | |
| } | |
| } | |
| ], | |
| "periodic_financial_reports": [ | |
| { | |
| "period": "2007-FY", | |
| "reporting_standard": "IFRS", | |
| "total_assets_nis_m": 24500.0, | |
| "total_liabilities_nis_m": 21400.0, | |
| "equity_nis_m": 3100.0, | |
| "working_capital_nis_m": -1200.0, | |
| "ebit_nis_m": 950.0, | |
| "retained_earnings_nis_m": 2100.0, | |
| "leverage_ratio_d_e": 6.90, | |
| "notes": "Massive capital expenditure commitments in Moscow AFI Mall, New York Clock Tower, and Miami properties." | |
| }, | |
| { | |
| "period": "2008-FY", | |
| "reporting_standard": "IFRS", | |
| "total_assets_nis_m": 22100.0, | |
| "total_liabilities_nis_m": 20650.0, | |
| "equity_nis_m": 1450.0, | |
| "working_capital_nis_m": -2850.0, | |
| "ebit_nis_m": 120.0, | |
| "retained_earnings_nis_m": 980.0, | |
| "leverage_ratio_d_e": 14.24, | |
| "notes": "Global Financial Crisis collapse in Russian Ruble and NYC commercial real estate, triggering liquidity covenants." | |
| } | |
| ], | |
| "corporate_restructurings_and_bondholder_notices": [ | |
| { | |
| "event": "2009-2010 Landmark Africa Israel Debt Arrangement", | |
| "court_approval_date": "2010-05-27", | |
| "district_court": "Tel Aviv-Jaffa District Court (Hon. Judge Varda Alshech)", | |
| "settlement_terms": { | |
| "total_bond_debt_nis_m": 7500.0, | |
| "cash_paydown_nis_m": 550.0, | |
| "new_bond_issuance_nis_m": 4400.0, | |
| "shares_and_subsidiary_equity_transferred_m": 2550.0, | |
| "controlling_owner_personal_injection_nis_m": 750.0 | |
| }, | |
| "legal_classification": "Largest Israeli Corporate Bond Restructuring Under Section 350" | |
| } | |
| ] | |
| } | |
| class MarketFeedAggregator: | |
| """ | |
| Orchestrates queries to MAYA APIs, Google Finance, and Company IR repositories. | |
| Compiles normalized, high-integrity records into maya_market_feed.json. | |
| """ | |
| def __init__(self, output_path: str = "/home/dcor/omerazoulay/nini/maya_market_feed.json"): | |
| self.output_path = output_path | |
| self.maya_client = TASEMayaClient() | |
| self.gf_scraper = GoogleFinanceScraper() | |
| self.ir_retriever = CompanyIRRetriever() | |
| def build_feed(self) -> Dict[str, Any]: | |
| """Queries all data sources and produces the master market feed record.""" | |
| logger.info("Starting TASE MAYA & Google Finance market data ingestion...") | |
| # 1. Live TASE MAYA queries | |
| maya_delek = self.maya_client.get_company_details(1084) | |
| maya_africa = self.maya_client.get_company_details(800) | |
| maya_delek_reports = self.maya_client.get_company_reports(1084) | |
| maya_africa_reports = self.maya_client.get_company_reports(800) | |
| # 2. Google Finance queries | |
| logger.info("Fetching real-time market data from Google Finance...") | |
| gf_delek = self.gf_scraper.fetch_quote("DLEKG", "TLV") | |
| gf_africa = self.gf_scraper.fetch_quote("AFIL", "TLV") | |
| gf_ta35 = self.gf_scraper.fetch_quote("TA35", "INDEXFTSE") | |
| # 3. Company IR and Empirical Accounting Data | |
| logger.info("Retrieving corporate actions, dividend notices, and audited balance sheet reports...") | |
| delek_ir = self.ir_retriever.get_delek_group_ir_feed() | |
| africa_ir = self.ir_retriever.get_africa_israel_ir_feed() | |
| # 4. Master Data Synthesis | |
| feed_data: Dict[str, Any] = { | |
| "metadata": { | |
| "generated_at": datetime.datetime.now(datetime.timezone.utc).isoformat(), | |
| "system": "TASE MAYA / MAGNA API Client & Google Finance Ingestion Pipeline", | |
| "version": "2.5.0-production", | |
| "target_companies": [ | |
| "Delek Group Ltd. / Delek Real Estate Ltd. (ืงืืืฆืช ืืืง / ืืืง ื ืื\"ื)", | |
| "Africa Israel Investments Ltd. (ืืคืจืืงื ืืฉืจืื ืืืฉืงืขืืช)" | |
| ], | |
| "academic_research_context": "Distressed Corporate Dividend Distribution, Executive Option Vega Windfalls & Insolvency Solvency Tests" | |
| }, | |
| "market_summary": { | |
| "benchmark_index": gf_ta35, | |
| "data_sources": [ | |
| "TASE MAYA Official API (api.tase.co.il / mayaapi.tase.co.il)", | |
| "Israel Securities Authority (MAGNA Electronic Filing)", | |
| "Google Finance Real-Time Scraper", | |
| "Audited Historical Financial Statements & District Court Debt Restructuring Protocols" | |
| ] | |
| }, | |
| "companies": { | |
| "Delek_Group_And_Real_Estate": { | |
| "live_maya_details": maya_delek, | |
| "live_maya_reports_feed": maya_delek_reports, | |
| "google_finance_quote": gf_delek, | |
| "ir_and_corporate_actions": delek_ir | |
| }, | |
| "Africa_Israel_Investments": { | |
| "live_maya_details": maya_africa, | |
| "live_maya_reports_feed": maya_africa_reports, | |
| "google_finance_quote": gf_africa, | |
| "ir_and_corporate_actions": africa_ir | |
| } | |
| } | |
| } | |
| # 5. Save to JSON | |
| logger.info("Writing structured feed to %s", self.output_path) | |
| with open(self.output_path, "w", encoding="utf-8") as f: | |
| json.dump(feed_data, f, indent=4, ensure_ascii=False) | |
| logger.info("Feed successfully written (%s bytes).", os.path.getsize(self.output_path)) | |
| return feed_data | |
| def main(): | |
| aggregator = MarketFeedAggregator() | |
| feed = aggregator.build_feed() | |
| print("\n" + "="*80) | |
| print("TASE MAYA & GOOGLE FINANCE DATA FEED SUMMARY") | |
| print("="*80) | |
| print(f"Generated at: {feed['metadata']['generated_at']}") | |
| print(f"Companies Processed: {list(feed['companies'].keys())}") | |
| for comp_key, comp_val in feed["companies"].items(): | |
| ir = comp_val["ir_and_corporate_actions"] | |
| divs = ir.get("dividend_distributions", []) | |
| print(f"\n[+] {ir['entity']}") | |
| print(f" - Corporate No / TASE ID: {ir['corporate_ids']}") | |
| print(f" - Dividend Events Tracked: {len(divs)}") | |
| for d in divs: | |
| print(f" * Date: {d['declaration_date']} | Dividend: {d['dividend_amount_nis_m']} NIS M | Solvency: {d['solvency_test_outcome']}") | |
| print(f" - Restructuring Notices: {len(ir.get('corporate_restructurings_and_bondholder_notices', []))}") | |
| gf = comp_val.get("google_finance_quote", {}) | |
| print(f" - Google Finance Status: {gf.get('status')} | Symbol: {gf.get('symbol')} | Price: {gf.get('current_price')}") | |
| print("\nSaved output to /home/dcor/omerazoulay/nini/maya_market_feed.json\n") | |
| if __name__ == "__main__": | |
| main() | |