fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

getPositions() #27

Closed pontussalenbo closed 5 years ago

pontussalenbo commented 5 years ago

Hi,

while using the avanza.getPositions() I manage to make it work, though it returns positions [array]. This seems like I don't manage to make it work properly, what am I doing wrong. Can't find any guidance inte the API.md

fhqvst commented 5 years ago

Could you specify exactly what is not working for you? There's a working example in the readme which you can refer to.

import Avanza from 'avanza'
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)
})
pontussalenbo commented 5 years ago

Yes, while using this example I get a JSON response as expected. [ { instrumentType: 'FUND', positions: [Array], totalValue: xxxxx, (censored but it returns a number)..

I don't know if it is correct for it to return a value of [Array], or do I need to make any further input to the code in order to recieve the positions held?

fhqvst commented 5 years ago

The response is grouped by instrument type, so you need to search through the array to find e.g. positions[i].instrumentType === 'STOCK', and then positions[i].positions contains all your positions of that type.

This information can be found in API.md, and you can of course also execute console.log(positions[i]) in your code to see what's in each response.

fhqvst commented 5 years ago

Closing as inactive.