Avanza

tests GitHub Workflow Status Read the Docs
package PyPI PyPI - License PyPI - Python Version

Based on https://github.com/fhqvst/avanza

Python wrapper for Unofficial Avanza API

Code is work in progress and is only meant as “proof of concept”

Authentication is done with selenium, which will save cookies in current working directory.

Short example of getting the current buyprice for msft stock:

import avanza

msft = avanza.Ticker(3873)
price = msft.buy_price
print(price)
> 166.48

Short example of displaying graph price of msft stock, using matplotlib:

import avanza
import matplotlib.pyplot as plt

df = avanza.ChartData().get_ticker_chartdata(3873)
df.plot(kind='line', x='timestamp', y='value')
plt.show()

More examples can be found here

Documentation

Security Notice

This python wrapper voids following bandit codes: B108 B301

API Reference

Config

class avanza.Config

Bases: object

Config class for setting and retrieving settings

settings
cookie_path
path to file which should be used when loading/storing cookies
classmethod get(name)

Retrieves the value of setting

Parameters:name (str) – The key which value should be returned
classmethod set(name)

Change settings using dict

Examples

>>> avanza.Config.set({'cookie_path': '/path/to/file'})
Parameters:name (dict) – The new values to set

Ticker

class avanza.Ticker(orderbook_id, **kwargs)

Bases: avanza.base.Base

Request information about stock/certificate/fund/etc

Parameters:
  • orderbook_id (int) – id of ticker
  • instrument (str) – Type of instrument, Defaults to ‘stock’
  • auth (bool) – Set true for additional information, Defaults to False

Note

Additional information if authenticated

buy_price

Grabs buy price of ticker

Returns:float
change

Grabs change price of ticker

Returns:int
change_percent

Grabs change price of ticker in percent

Returns:int
country

Grabs the country of ticker

Returns:str
currency

Grabs currency of ticker

Returns:str
flag_code

Grabs flag code of ticker

Returns:str
highest_price

Grabs highest price of ticker

Returns:float
id

Grabs the id of ticker

Returns:int
info

Grabs full json of ticker call

Returns:dict
isin

Grabs ISIN of ticker

Returns:str
last_price

Grabs last price of ticker

Returns:float
last_price_updated

Grabs last time price was updated

Returns:str – ISO 8601
lowest_price

Grabs lowest price of ticker

Returns:float
marketplace

Grabs marketplace of ticker

Returns:str
name

Grabs full name of ticker

Returns:str
quote_updated

Grabs last time quote was updated

Returns:str – ISO 8601
sell_price

Grabs buy sell of ticker

Returns:float
symbol

Grabs symbol of ticker

Returns:str

News

class avanza.News(index)

Bases: avanza.base.Base

Returns Avanza news

Parameters:index (int) – The amount of news to be returned
info

Grabs full json of returned news

Returns:dict
pretty

Prints the news in a prettier format

Returns:str
results

Grabs the list of results

Returns:list

Collection

avanza.collection.get_account_overview(account_id)

Returns information about accounts watchlists

Parameters:account_id (int) – id of account
Returns:dict

Note

Authentication neccessary

avanza.collection.get_account_summary()

Returns account summary

Returns:dict

Note

Authentication neccessary

avanza.collection.get_accounts()

Returns accounts

Returns:dict

Note

Authentication neccessary

avanza.collection.get_deals_and_orders()

Returns deals, orders and accounts

Returns:dict

Note

Authentication neccessary

avanza.collection.get_feed()

Returns feed from Home

Returns:dict

Note

Authentication neccessary

avanza.collection.get_insight(**kwargs)

Returns accounts

Parameters:time_period (str) – time period
Returns:dict

Note

Authentication neccessary

avanza.collection.get_inspiration_list()

Returns inspiration list

Returns:dict

Note

Authentication neccessary

avanza.collection.get_positions()

Returns information about accounts positions

Returns:dict

Note

Authentication neccessary

avanza.collection.get_transactions(account_id=None)

Returns information about accounts watchlists

Parameters:account_id (int) – id of account
Returns:dict

Note

Authentication neccessary

avanza.collection.get_watchlists()

Returns information about accounts watchlists

Returns:dict

Note

Authentication neccessary

Chartdata

class avanza.chartdata.ChartData

Bases: avanza.base.Base

Grab json chartdata and output as pandas DataFrame

get_distribution_chartdata()

Returns values from account distribution pie chart

Returns:pandas.core.frame.DataFrame – Fallback to dict if pandas is not imported

Note

Authentication necessary

Will “unpack” original drilldown

get_overview_chartdata(time_period='one_month')

Returns chartdata from overview page

Parameters:time_period (str) – time period
Returns:pandas.core.frame.DataFrame – Fallback to dict if pandas is not imported

Note

Authentication necessary

get_ticker_chartdata(orderbook_id, **kwargs)

Returns chartdata from overview page

Parameters:
  • orderbook_id (int) – Id of ticker
  • time_period (str) – time period
  • chart_type (str) –

    The kind of chartdata to retrieve

    • area: Data for typical line chart (default)
    • candlestick: Data for candlestick/ohlc chart
    • ohlc: Produces same result as candlestick
  • chart_resolution (str) – resolution of chart
Returns:

pandas.core.frame.DataFrame – Fallback to dict if pandas is not imported

Note

Authentication necessary

Version

avanza.__version__

Get the current version in string format

Indices and tables