Skip to content
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

[Feature]try to add fmp senate trading data api #6957

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

joshuaBri
Copy link

  1. Why?:

try to add fmp senate trading data api
2. What?:

attempted to integrate the Senate API

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@markqiu
Copy link

markqiu commented Nov 27, 2024

@mmistroni take a look please.

@mmistroni
Copy link
Contributor

mmistroni commented Nov 27, 2024 via email

@deeleeramone deeleeramone self-requested a review November 28, 2024 03:19
@deeleeramone deeleeramone added enhancement Enhancement platform OpenBB Platform v4 PRs for v4 labels Nov 28, 2024
Copy link
Contributor

@deeleeramone deeleeramone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this is great!

I'm asking for a few minor changes, and to please translate all code comments into English.

Thanks very much!

symbol: Optional[str] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("symbol", "")
)
chamber: Literal["house", "senate", "all"] = Field(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a default value here, let's go with "all".


@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we can lose the Type annotations so it's def to_upper(cls, v):

And then we need to allow NoneType, so it becomes, return v.upper() if v else None

api_key = credentials.get("fmp_api_key") if credentials else ""

async def get_one(url):
# 指定要移除的键
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a docstring here instead of a comment. Something like, """Get data for one URL.""" is sufficient.

async def get_one(url):
# 指定要移除的键
keys_to_remove = [
"comment",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"comment" might be worth keeping here, and we can probably remove "firstName", "lastName" because they are redundant copies of "representative_name".

Screenshot 2024-11-27 at 7 45 09 PM

query: FMPGovernmentTradesQueryParams, data: List[Dict], **kwargs: Any
) -> List[FMPGovernmentTradesData]:
"""Return the transformed data."""
return [FMPGovernmentTradesData(**d) for d in data]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage, we should sort the data by date because the gather process will be appending as they come.

There's also some empty strings being passed in a few fields. None is preferred for Optional[str] because evaluating for None is more consistent than checking truthiness. For example, it's not uncommon to receive "''", which would pass truthiness.

Example of empty strings, "owner="

FMPGovernmentTradesData(symbol=AMZN, date=2024-11-22, transaction_date=2024-11-20, representative=Marjorie Taylor Greene, link=https://disclosures-clerk.house.gov/public_disc/ptr-pdfs/2024/20026257.pdf, owner=, asset_type=None, asset_description=Amazon.com Inc, type=Purchase, amount=$1,001 - $15,000, comment=None)

params limit only functions when there is no parameter symbol
"""
params = {
"chamber": "all",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we will be capturing the requests. If we can minimize the amount of data received in the HTTP request, this will help reduce the overall footprint of the testing suite. A limit of 1 should be adequate as the purpose for these tests is to check the fetching mechanism and the typing.

Capturing the test cassettes is rather peculiar, so don't worry about that. I'll deal with that, you've done great.

Copy link
Author

@joshuaBri joshuaBri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deeleeramone Thanks for your correction, I alreadey improved my codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement platform OpenBB Platform v4 PRs for v4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants