├── package.json ├── .gitignore ├── README.md ├── tickers.js └── stocks.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "express": "^4.18.2" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *node_modules* 2 | *npm-debug* 3 | *dist* 4 | .idea 5 | .DS_Store 6 | .orig 7 | *.tmp* 8 | web/dll/vendor-manifest.json 9 | yarn.error 10 | yarn-error.log 11 | 12 | logs* 13 | !logs/.gitkeep 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using "Stocks", the real-time terminal-based quote monitor 2 | Adjust line 17 for the refresh rate in milliseconds. The default is 500. 3 | 4 | ## 5 | Planned upgrades: 6 | - Edit the monitor during runtime 7 | - Add more stock exchanges explicitly (you may be able to figure out how to use international) 8 | 9 | ### 10 | This is a work in progress. The quotes are fed from my own personal server. If you're looking for a more robust solution, 11 | feel free to email me at martin@martinshkreli.com. I'll be happy to help you out. 12 | -------------------------------------------------------------------------------- /tickers.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'AAPL', 3 | 'ABBV', 4 | 'BA', 5 | 'BABA', 6 | 'BAC', 7 | 'BAX', 8 | 'BBY', 9 | 'BDX', 10 | 'BIDU', 11 | 'BIIB', 12 | 'BMY', 13 | 'BP', 14 | 'BRK.A', 15 | 'BRK.B', 16 | 'BSX', 17 | 'C', 18 | 'CL', 19 | 'DIS', 20 | 'EA', 21 | 'F', 22 | 'GM', 23 | 'GS', 24 | 'HD', 25 | 'IBM', 26 | 'JNJ', 27 | 'KO', 28 | 'LMT', 29 | 'LOW', 30 | 'META', 31 | 'MSFT', 32 | 'NFLX', 33 | 'NKE', 34 | 'NOK', 35 | 'NVDA', 36 | 'ORCL', 37 | 'OXY', 38 | 'PFE', 39 | 'PG', 40 | 'PYPL', 41 | 'QCOM', 42 | 'RBLX', 43 | 'REGN', 44 | 'SBUX', 45 | 'SHOP', 46 | 'SQ', 47 | 'T', 48 | 'TSLA', 49 | 'U', 50 | 'UNH', 51 | 'V', 52 | 'VZ', 53 | 'WMT', 54 | 'XOM', 55 | 'ZM' 56 | ] -------------------------------------------------------------------------------- /stocks.js: -------------------------------------------------------------------------------- 1 | const readline = require('readline'); 2 | const tickers = require('./tickers'); 3 | let count = 0, columnwidth = 20, rows = 30; 4 | let startTime = Date.now(); 5 | let randchars = ['*','%','$','&','@','!','^','~','+','?','/','|','<','>']; 6 | console.clear(); 7 | function drawScreen() { 8 | for (i = 0; i < tickers.length; i++) { 9 | let k = Math.floor(i / rows); 10 | readline.cursorTo(process.stdout, k*columnwidth, i-rows*k); 11 | let dashes = "-".repeat(columnwidth - tickers[i].length) 12 | process.stdout.write(`\x1b[33m${tickers[i]}${dashes}`); 13 | }}; 14 | drawScreen(); 15 | readline.cursorTo(process.stdout,0,40); 16 | console.log(" "); 17 | setInterval(grab, 500); 18 | async function grab() { 19 | for (const singleticker of tickers) { 20 | const res1 = await fetch(`https://generic709.herokuapp.com/stockc/${singleticker}`) 21 | let quote; 22 | try {quote = await res1.json();} 23 | catch (e) {console.log(e);return;}; 24 | if (count % 250 == 0 && count > 1) { 25 | readline.cursorTo(process.stdout,3,45) 26 | process.stdout.write(`Data Received: ${count}`); 27 | let endTime = Date.now(); 28 | readline.cursorTo(process.stdout,3,46) 29 | let seconds = parseInt((((endTime - startTime) / 1000) % 60),10) 30 | seconds = seconds < 10 ? `0${seconds}` : seconds; 31 | process.stdout.write(`Time Elapsed: ${(Math.floor(((endTime - startTime) / 1000)/60))}:${seconds}`); 32 | readline.cursorTo(process.stdout,3,47) 33 | process.stdout.write(`Rate: ${parseInt(count / ((endTime - startTime) / 1000),10)}x`);} 34 | if (!quote) {return;} 35 | let xposition = 7 + Math.floor(tickers.indexOf(singleticker) / rows) * columnwidth; 36 | readline.cursorTo(process.stdout,xposition, tickers.indexOf(singleticker) % rows); 37 | process.stdout.write(`\x1b[37m${quote.price.toFixed(2)}${randchars[Math.floor(Math.random() * 10)]}`); 38 | count++;}} --------------------------------------------------------------------------------