67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
|
|
import sys
|
|
import os
|
|
import pandas as pd
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
# Add backend to path
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from app.fetchers.factory import FetcherFactory
|
|
from app.clients.ifind_hk_client import IFindHKClient
|
|
|
|
# Load .env
|
|
ROOT_DIR = Path(__file__).resolve().parent.parent.parent
|
|
load_dotenv(ROOT_DIR / ".env")
|
|
|
|
def verify_fetcher(market, symbol, source, method_name='get_market_metrics'):
|
|
print(f"\n--- Verifying {market} ({source}) for {symbol} ---")
|
|
try:
|
|
fetcher = FetcherFactory.get_fetcher(market, source)
|
|
print(f"✅ Fetcher instantiated: {type(fetcher).__name__}")
|
|
|
|
if method_name == 'get_market_metrics':
|
|
print(f"Calling {method_name}...")
|
|
data = fetcher.get_market_metrics(symbol)
|
|
print(f"Result: {data}")
|
|
if data and isinstance(data, dict) and data.get('price') != 0:
|
|
print("✅ Data looks valid (Price > 0)")
|
|
else:
|
|
print("⚠️ Data might be empty or zero (Market closed or invalid symbol?)")
|
|
|
|
elif method_name == 'get_income_statement':
|
|
print(f"Calling {method_name}...")
|
|
df = fetcher.get_income_statement(symbol)
|
|
if not df.empty:
|
|
print(f"✅ Got DataFrame with shape: {df.shape}")
|
|
print(df.head(2))
|
|
else:
|
|
print("⚠️ Returned empty DataFrame")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
|
|
def main():
|
|
print("Start Verification...")
|
|
|
|
# 1. HK (iFinD) - Tencent
|
|
verify_fetcher('HK', '0700', 'iFinD', 'get_market_metrics')
|
|
|
|
# 2. JP (iFinD) - Toyota
|
|
verify_fetcher('JP', '7203', 'iFinD', 'get_market_metrics')
|
|
|
|
# 3. US (iFinD) - Apple
|
|
verify_fetcher('US', 'AAPL', 'iFinD', 'get_market_metrics')
|
|
|
|
# 4. VN (iFinD) - VIC? (Vingroup)
|
|
verify_fetcher('VN', 'VIC', 'iFinD', 'get_market_metrics')
|
|
|
|
# 5. Bloomberg - US - AAPL (Skip if no connection, but try)
|
|
# verify_fetcher('US', 'AAPL', 'Bloomberg', 'get_market_metrics') # Enabling for test
|
|
|
|
print("\nVerification Script Completed.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|