Coverage for mindsdb / integrations / handlers / financial_modeling_prep_handler / financial_modeling_handler.py: 0%
30 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1from mindsdb.integrations.libs.api_handler import APIHandler
2from mindsdb.integrations.libs.response import (
3 HandlerStatusResponse as StatusResponse,
4)
5from mindsdb.integrations.handlers.financial_modeling_prep_handler.financial_modeling_tables import HistoricalPriceTable
7from mindsdb.utilities import log
8import requests
10logger = log.getLogger(__name__)
13class FinancialModelingHandler(APIHandler):
15 name = "financial_modeling_prep"
17 def __init__(self, name, connection_data: dict, **kwargs):
18 super().__init__(name)
20 self.api_key = None
21 self.connection_data = connection_data
22 if "api_key" not in connection_data:
23 raise Exception(
24 "FINANCIAL_MODELING engine requires an API key. Retrieve an API key from https://site.financialmodelingprep.com/developer. See financial_modeling_prep_handler/README.MD on how to include API key in query."
25 )
26 self.api_key = connection_data['api_key']
27 self.client = None
28 self.is_connected = False
30 historical_prices = HistoricalPriceTable(self)
31 self._register_table('historical_prices', historical_prices)
33 def connect(self):
34 self.is_connected = True
35 base_url = "https://financialmodelingprep.com/api/v3/historical-price-full/"
36 return base_url
38 def check_connection(self) -> StatusResponse:
39 """ Check connection to the handler
40 Returns:
41 HandlerStatusResponse
42 """
43 base_url = 'https://financialmodelingprep.com/api/v3/search'
44 param = {
45 'query': 'AA',
46 'apikey': self.api_key,
47 'limit': 5
48 }
50 response = requests.get(base_url, param)
51 if response.status_code == 200:
52 return StatusResponse(success=True)
53 else:
54 raise Exception(
55 "API key provided in query is not valid. Retrieve a valid API key from https://site.financialmodelingprep.com/developer. See financial_modeling_prep_handler/README.MD on how to include API key in query."
56 )