-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor FinancialDatasetAPI integration and add configuration classes for API setup. #42
base: main
Are you sure you want to change the base?
Refactor FinancialDatasetAPI integration and add configuration classes for API setup. #42
Conversation
…tion classes for API setup.
Awesome |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 👏🏼 Would probably just recommend some typing improvements
**data, | ||
"prices": prices, | ||
"start_date": start_date, | ||
**data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.9+ syntax is preferred, i.e. data | { ... }
, rather than { **data, ... }
from .config import FinancialDatasetAPIConfig | ||
|
||
|
||
class Period(str, Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think you need str
def _get_headers(self) -> Dict[str, str]: | ||
return {"X-API-KEY": self.config.api_key} | ||
|
||
def _handle_response(self, response: requests.Response) -> Dict[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use dict
instead of Dict
. I would add a type alias for dict[str, Any]
in an appropriate file, since it's used so often (arguably too often)
|
||
return df.sort_index() | ||
|
||
def get_financial_metrics( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public methods usually come before private methods
return response.json() | ||
|
||
@staticmethod | ||
def prices_to_df(prices: List[Dict[str, Any]]) -> pd.DataFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use list
instead of List
) | ||
|
||
def get_insider_trades( | ||
self, ticker: str, end_date: Union[str, datetime], limit: int = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of Union
, use str | datetime
This pull request focuses on refactoring the codebase to use a new
FinancialDatasetAPI
class for accessing financial data, replacing individual API functions. The changes involve using this new class, removing the old API functions, and implementing a base API client class for better structure and error handling.Refactoring to use
FinancialDatasetAPI
:src/agents/market_data.py
: Replaced individual API function calls with methods from the newFinancialDatasetAPI
class. Adjusted the import statements accordingly.src/agents/risk_manager.py
,src/agents/technicals.py
,src/backtester.py
: Updated to useFinancialDatasetAPI.prices_to_df
for converting price data to a DataFrame.Removal of old API functions:
src/tools/api.py
: Removed all old API functions such asget_financial_metrics
,search_line_items
,get_insider_trades
,get_market_cap
,get_prices
, andprices_to_df
.Implementation of base API client:
src/tools/api/base.py
: Made an abstract base classBaseAPIClient
to handle common API client functionality such as making requests and handling responses.src/tools/api/config.py
: Added configuration classesBaseAPIConfig
andFinancialDatasetAPIConfig
for managing API configuration.src/tools/api/financial_dataset.py
: Created theFinancialDatasetAPI
class extendingBaseAPIClient
, implementing methods for fetching financial metrics, insider trades, market cap, and price data.