• 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
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Stocks

Scheduled Pinned Locked Moved Utilities
36 Posts 15 Posters 31.7k Views 14 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    alexyak
    last edited by Aug 14, 2016, 12:14 AM

    Here’s a basic scrolling stocks ticker module. You can get it from here:

    https://github.com/alexyak/stocks

    This is how it looks:

    0_1471133603462_Screen Shot 2016-08-13 at 8.09.32 PM.png

    H 1 Reply Last reply Dec 27, 2017, 10:16 PM Reply Quote 0
    • ? Offline
      A Former User
      last edited by Oct 24, 2016, 4:16 PM

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • L Offline
        lb-rezende
        last edited by Nov 29, 2016, 9:45 PM

        Is it possible to check currency rates using this module?

        1 Reply Last reply Reply Quote 0
        • Z Offline
          ZTA0796
          last edited by Dec 14, 2016, 12:19 AM

          Great module! I’m currently modifying it for some visual changes as well as trying to get it to pull yahoo finance data instead of google. The reason for that is that Yahoo also lists commodities (crude oil, corn, etc).

          I’ve gotten what I think is most of it done, but I’m getting an error on the node_helper.js module. I’m relatively new to node, but can someone explain why if I change the URL in the code to a yahoo URL that also spits back a JSON file, that it gives me an “unexpected token u in JSON at position 0”?

          For reference, the yahoo URL is: https://query.yahooapis.com/v1/public/yql?q=select * from csv where url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3DMSFT,AAPL%26f%3Dsl1d1t1c1ohgv%26e%3D.csv' and columns%3D'symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Ccol2'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

          Thanks!

          A 1 Reply Last reply Dec 14, 2016, 1:01 AM Reply Quote 0
          • A Offline
            alexyak @ZTA0796
            last edited by Dec 14, 2016, 1:01 AM

            @ZTA0796 The original code does a hardcoded substring on the result:

            var result = JSON.parse(body.substring(3, body.length));

            You probably don’t need to do that.

            Z 2 Replies Last reply Dec 14, 2016, 1:36 AM Reply Quote 0
            • Z Offline
              ZTA0796 @alexyak
              last edited by Dec 14, 2016, 1:36 AM

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • Z Offline
                ZTA0796 @alexyak
                last edited by Dec 16, 2016, 1:53 AM

                @alexyak Thanks! I have one more question about syntax that I’m having trouble with.

                I can pull the Yahoo JSON into the node_helper file and print it to the terminal without a problem. But when I try to reference it in the “getDom” function, I get nothing. I haven’t changed the code at the start of that function at all. But when it runs “this.result.length”, the length returned is 0.

                I’m not super-familiar with the “this” syntax, but was hoping you or someone else might have an idea of why the JSON you pass would work, but not the JSON that I pass?

                Thanks!

                A 1 Reply Last reply Dec 16, 2016, 2:05 PM Reply Quote 0
                • C Offline
                  chrisfoerg
                  last edited by Dec 16, 2016, 8:54 AM

                  great! would also be good for rss feeds :-)

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    alexyak @ZTA0796
                    last edited by Dec 16, 2016, 2:05 PM

                    @ZTA0796 Could you show your code?

                    Z 1 Reply Last reply Dec 17, 2016, 2:40 PM Reply Quote 0
                    • Z Offline
                      ZTA0796 @alexyak
                      last edited by Dec 17, 2016, 2:40 PM

                      @alexyak Sure…see below.

                      In the node_helper.js:

                      getStocks: function (url) {
                      var self = this;

                        request({ url: url, method: 'GET' }, function (error, response, body) {
                            if (!error && response.statusCode == 200) {
                              
                                var result = JSON.parse(body);
                                console.log(result.query.results.row);  //prints the JSON as expected to the terminal
                                self.sendSocketNotification('STOCKS_RESULT', result);
                            }
                        });
                      

                      },

                      //Subclass socketNotificationReceived received.
                      socketNotificationReceived: function(notification, payload) {
                      if (notification === ‘GET_STOCKS’) {
                      this.getStocks(payload);
                      }
                      }

                      });

                      in stocks.js:

                      getDom: function() {
                      
                          var wrapper = document.createElement("table");
                          wrapper.className = 'normal regular small';
                          
                          var count = 0;
                      
                          var _this = this;
                      
                      	console.log("in the DOM function");
                      	console.log("result is " + this);  //prints [object Object]
                      	console.log("result is " + _this); //prints [object Object]
                      	console.log("result length is " + this.result.length); //prints 0
                      
                          if (this.result.length > 0){
                              this.result.forEach(function(stock) {
                      			//since length=0, it never gets in this loop
                                                 //
                      			//
                      },
                      
                      scheduleUpdate: function(delay) {
                      	console.log("scheduled update check");
                      	var nextLoad = this.config.updateInterval;
                      	if (typeof delay !== "undefined" && delay >= 0) {
                      		nextLoad = delay;
                      	}
                      
                      	var self = this;
                      	setInterval(function() {
                      		self.getStocks();
                      	}, nextLoad);
                      },
                      
                      roundValue: function(value) {
                         return Math.round(value*100)/100; 
                      },
                      
                      getStocks: function () {
                          var url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D%27http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D' + this.config.stocks + '%26f%3Dsl1d1t1c1ohgv%26e%3D.csv%27%20and%20columns%3D%27symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Ccol2%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
                          this.sendSocketNotification('GET_STOCKS', url);
                      },
                      
                      
                      socketNotificationReceived: function(notification, payload) {
                          if (notification === "STOCKS_RESULT") {
                      		console.log("notification received");
                      		console.log(payload);  //prints Object { query: Object }
                              this.result = payload;
                              this.updateDom(self.config.fadeSpeed);
                          }    
                      },
                      
                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 1 / 4
                      • First post
                        Last post
                      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