FA3-Datafetch/backend/verify_currency.py
2026-01-12 19:20:18 +08:00

58 lines
1.5 KiB
Python

import sys
import asyncio
from app.clients.bloomberg_client import BloombergClient
async def run():
client = BloombergClient()
company = "2503 JP Equity"
# We want to check 2024-12-31 data for JPY, CNY, USD
currencies = ["JPY", "CNY", "USD"]
print(f"Testing Market Cap for {company} on 2024-12-31 in {currencies}")
remote_code = f"""
def test_currency():
company = "{company}"
currencies = {currencies}
date = "20241231"
results = {{}}
try:
for curr in currencies:
print(f"Fetching for {{curr}}...")
# Use BDH for historical specific date
df = bquery.bdh(
[company],
['CUR_MKT_CAP'],
start_date=date,
end_date=date,
options={{'currency': curr, 'periodicitySelection': 'DAILY', 'nonTradingDayFillOption': 'ALL_CALENDAR_DAYS', 'nonTradingDayFillMethod': 'PREVIOUS_VALUE'}}
)
if not df.empty and 'CUR_MKT_CAP' in df.columns:
val = df['CUR_MKT_CAP'].iloc[0]
results[curr] = val
else:
results[curr] = "No Data"
except Exception as e:
print(f"Error: {{e}}")
import json
print("JSON_START")
print(json.dumps(results))
print("JSON_END")
test_currency()
"""
result = client.execute_remote_code(remote_code)
print("\nCheck Result:")
print(result)
if __name__ == "__main__":
asyncio.run(run())