71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
|
|
import sys
|
|
import os
|
|
import time
|
|
import logging
|
|
|
|
# Ensure we can import from backend
|
|
sys.path.append(os.path.join(os.getcwd(), 'backend'))
|
|
|
|
# Setup logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
from app.clients.bloomberg_client import BloombergClient
|
|
|
|
def test_bdh_currency():
|
|
print("Initializing BloombergClient...")
|
|
client = BloombergClient()
|
|
|
|
ticker = "6301 JP Equity"
|
|
|
|
code = """
|
|
import sys
|
|
import datetime
|
|
try:
|
|
if 'bquery' not in globals():
|
|
import bquery
|
|
except ImportError:
|
|
pass
|
|
|
|
ticker = "{ticker}"
|
|
fields = ["CUR_MKT_CAP", "PX_LAST"]
|
|
|
|
print(f"--- BDH Currency Test for {{ticker}} ---")
|
|
|
|
def get_bdh_val(curr, desc):
|
|
try:
|
|
# BDH request for last 5 days to ensure we hit a trading day
|
|
end_date = datetime.datetime.now().strftime('%Y%m%d')
|
|
start_date = (datetime.datetime.now() - datetime.timedelta(days=10)).strftime('%Y%m%d')
|
|
|
|
# Pass currency in options
|
|
df = bquery.bdh([ticker], fields, start_date=start_date, end_date=end_date, options={{'currency': curr}})
|
|
|
|
if not df.empty:
|
|
print(f"--- {{desc}} (Currency: {{curr}}) ---")
|
|
# Get last row
|
|
last_row = df.iloc[-1]
|
|
for col in df.columns:
|
|
print(f" {{col}}: {{last_row[col]}}")
|
|
else:
|
|
print(f"{{desc}} Empty")
|
|
except Exception as e:
|
|
print(f"{{desc}} Error: {{e}}")
|
|
|
|
# 1. JPY
|
|
get_bdh_val('JPY', "BDH_JPY")
|
|
|
|
# 2. USD
|
|
get_bdh_val('USD', "BDH_USD")
|
|
|
|
"""
|
|
formatted_code = code.format(ticker=ticker)
|
|
|
|
print(f"Executing remote logic for {ticker}...")
|
|
output = client.execute_remote_code(formatted_code)
|
|
print("Remote Output:")
|
|
print(output)
|
|
|
|
if __name__ == "__main__":
|
|
test_bdh_currency()
|