tools.py•3.25 kB
from typing import List, Dict, Any, Optional
from kap_sdk.kap_client import KapClient
class KAPTools:
def __init__(self):
self.kap_client = KapClient()
async def get_companies(self) -> List[Dict[str, Any]]:
"""Returns a list of all companies."""
try:
return await self.kap_client.get_companies()
except Exception as e:
raise Exception(f"Error while fetching company list: {str(e)}")
async def get_company(self, company_code: str) -> Dict[str, Any]:
"""Returns details of a specific company.
Args:
company_code: Company code (e.g., THYAO)
"""
try:
return await self.kap_client.get_company(company_code)
except Exception as e:
raise Exception(f"Error while fetching company details: {str(e)}")
async def get_company_info(self, company_code: str) -> Dict[str, Any]:
"""Returns detailed information about a company.
Args:
company_code: Company code (e.g., THYAO)
"""
try:
company = await self.kap_client.get_company(company_code)
return await self.kap_client.get_company_info(company)
except Exception as e:
raise Exception(f"Error while fetching detailed company information: {str(e)}")
async def get_financial_report(self, company_code: str, year: str) -> Dict[str, Any]:
"""Returns the financial report of a company.
Args:
company_code: Company code (e.g., THYAO)
year: Report year (e.g., 2023)
"""
try:
company = await self.kap_client.get_company(company_code)
return await self.kap_client.get_financial_report(company, year)
except Exception as e:
raise Exception(f"Error while fetching financial report: {str(e)}")
async def get_indices(self) -> List[Dict[str, Any]]:
"""Returns a list of all indices."""
try:
return await self.kap_client.get_indices()
except Exception as e:
raise Exception(f"Error while fetching index list: {str(e)}")
async def get_announcements_by_company(self, company_code: str) -> List[Dict[str, Any]]:
"""Returns announcements of a specific company.
Args:
company_code: Company code (e.g., THYAO)
"""
try:
company = await self.kap_client.get_company(company_code)
return await self.kap_client.get_announcements(company)
except Exception as e:
raise Exception(f"Error while fetching company announcements: {str(e)}")
async def get_announcements(self) -> List[Dict[str, Any]]:
"""Returns a list of all announcements."""
try:
return await self.kap_client.get_announcements()
except Exception as e:
raise Exception(f"Error while fetching announcement list: {str(e)}")
async def get_sectors(self) -> List[Dict[str, Any]]:
"""Returns a list of all sectors."""
try:
return await self.kap_client.get_sectors()
except Exception as e:
raise Exception(f"Error while fetching sector list: {str(e)}")