npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

avanza-api-unofficial

v1.1.11

Published

An unofficial API wrapper for Avanza Bank

Downloads

15

Readme

avanza-api-unofficial

CI npm version npm downloads

A Node.js wrapper for the unofficial Avanza API. Created as most of the libraries out there are outdated or not maintained. We will do our best to keep this up to date, but please create issues if you find any bugs or have feature requests on our GitHub page.

⚠️ Disclaimer: This is an unofficial API wrapper and is not affiliated with or endorsed by Avanza Bank AB. The underlying API can be changed or removed at any time without notice. Use at your own risk.

Installation

Install via npm

$ npm install avanza-api-unofficial

Documentation

Refer to API.md for complete API documentation. The documentation is generated from JSDoc comments using jsdoc-to-markdown.

Getting a TOTP Secret

Here are the steps to get your TOTP Secret:

  1. Go to Profil > Inställningar > Sajtinställningar > Inloggning och utloggning > Användarnamn > Tvåfaktorsinloggning and click "Återaktivera". (Only do this step if you have already set up two-factor auth.)
  2. Click "Aktivera" on the next screen.
  3. Select "Annan app för tvåfaktorsinloggning".
  4. Click "Kan du inte scanna QR-koden?" to reveal your TOTP Secret.
  5. Finally, run node -e "console.log(require('avanza-api-unofficial/dist/totp')('PASTE_YOUR_TOTP_SECRET_HERE'))" to generate an initial code.
  6. Done! From now on all you have to do is supply your secret in the authenticate() function as in the example below.

Example

Authenticate and fetch currently held positions:

import Avanza from 'avanza-api-unofficial'
const avanza = new Avanza()

avanza.authenticate({
  username: 'MY_USERNAME',
  password: 'MY_PASSWORD',
  totpSecret: 'MY_TOTP_SECRET'
}).then(async () => {
  const positions = await avanza.getPositions()
  console.log(positions)
})

Authenticate and subscribe to real-time data:

import Avanza from 'avanza-api-unofficial'
const avanza = new Avanza()

avanza.authenticate({
  username: 'USERNAME',
  password: 'PASSWORD',
  totpSecret: 'MY_TOTP_SECRET'
}).then(() => {
  avanza.subscribe(Avanza.QUOTES, '5479', (quote) => {
    console.log('Received quote:', quote)
  })
})

Documentation

Refer to API.md.

Testing

This project contains comprehensive tests for all API methods. Tests are run automatically:

  • Before any commit (via pre-commit hook)
  • During the release process

Running Tests

Tests will run with or without credentials. If you don't provide credentials in a .env file, the API call tests will be skipped, but the path construction tests will still run.

  1. Copy .env.example to .env and fill in your credentials
  2. Run the tests:
# Run all tests
$ npm test

# Run tests with coverage report
$ npm run test:coverage

Test Structure

  • Path Tests: Verify all API endpoint paths are constructed correctly (runs without credentials)
  • API Tests: Verify actual API calls work correctly (requires credentials)
  • No Real Trades: The tests are designed to check functionality without placing any actual orders

Testing in CI/CD

The GitHub Actions workflow runs the path tests automatically without requiring credentials.

API Endpoint Maintenance

This library includes a tool to help detect changes in Avanza's API endpoints, which can change without notice.

Endpoint Crawler

The endpoint crawler logs into Avanza's web interface using Puppeteer and monitors network traffic to detect API endpoints. This helps discover when endpoints have changed (e.g., from /_mobile/ to /_api/ paths).

# Install required dependencies if not already installed
npm install

# Run the endpoint crawler
npm run endpoint-crawler

# Run with comparison against current constants.js
npm run check-endpoints

See ENDPOINT_CRAWLER.md for detailed documentation on using the crawler and keeping the API up to date.

LICENSE

MIT license. See the LICENSE file for details.

RESPONSIBILITIES

The author of this software is not responsible for any indirect damages (foreseeable or unforeseeable), such as, if necessary, loss or alteration of or fraudulent access to data, accidental transmission of viruses or of any other harmful element, loss of profits or opportunities, the cost of replacement goods and services or the attitude and behavior of a third party.