Closed Lejoon closed 3 years ago
While I haven't tried this myself, it looks like you could do so by leveraging this package:
https://www.npmjs.com/package/google-spreadsheet
Untested example below:
const { GoogleSpreadsheet } = require('google-spreadsheet')
const Avanza = require('avanza')
const avanza = new Avanza()
const p1 = avanza.authenticate({
username: process.env.AVANZA_USERNAME,
password: process.env.AVANZA_PASSWORD,
totpSecret: process.env.AVANZA_TOTP_SECRET,
})
const doc = new GoogleSpreadsheet(process.env.GOOGLE_SHEET_ID)
const p2 = await doc.useServiceAccountAuth({
client_email: process.env.GOOGLE_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY,
})
Promise.all([p1, p2]).then(async () => {
await doc.loadInfo()
const sheet = doc.sheetsByIndex[0]
const positions = await avanza.getPositions()
await sheet.addRows(positions.instrumentPositions)
})
That looks awesome! I will check it out. I was hoping the other way around however, to implement your package somehow into Google Apps to be able to define functions spreadsheet that you can use in the cells directly in Google Sheets.
Right, I don't think that's possible unfortunately. Even if you make the HTTP calls manually using Google Sheets, I suspect you'd still run into CORS issues.
Is it possible to implement your implementation into Google Sheets/Google Script to be able to use the functions in spreadsheets?