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

Fix malformed query filter params #389

Merged
merged 1 commit into from
Feb 23, 2023
Merged

Conversation

justinpolygon
Copy link
Contributor

@justinpolygon justinpolygon commented Feb 23, 2023

There are two bugs #382 and #388 that have reported query filter extensions ("lt", "lte", "gt", "gte", "any_of") are not working as expected. Thanks to the debug work of jakekdodd it was easy to track down the source of the bug.

Examples of the malformed params being passed to the API before the fix:

  • expiration.date_gte
  • strike.price_gte

Examples of what these should look like:

  • expiration_date.gte
  • strike_price.gte

Example 1 - code to test (these should both get you the same result):

from polygon import RESTClient
client = RESTClient()

foo = client.list_options_contracts(underlying_ticker='HCP', expiration_date_gte='2024-03-16', contract_type='call', strike_price_gte=20)

for p in foo:
    print(p)

bar = client.list_options_contracts(
    underlying_ticker="HCP",
    contract_type="call",
    params={
        "expiration_date.gte": "2024-03-16",
        "strike_price.gte": 20,
    },
)

for p in bar:
    print(p)

Example 2 - code to test (these should both get you the same result):

from polygon import RESTClient
import datetime
client = RESTClient()

foo = client.vx.list_stock_financials(ticker="AAPL", timeframe='annual', period_of_report_date_gte=str(datetime.date(2017, 1, 1)), period_of_report_date_lt=str(datetime.date(2021, 1, 1)))

for report in foo:
    print(f"{report.fiscal_year=}, {report.fiscal_period=}")

bar = client.vx.list_stock_financials(
    ticker="AAPL", 
    timeframe='annual', 
    params={
        "period_of_report_date.gte": str(datetime.date(2017, 1, 1)),
        "period_of_report_date.lt": str(datetime.date(2021, 1, 1)),
    },
)

for report in bar:
    print(f"{report.fiscal_year=}, {report.fiscal_period=}")

Note: I didn't end up using the suggested code from the bug report, since removesuffix requires python 3.9, and we say the client library should work with 3.8. So, didn't want to break a bunch of existing code.

Credits: Thanks for the great debug work @jakekdodd.

@justinpolygon justinpolygon merged commit c23cf2d into master Feb 23, 2023
@justinpolygon justinpolygon deleted the pr-query-filter-fix branch February 23, 2023 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants