custom-components / sensor.avanza_stock

Custom component to get stock data from Avanza for Home Assistant
MIT License
46 stars 10 forks source link

api gives error 400 #145

Closed eddysteurs closed 1 year ago

eddysteurs commented 1 year ago

since this morning the avanza responds with : "2022-12-02 11:02:39.075 WARNING (MainThread) [pyavanza] Response Error 400: Bad Request" and results are incorrect Some quotes are updating but I have the impression something is not working with non euro values (usd, nok,dkk,..)

claha commented 1 year ago

I think I had some problems this morning too but seems to be resolved now? Perhaps they made some maintenance

eddysteurs commented 1 year ago

I think I had some problems this morning too but seems to be resolved now? Perhaps they made some maintenance

no I have something different it is still going on, quotes are updating but it does no longer recalculate to EUR so the attribute 'totalValue' is in original measurement

claha commented 1 year ago

Seems like I would need to bump to a never version of pyavanza (https://github.com/claha/pyavanza). The current version uses the stock endpoint to get funds, index, currency etc and that does not seem to work anymore. I've been thinking of trying to integrate this directly into homeassistant, so perhaps that time has come now...

hajo62 commented 1 year ago

I'm looking for IBM stock prices (id: 4175) and some days ago the value provided had switched from EUR to the USD value.

      - id: 4175
        name: IBM 
        conversion_currency: 18987
        invert_conversion_currency: true
        currency: €

Another flavor of the same problem?

eddysteurs commented 1 year ago

that is indeed how I noticed it because I have a lot in USD but also in NOK (10x Euro), I temporary solved it by using yahoo finance platform to get currency prices and divide my stock prices with the correct currency price

hajo62 commented 1 year ago

Although it is a side topic: How have you solved that? With an additional template sensor?

eddysteurs commented 1 year ago

Although it is a side topic: How have you solved that? With an additional template sensor? (Yahoo finance is also a HACS integration) yahoo yahoofinance: symbols:

  • EURUSD=X
  • EURCHF=X
  • EURDKK=X
  • EURGBP=X
  • EURNOK=X sensor: and then I use total usd stocks * EURUSD-x state
  • platform: template sensors: totaal_fisher_value: friendly_name: "totaal fisher waarde" unit_of_measurement: '€' icon_template: mdi:currency-eur value_template: "{{ states('sensor.totaal_fisher_value_eur')|float(default=0) | round(2)
  • (states('sensor.totaal_fisher_value_dkk')|float(default=0) | round(2) / states ('sensor.yahoofinance_eurdkk_x') |float(default=0))
  • (states('sensor.totaal_fisher_value_nok')|float(default=0) | round(2) / states ('sensor.yahoofinance_eurnok_x') |float(default=0))
  • (states('sensor.totaal_fisher_value_usd')|float(default=0) | round(2) / states ('sensor.yahoofinance_eurusd_x') |float(default=0)) }}"
eddysteurs commented 1 year ago

since this morning it got worse; error is now: 2022-12-08 10:28:59.079 WARNING (MainThread) [pyavanza] Response Error 404: Not Found

and all stock are now value 0 (zero)

(first believed to be linked to ha upgrade to 2012-12 but after rollback to 2012-11 error is still 404)

Question: when do you foresee to have the new method available?

claha commented 1 year ago

So either the api completely changed or it has been removed. I currently don't have time to look into it.

Anrolosia commented 1 year ago

Hey @claha , could you try to replace /_mobile/market by /_api/market-guide here https://github.com/claha/pyavanza/blob/8cd55f5814663d63f7bd7485a247f88db0bd71c7/pyavanza/const.py#L4 ? I looked at the network tab on the avanza website, and the API still exists (example here: https://www.avanza.se/_api/market-guide/stock/238449) Let me know if it helps

hajo62 commented 1 year ago

I currently don't have time to look into it.

There is no fix to be expected within the next days/a week? If so - which is okay for me - pls. state this; I would move my config to yahoo...

claha commented 1 year ago

Just released a new version that uses the new api. Unfourtenaly the json it returns is not as flat as for the previous api and thus the monitored_conditoins will not work, I have only modified so that the state and currency is correct. Pull requests to fix this is welcome, my plan otherwise is to create a native integration in home-assistant if I ever find the time....

Anrolosia commented 1 year ago

I'll try to take a look this weekend to submit a pull request asap. Thanks @claha and sorry it wasn't enough to fix the issue :(

claha commented 1 year ago

Any help is appriciated 🙂 the trickiest part will be to stay backwards compatible with the old monitored conditions... the biggest issue is probably that my python skills have evolved quite a bit since I wrote this that I just want to delete all of it and start over 😆

eddysteurs commented 1 year ago

Just released a new version that uses the new api. Unfourtenaly the json it returns is not as flat as for the previous api and thus the monitored_conditoins will not work, I have only modified so that the state and currency is correct. Pull requests to fix this is welcome, my plan otherwise is to create a native integration in home-assistant if I ever find the time....

thanks for this intermediate fix, it solves at least the basic issue, new version is now not so urgent, but still very welcome

claha commented 1 year ago

Just released v1.1.0 that uses the new api. State and the change/changePercent attributes should at least work now :slight_smile:

Please let me know if you find issues!