Closed pontussalenbo closed 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)
})
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?
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.
Closing as inactive.
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