• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
  1. Home
  2. jcsindelar
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
Offline
  • Profile
  • Following 0
  • Followers 0
  • Topics 1
  • Posts 1
  • Groups 0

jcsindelar

@jcsindelar

0
Reputation
1
Profile views
1
Posts
0
Followers
0
Following
Joined Mar 17, 2021, 3:18 AM
Last Online Mar 21, 2021, 4:47 AM

jcsindelar Unfollow Follow

Latest posts made by jcsindelar

  • Async Functions, Sockets, Arrays, and Figuring this out

    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.

    posted in Troubleshooting
    J
    jcsindelar
    Mar 21, 2021, 4:47 AM
Enjoying MagicMirror? Please consider a donation!
MagicMirror created by Michael Teeuw.
Forum managed by Sam, technical setup by Karsten.
This forum is using NodeBB as its core | Contributors
Contact | Privacy Policy