<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Async Functions, Sockets, Arrays, and Figuring this out]]></title><description><![CDATA[<p dir="auto">Hello,<br />
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:</p>
<p dir="auto">(async() =&gt; {<br />
const getAcctResult = await tdaclient.accounts.getAccount(configGetAcct);</p>
<pre><code>const acctPositions = await lod.get(getAcctResult, 'securitiesAccount.positions');
const acctSymbols = await lod.map(acctPositions, 'instrument.symbol');
acctSymbols.forEach(function(value) {
    if (value.length &lt;= 4)
    {
        tickerArray.push(value);
    }
});
</code></pre>
<p dir="auto">I would like to pass the first 5 values from “tickerArray,”  and feed them into this existing function in the node_helper.js file:</p>
<pre><code>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 &amp;&amp; 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);
	});
},
</code></pre>
<p dir="auto">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.</p>
<p dir="auto">The original module for the stock ticker is here:</p>
<p dir="auto"><a href="https://github.com/hakanmhmd/MMM-Stock" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/hakanmhmd/MMM-Stock</a></p>
<p dir="auto">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.</p>
<p dir="auto">Thanks for any help or thoughts you can offer me, and if you need more information let me know.</p>
]]></description><link>https://forum.magicmirror.builders/topic/14814/async-functions-sockets-arrays-and-figuring-this-out</link><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 23:40:55 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/14814.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 21 Mar 2021 04:47:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Async Functions, Sockets, Arrays, and Figuring this out on Wed, 24 Mar 2021 14:50:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jcsindelar" aria-label="Profile: jcsindelar">@<bdi>jcsindelar</bdi></a> if I understand correctly you want to call stockdata from a dynamic and changing range of stocks.<br />
In some modules the array is provided by the config with every call to node_helper, in some modules just at the start.</p>
<p dir="auto">Another option would be to include a notification in the stock ticker module and use that to change the array.<br />
I’m currently working on a successor to MMM-AVStock that also has a ticker.<br />
If you’re interested we could implement your request into the code.<br />
Meaning: your module sends a notification “CHANGE_STOCKS” and my module receives it and acts accordingly.</p>
<pre><code>notificationReceived: function(noti, payload) {
  if (noti === "CHANGE_STOCKS") {
    this.config.symbols = payload
    this.sendSocketNotification("GET_STOCKDATA", payload)
  }
}
</code></pre>
<p dir="auto">However, consider that the actual config will obviously not be safed in case of restart. But I guess your module will do the rest.</p>
]]></description><link>https://forum.magicmirror.builders/post/89825</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/89825</guid><dc:creator><![CDATA[lavolp3]]></dc:creator><pubDate>Wed, 24 Mar 2021 14:50:19 GMT</pubDate></item><item><title><![CDATA[Reply to Async Functions, Sockets, Arrays, and Figuring this out on Sun, 21 Mar 2021 12:46:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jcsindelar" aria-label="Profile: jcsindelar">@<bdi>jcsindelar</bdi></a> doesn’t look too hard. u are just missing the step that builds the url string from the stock symbol.</p>
<p dir="auto">the existing function assumes an array of urls.</p>
<p dir="auto">instead of storing the stock symbol, store the url with the stock symbol. the array doesn’t care.<br />
then after the foreach loop call the existing function, passing tickerArray</p>
<p dir="auto">also the acct symbols to tickerarray is checking the length of the stock symbol not the ticker array</p>
]]></description><link>https://forum.magicmirror.builders/post/89726</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/89726</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sun, 21 Mar 2021 12:46:10 GMT</pubDate></item></channel></rss>