67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
|
|
import sys
|
|
import os
|
|
import logging
|
|
import json
|
|
from datetime import datetime, timedelta
|
|
|
|
# Add app to path
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), 'app'))
|
|
|
|
from app.clients.bloomberg_client import BloombergClient
|
|
|
|
# Config logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
def test_series():
|
|
print("Initializing Client...")
|
|
client = BloombergClient()
|
|
|
|
# Simulate the logic in fetch_company for HK
|
|
symbol = "00631"
|
|
market = "HK"
|
|
|
|
# 1. Ticker Logic
|
|
mapped_market = "CH" if market == "CN" else market
|
|
company_code = f"{symbol} {mapped_market} Equity" # "00631 HK Equity"
|
|
|
|
query_ticker = company_code
|
|
if market == "HK" or (len(company_code.split()) > 1 and company_code.split()[1] == "HK"):
|
|
parts = company_code.split()
|
|
ticker_part = parts[0]
|
|
if ticker_part.isdigit():
|
|
short_ticker = str(int(ticker_part))
|
|
query_ticker = f"{short_ticker} {' '.join(parts[1:])}" # "631 HK Equity"
|
|
|
|
print(f"Company Code (Storage): {company_code}")
|
|
print(f"Query Ticker (Bloomberg): {query_ticker}")
|
|
|
|
currency = "HKD"
|
|
|
|
# 2. Test Currency Data Fetch (Revenue)
|
|
print("\nfetching Currency Data (Series)...")
|
|
curr_indicators = {
|
|
"Revenue": "SALES_REV_TURN"
|
|
}
|
|
|
|
try:
|
|
# Call the internal method directly
|
|
data = client._fetch_series_remote(
|
|
company_code=company_code,
|
|
currency=currency,
|
|
config_dict=curr_indicators,
|
|
result_type="currency",
|
|
query_ticker=query_ticker
|
|
)
|
|
print("--- Result (First 5 items) ---")
|
|
print(json.dumps(data[:5], indent=2, ensure_ascii=False))
|
|
print(f"Total items: {len(data)}")
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_series()
|