Skip to content

Commit

Permalink
crypto support doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Litzenburger authored and Jan Litzenburger committed Jan 19, 2021
1 parent 3cd8f7d commit a962bda
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
5 changes: 4 additions & 1 deletion MMM-Jast.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global Class, JastUtils */

"use strict";

Module.register("MMM-Jast", {
Expand All @@ -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
},

Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# 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
- Horizontal scrolling
- 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
Expand All @@ -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: "<none, vertical, horizontal>",
defaultCurrency: "EUR",
showDepotGrowth: true
apiKey: "<Insert your API Key>",
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: "<Insert your API Key>",
scroll: "<none, vertical, horizontal>",
maxWidth: "100%",
showDepotGrowth: true
],
crypto: [{ name: "BTC", symbol: "BTC" },],
}
}
```
Expand Down
17 changes: 13 additions & 4 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a962bda

Please sign in to comment.