Qluxzz / avanza

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

404 Client Error: get_stock_info() #73

Closed AmirEghbali closed 1 year ago

AmirEghbali commented 1 year ago

Cannot retrieve price information etc.

404 Client Error: Not Found for url: https://www.avanza.se/_mobile/market/stock/'WHATERVER_ID'

tux2000 commented 1 year ago

probably related to #70

AmirEghbali commented 1 year ago

Or maybe related to #68 since I have observed similar changes but I could not get it work. Other than websocket, is there any other way to get price (and more detailed relevant) information about a stock?

Alexey-Klechikov commented 1 year ago

Hej all,

I made an extension in my code to this Avanza API to use some other endpoints (_api instead of _mobile). The responses are different but sometimes contain way more helpful info.

Stock info price could be retrieved using https://www.avanza.se/_api/market-guide/{instrument_type}/{instrument_it} And more detailed stock info lays under https://www.avanza.se/_api/market-guide/{instrument_type}/{instrument_it} /details

Check this for example - https://www.avanza.se/_api/market-guide/stock/5564/details

AmirEghbali commented 1 year ago

Hi, have you observed that the prices have a lag of ca 15-20 minutes? Also before we could get the sellPrice and buyPrice which we do not now.

Alexey-Klechikov commented 1 year ago

I did not observe that. I have a script that fetches the chart data once per minute and verifies that the latest complete data point is no older than 2 minutes (I worked with OMX index and certificates) - so far that checkup gave me no log of massively outdated chart data

The endpoint that I fetch OMX data from is /_api/price-chart/stock/{order_book_id} (it contains Volume for OMX index, compared to the endpoint in the repo where this info is missing)

AmirEghbali commented 1 year ago

At least change from

INSTRUMENT_PATH = '/_mobile/market/{}/{}'

to

INSTRUMENT_PATH = '/_api/market-guide/{}/{}'

solves the problem of getting the price for stocks in realtime using get_stock_info().

However, some information (like how many one owns etc) is not available now. Those information can be acquired by accounts_positions() but you will need to extract it for the desired stock_id. Any better solution?

jfla011 commented 1 year ago

Hi, have you observed that the prices have a lag of ca 15-20 minutes? Also before we could get the sellPrice and buyPrice which we do not now.

Hi, you'll see that data delay if you haven't authenticated.

jfla011 commented 1 year ago

However, some information (like how many one owns etc) is not available now. Those information can be acquired by accounts_positions() but you will need to extract it for the desired stock_id. Any better solution?

add /details to the end and you'll get holding info as well

sege commented 1 year ago

In the 5.0.0 version, I'm missing buy/sell/lastPrice in get_stock_info(). Any suggestions on what to use instead?

AmirEghbali commented 1 year ago

INSTRUMENT_PATH = '/_api/market-guide/{}/{}'

Make this change and it should work

tux2000 commented 1 year ago

Using get_instrument_details() directly might work https://github.com/Qluxzz/avanza/blob/d1ada7ccdeaf55becfcd00e5f71a5e69d4ec1fc7/avanza/avanza.py#L948

or you could add a function similar to get_certificate_details() https://github.com/Qluxzz/avanza/blob/d1ada7ccdeaf55becfcd00e5f71a5e69d4ec1fc7/avanza/avanza.py#L763

AmirEghbali commented 1 year ago

Change has been applied in a different PR.