From a962bdabe11a1e1ecb71edc38a2d3d462cf054fb Mon Sep 17 00:00:00 2001 From: Jan Litzenburger Date: Tue, 19 Jan 2021 18:15:01 +0100 Subject: [PATCH] crypto support doc --- MMM-Jast.js | 5 ++++- README.md | 22 ++++++++++++---------- node_helper.js | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/MMM-Jast.js b/MMM-Jast.js index 5fcbd8a..5426270 100644 --- a/MMM-Jast.js +++ b/MMM-Jast.js @@ -1,3 +1,5 @@ +/* global Class, JastUtils */ + "use strict"; Module.register("MMM-Jast", { @@ -20,11 +22,12 @@ Module.register("MMM-Jast", { quantity: 10 } ], + crypto: [{ name: "BTC", symbol: "BTC" }], defaultCurrency: "EUR", baseURL: "https://www.alphavantage.co/", apiKey: "", scroll: "vertical", - //maxWidth: "300px", + maxWidth: "100%", showDepotGrowth: false }, diff --git a/README.md b/README.md index 2bded12..ce9214b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # MMM-JaST - **J**ust **a**nother **S**tock **T**icker -This is just another stock ticker for [Magic Mirror](https://magicmirror.builders/). +This is just another stock ticker for [Magic Mirror](https://magicmirror.builders/). Click here for the Magic Mirror [Forum Thread](https://forum.magicmirror.builders/topic/12507/mmm-jast-just-another-stock-ticker) - ## Features +- Support for Stock symbols +- Support for Crypto symbols (experimental!) - Multiple currencies - Currency exchange support - Vertical scrolling @@ -11,7 +12,7 @@ Click here for the Magic Mirror [Forum Thread](https://forum.magicmirror.builder - Depot value growth summary ## Installing the Module -Navigate to the MagicMirror subfolder "modules" and execute the following command +Navigate to the MagicMirror subfolder "modules" and execute the following command `git clone https://github.com/jalibu/MMM-Jast.git` ## Using the module @@ -25,19 +26,20 @@ To use this module, add it to the modules array in the `config/config.js` file: module: "MMM-Jast", position: "top_left", config: { + maxWidth: "100%", updateIntervalInSeconds: 1800, - fadeSpeedInSeconds: 3.5, + fadeSpeedInSeconds: 3.5, // Higher value: vertical -> faster // horizontal -> slower + scroll: "", + defaultCurrency: "EUR", + showDepotGrowth: true + apiKey: "", stocks: [ { name: "BASF", symbol: "BAS.DE", quantity: 10 }, { name: "SAP", symbol: "SAP.DE", quantitiy: 15 }, { name: "Henkel", symbol: "HEN3.DE" }, { name: "Alibaba", symbol: "BABA", tradeCurrency: "USD", displayCurrency: "EUR" }, - ], - defaultCurrency: "EUR", - apiKey: "", - scroll: "", - maxWidth: "100%", - showDepotGrowth: true + ], + crypto: [{ name: "BTC", symbol: "BTC" },], } } ``` diff --git a/node_helper.js b/node_helper.js index 303e624..d427696 100644 --- a/node_helper.js +++ b/node_helper.js @@ -74,20 +74,29 @@ module.exports = NodeHelper.create({ } config.crypto.forEach((crypto) => { - if (!crypto.lastUpdate || Date.now() - crypto.lastUpdate >= config.updateIntervalInSeconds * 1000) { + if ( + !crypto.lastUpdate || + Date.now() - crypto.lastUpdate >= config.updateIntervalInSeconds * 1000 + ) { const url = `${config.baseURL}query?function=DIGITAL_CURRENCY_DAILY&symbol=${crypto.symbol}&market=USD&apikey=${config.apiKey}`; - request(url, { json: true }, (err, res, body) => { + request(url, { json: true }, (err, _res, body) => { if (err) { console.error(`Error requesting Crypto data`); } try { const symbol = body["Meta Data"]["2. Digital Currency Code"]; - const values = Object.values(body["Time Series (Digital Currency Daily)"]); + const values = Object.values( + body["Time Series (Digital Currency Daily)"] + ); const current = parseFloat(values[0]["4a. close (USD)"]); const last = parseFloat(values[1]["4a. close (USD)"]); console.log("Sending Crypto result:", { symbol, current, last }); - self.sendSocketNotification("CRYPTO_RESULT", { symbol, current, last }); + self.sendSocketNotification("CRYPTO_RESULT", { + symbol, + current, + last + }); } catch (err) { console.error(`Error processing Crypto response`, body); }