Skip to content

widarlein/kavanza

Repository files navigation

Kavanza

A Kotlin port of the Node.js lib wrapping the unofficial Avanza API, https://github.com/fhqvst/avanza. As with the original this is a proof of concept, made to practice Kotlin and not for serious use. You can use it from Java (or any suitable JVM language with good interoperability) with Java interop making it the perfect Java Avanza API.

I am not affiliated with Avanza and the API might change in any way at any time, rendering this library unusable.

V2 Changes

The API has changed a bit and there has been some code changes to accommodate this, but the fixes are not complete and some methods have been deprecated for later consideration and some have been indefinitely deprecated.

In progress

  • getChartData
  • getInstrument
  • getInspirationLists

Permanently gone (or until I get a tip on how to implement it)

  • getOrder (you can still get all orders through getDealsAndOrders)

TOTP Secret

In order to log in to Avanza, you need to enable two-factor authentication and establish a TOTP secret.

Getting a jar

You will need to confirm the TOTP secret later. You can do that with an authenticator app, but I have also included a jar for this purpose. Depending how much you trust me you can use it straight from the repo or inspect the code first and build it yourself.

I trust you with my life savings

Great! Just use the totpcodegen-1.0.jar from the root of this repo.

Fat chance, also I enjoy wearing tin foil hats

Sigh. Code is in totpcodegen

cd totpcodegen
./gradlew build
ls build/libs/totpcodegen-1.0.jar

On the Avanza web page, log in and:

  1. Go to Mina Sidor > Profil > Sajtinställningar > Tvåfaktorsinloggning and click Återaktivera
  2. Click Ja, återaktivera
  3. Click Aktivera
  4. Under Annan app för tvåfaktorsinloggning click Nu har jag laddat ner appen, gå vidare
  5. Enter your password
  6. Click Kan du inte scanna QR-koden? to reveal the TOTP secret, 32 character long base 32 string.
  7. Confirm Secret by generating a TOTP code, perhaps with the totpcodegen-1.0.jar
    • java -jar totpcodegen-1.0.jar <YOUR_TOTP_SECRET_HERE>
  8. Save your secret somewhere secret.

Installation

Gradle/Maven

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.widarlein:kavanza:1.0'
}

Usage

By calling Avanza.connect() with proper arguments, the lib will log you in and return a client for further interactions. Check out all capabilities of the AvanzaClient by checking the docs or reading the code.

import com.github.widarlein.kavanza.Avanza
import com.github.widarlein.kavanza.AvanzaClient
import com.github.widarlein.kavanza.model.*

val avanzaClient: AvanzaClient = Avanza.connect(UserCredentials("<USERNAME>", "<PASSWORD>"), "<TOTP_SECRET>")
val overview = avanzaClient.getOverview()

println("User account overview: $overview")

Docs

You find the dokka docs here, baby https://widarlein.github.io/kavanza/

Known Issues

  • AvanzaClient.getInspirationLists() does not currently work and will cast an exception if you try to use it. The response json contains some polymorphism depending on what type of list is returned and I haven't worked out a good way of handling that yet. The only type actually working is STOCK, but this endpoint can return several different types.
  • AvanzaClient.getInspirationList() has the same problem as above. Only type responses of type STOCK would work, but the only types available to request are different lists with type FUND.
  • Real time data is not yet implemented.

Disclaimer

Use at own risk, I'm not responsible for anything you do with this.

About

Kotlin lib for the unofficial Avanza API

Resources

License

Stars

Watchers

Forks

Packages

No packages published