62 lines
1.9 KiB
Python
62 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_market_cap():
|
|
print("Initializing Client...")
|
|
client = BloombergClient()
|
|
|
|
# Target: 6301 JP Equity (Komatsu Ltd)
|
|
company_code = "6301 JP Equity"
|
|
|
|
# Dates to fetch (last few years)
|
|
dates = ["2023-03-31", "2024-03-31"] # Komatsu fiscal year end is usually March 31
|
|
|
|
# 1. Fetch in JPY (Local)
|
|
print("\nfetching Market Cap in JPY...")
|
|
try:
|
|
data_jpy = client._fetch_price_by_dates_remote(
|
|
company_code=company_code,
|
|
currency="JPY",
|
|
dates=dates,
|
|
query_ticker=company_code
|
|
)
|
|
print("--- Result JPY ---")
|
|
print(json.dumps(data_jpy, indent=2, ensure_ascii=False))
|
|
except Exception as e:
|
|
print(f"Error JPY: {e}")
|
|
|
|
# 2. Fetch in CNY (Converted) - Using Series Remote (Fallback Path)
|
|
print("\nfetching Market Cap in CNY (Series Remote Fallback)...")
|
|
try:
|
|
from app.clients.bloomberg_client import PRICE_CONFIG
|
|
|
|
# We need to simulate the fallback call:
|
|
# price_data = self._fetch_series_remote(company_code, currency, PRICE_CONFIG, "price", query_ticker=query_ticker)
|
|
|
|
data_cny = client._fetch_series_remote(
|
|
company_code=company_code,
|
|
currency="CNY",
|
|
config_dict=PRICE_CONFIG,
|
|
result_type="price",
|
|
query_ticker=company_code
|
|
)
|
|
print("--- Result CNY (Series) ---")
|
|
print(json.dumps(data_cny[:5], indent=2, ensure_ascii=False))
|
|
except Exception as e:
|
|
print(f"Error CNY: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_market_cap()
|