Skip to content

Instantly share code, notes, and snippets.

@dceejay
Last active March 8, 2017 05:24
Show Gist options
  • Select an option

  • Save dceejay/c1e01cae4d81ec52106a to your computer and use it in GitHub Desktop.

Select an option

Save dceejay/c1e01cae4d81ec52106a to your computer and use it in GitHub Desktop.
Stock Price Alerts

#Stock price alerts

Get stock price quote every 10 mins and sends alert to desktop. First output is a full json object, second is simple text sentance.

How-to

  • On Linux - sudo apt-get install libnotify-bin
  • On Windows - download and install Growl for Windows
  • then download growlnotify - IMPORTANT : Unpack growlnotify to a folder that is present in your path!
  • Also requires growl package npm install growl
  • This requires the notify node which is available in the node-red-nodes project https://github.com/node-red/node-red-nodes/archive/master.zip
  • Import the flow.json to Node-RED, Deploy.
[{"id":"9237c789.3558f8","type":"notify","title":"","name":"","x":908.4394721984863,"y":236.6212673187256,"wires":[]},{"id":"8b351a1e.4bf998","type":"function","name":"Make price object","func":"\nif ( ~msg.payload.indexOf('quote') ) { \n var quote = JSON.parse(msg.payload.slice(6,-2)).query.results.row;\n if (typeof quote.length == \"undefined\") { quote = [ quote ]; }\n for (var i=0; i < quote.length; i++) {\n var da = quote[i].date.split('/');\n quote[i].date = da[1]+'/'+da[0]+'/'+da[2];\n var ti = quote[i].time.split(':');\n var hr = parseInt(ti[0]);\n var mn = ti[1].slice(0,-2);\n var pm = ti[1].slice(-2);\n if (pm == \"pm\") { hr += 12; }\n quote[i].time = hr+\":\"+mn;\n quote[i].price = quote[i].price * 1;\n quote[i].change = quote[i].change * 1;\n quote[i].high = quote[i].high * 1 || \"N/A\";\n quote[i].low = quote[i].low * 1 || \"N/A\";\n quote[i].open = quote[i].col1 * 1 || \"N/A\";\n delete(quote[i].col1);\n quote[i].vol = quote[i].col2 * 1;\n delete(quote[i].col2);\n }\n if (quote.length == 1) { quote = quote[0]; }\n msg.payload = quote;\n msg2 = {topic:\"Stock Price\", payload:quote.symbol +\" is \"+quote.price};\n return [msg,msg2];\n}\nreturn null;","outputs":"2","x":714.5302963256836,"y":215.1666774749756,"wires":[["5791bbc4.9ab40c"],["9237c789.3558f8"]]},{"id":"a9d8f720.136c3","type":"httpget","name":"Get Quote","baseurl":"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D","append":"%26f%3Dsl1d1t1c1ohgv%26e%3D.json'%20and%20columns%3D'symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Ccol2'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=quote","x":538.439380645752,"y":215.62126636505127,"wires":[["8b351a1e.4bf998"]]},{"id":"5791bbc4.9ab40c","type":"debug","name":"","complete":true,"x":907.4394721984863,"y":193.62126636505127,"wires":[]},{"id":"8f99a64e.7bd208","type":"inject","name":"","topic":"","payload":"IBM","repeat":"600","once":true,"x":401.1666793823242,"y":215.1666774749756,"wires":[["a9d8f720.136c3"]]}]
@andypiper

Copy link
Copy Markdown

Should be modified to use HTTP Request node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment