Open windowshopr opened 2 years ago
hey @windowshopr, you may want to read up a bit more about promises and async functions, they're super useful. I'm not so familiar with Vue (or trading-vue-js), but assuming they support async functions, I'd suggest to:
export default {
name: 'app',
components: { TradingVue },
// make this an async function
async data() {
// move the retrieve code here, i.e.
const query = 'SPY';
const queryOptions = { period1: '2021-01-01', /* ... */ };
const result = await yahooFinance.historical(query, queryOptions);
console.log(result)
// asuming the above works, you could probably just
return result.map(row => ([ row.date.getTime(), row.open, row.high, row.low, row.close, row.volume ]);
}
}
I made some assumptions here about vue, I don't use vue, so can't be sure this will work or is the recommended way to use async functions in vue.
Will this be run server side or client side? Using yahoo-finance in a web browser is possible but very complicated and we can't help with that.
Bug Report
Describe the bug
Trying to use this API on a VUE.JS page, and getting the error
Module parse failed: Cannot use keyword 'await' outside an async function
Minimal Reproduction
My Trading.vue code looks like this:
I plan on replacing the dummy data with the results I get back from the API.
Environment
Browser or Node: Node version (if applicable): v14.17.0 Npm version: npm@8.1.4 Browser verion (if applicable): Latest Chrome Library version (e.g.
1.10.1
): LatestAdditional Context
I tried wrapping the call in an async function that looked like this:
const result = (async () => {await yahooFinance.historical(query, queryOptions)});
...but the result that was logged was just a promise. I'm likely not using this correctly as I'm a bit of a newbie to Vue, but would like to figure it out. Thanks!