Hello,
I am fairly new to Javascript, and I am working on developing my first MMM. I am trying to pass the values from an array into an existing stock ticker module. My array is populated dynamically with values from a user’s portfolio, thus the values inside the array are returned from an Async function. Here is the code snippet from the async function:
(async() => {
const getAcctResult = await tdaclient.accounts.getAccount(configGetAcct);
const acctPositions = await lod.get(getAcctResult, 'securitiesAccount.positions');
const acctSymbols = await lod.map(acctPositions, 'instrument.symbol');
acctSymbols.forEach(function(value) {
if (value.length <= 4)
{
tickerArray.push(value);
}
});
I would like to pass the first 5 values from “tickerArray,” and feed them into this existing function in the node_helper.js file:
sendRequest: function (urls) {
var self = this;
var results = {};
async.eachSeries(urls, function(url, done) {
request({ url: url, method: "GET" }, function (error, response, body) {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body);
if(result["Error Message"]) {
console.log("No such symbol!");
} else {
var meta = result["Meta Data"];
if(!meta){
return;
}
var data = result["Time Series (Daily)"];
var compName = meta["2. Symbol"];
var count = 0;
for (var key in data) {
if (!data.hasOwnProperty(key)) {continue;}
var obj = data[key];
if(!results[compName]){
results[compName] = [];
}
results[compName].push(obj);
count++;
if(count == 2) {
break;
}
}
}
}
done();
});
}, function(err) {
if (err) {
throw err;
}
self.sendSocketNotification("STOCK_RESULT", results);
});
},
Effectively, I aim to replace the variable “urls” with tickerArray. The URLs variable is passed in from the config file. By nature this data in the config file is static, and I would like to make it dynamic. This is probably too big of an ask, but if anyone here has a clue on how I can figure this out let me know.
The original module for the stock ticker is here:
https://github.com/hakanmhmd/MMM-Stock
Again, all I really want to do is replace the default array with a dynamic version from the result of my above async function. If this module simply won’t play nice, I can probably eventually just write my own. Thats said, it just seems like it would be a lot easier if I could swap the config data with my array.
Thanks for any help or thoughts you can offer me, and if you need more information let me know.