Qluxzz / avanza

A Python library for the unofficial Avanza API
https://qluxzz.github.io/avanza/
MIT License
85 stars 40 forks source link

get_insights_report method fail when using different time periods #90

Closed BhanuKiranChaluvadi closed 2 months ago

BhanuKiranChaluvadi commented 8 months ago

Setup versions

avanza-api==8.0.0
python==3.11

The following piece of code works

avanza.get_insights_report(
    account_id=account_id,
    time_period=TimePeriod.ONE_WEEK
)

But When used with other time_periods likeTimePeriod.ONE_MONTH, TimePeriod.THREE_MONTHS , the request fails.

insights_report = avanza.get_insights_report(
    account_id=account_id,
    time_period=TimePeriod.ONE_MONTH
)

Error log

Traceback (most recent call last):
  File "/workspaces/avanza/src/example_avanza.py", line 27, in <module>
    insights_report = avanza.get_insights_report(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vscode/.local/lib/python3.11/site-packages/avanza/avanza.py", line 1483, in get_insights_report
    return self.__call(
           ^^^^^^^^^^^^
  File "/home/vscode/.local/lib/python3.11/site-packages/avanza/avanza.py", line 139, in __call
    response.raise_for_status()
  File "/home/vscode/.local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.avanza.se/_api/insights-development/?timePeriod=ONE_MONTH&accountIds=1234567
Qluxzz commented 2 months ago

Validated which time periods work with the endpoint and created its own enum with only the valid values. Fixed in v11.0.0