95 lines
2.8 KiB
Python
95 lines
2.8 KiB
Python
|
|
import asyncio
|
|
from app.clients.bloomberg_client import BloombergClient, CURRENCY_CONFIG
|
|
|
|
async def run():
|
|
client = BloombergClient()
|
|
company = "2503 JP Equity"
|
|
|
|
# Simulate fetch of currency data (which includes Revenue)
|
|
# CURRENCY_CONFIG key "Revenue" is "SALES_REV_TURN"
|
|
|
|
print(f"Debugging Revenue Dates for {company} (CNY)...")
|
|
|
|
# We'll use the exact simulating logic of _fetch_series_remote but print the dates
|
|
|
|
config = {"Revenue": CURRENCY_CONFIG["Revenue"]}
|
|
# Force CNY
|
|
currency = "CNY"
|
|
|
|
# Generate the code that _fetch_series_remote generates
|
|
# We need to replicate the remote code construction roughly or call execute_remote_code
|
|
|
|
import json
|
|
from datetime import datetime
|
|
|
|
STOCKCARD_CONFIG = { "period": 10 }
|
|
period_years = STOCKCARD_CONFIG['period']
|
|
start_year = datetime.now().year - period_years
|
|
start_date = f"{start_year}0101"
|
|
end_date = datetime.now().strftime('%Y%m%d')
|
|
|
|
bdh_options = {
|
|
'periodicitySelection': 'YEARLY',
|
|
'currency': currency,
|
|
'nonTradingDayFillOption': 'ALL_CALENDAR_DAYS',
|
|
'nonTradingDayFillMethod': 'PREVIOUS_VALUE'
|
|
}
|
|
|
|
config_json = json.dumps(config)
|
|
bdh_opts_json = json.dumps(bdh_options)
|
|
|
|
remote_code = f"""
|
|
def debug_series():
|
|
company = "{company}"
|
|
curr = "{currency}"
|
|
config = {config_json}
|
|
|
|
mnemonic_map = {{v.upper(): k for k, v in config.items()}}
|
|
fields = list(mnemonic_map.keys())
|
|
|
|
try:
|
|
df = bquery.bdh(
|
|
[company],
|
|
fields,
|
|
start_date='{start_date}',
|
|
end_date='{end_date}',
|
|
options={bdh_opts_json}
|
|
)
|
|
|
|
print(f"--- Raw Revenue Data (CNY) ---")
|
|
if not df.empty:
|
|
print(df)
|
|
|
|
revenue_dates = []
|
|
for _, row in df.iterrows():
|
|
# Extract date
|
|
date_val = None
|
|
if 'date' in df.columns: date_val = row['date']
|
|
elif 'DATE' in df.columns: date_val = row['DATE']
|
|
|
|
if date_val:
|
|
d_str = str(date_val)[:10]
|
|
# Check for value
|
|
val = None
|
|
if fields[0] in row: val = row[fields[0]]
|
|
elif fields[0] in df.columns: val = row[fields[0]]
|
|
|
|
if val is not None:
|
|
revenue_dates.append(d_str)
|
|
|
|
print(f"\\nExtracted Revenue Dates: {{sorted(revenue_dates, reverse=True)}}")
|
|
else:
|
|
print("DataFrame is empty.")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {{e}}")
|
|
|
|
debug_series()
|
|
"""
|
|
result = client.execute_remote_code(remote_code)
|
|
print(result)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(run())
|