You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5 KiB
Python

"""
Test if yfinance_plus fallback is working
"""
import yfinance_plus as yf
import requests
def test_yfinance_plus_directly():
"""Test yfinance_plus directly"""
print("=== Testing yfinance_plus directly ===")
try:
stock = yf.Ticker("AAPL")
info = stock.info
print(f"Company: {info.get('longName', 'N/A')}")
print(f"Shares Outstanding: {info.get('sharesOutstanding', 0):,.0f}")
quarterly_income = stock.quarterly_income_stmt
print(f"Quarterly Income Statement shape: {quarterly_income.shape}")
if not quarterly_income.empty:
latest_quarter = quarterly_income.columns[0]
print(f"Latest quarter: {latest_quarter}")
revenue = quarterly_income.loc['Total Revenue', latest_quarter] if 'Total Revenue' in quarterly_income.index else None
print(f"Revenue: ${revenue:,.0f}")
return True
except Exception as e:
print(f"Error: {e}")
return False
def test_api_manually():
"""Test API to see what's returned"""
print("\n=== Testing API manually ===")
response = requests.post(
"http://localhost:18001/api/v1/financial/data",
json={
"ticker": "AAPL",
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"period_type": "all",
"include_metrics": True,
"force_refresh": True # Force refresh to trigger data fetching
}
)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Company: {data['company']['name']}")
print(f"Financial data count: {len(data['financial_data'])}")
if data['financial_data']:
latest = data['financial_data'][-1]
print(f"Latest period: {latest['period_date']}")
print(f"Revenue: ${latest.get('revenue', 0):,.0f}")
print(f"Shares Outstanding: {latest.get('shares_outstanding', 0):,.0f}")
print(f"Data Source: {latest.get('data_source', 'Unknown')}")
print(f"Is Estimated: {latest.get('is_estimated', 'Unknown')}")
else:
print(f"Error: {response.text}")
if __name__ == "__main__":
# Test yfinance_plus directly first
yf_works = test_yfinance_plus_directly()
if yf_works:
test_api_manually()
else:
print("yfinance_plus is not working properly")