MMM-cryptocurrency icon indicating copy to clipboard operation
MMM-cryptocurrency copied to clipboard

Column for own portfolio

Open lordvalium opened this issue 7 years ago • 53 comments

Hi, could it be possible to add a new column (e.g. in detail mode), right after 7d forecast, in which i could paste my number of coins i have in the specific currency? Thank you

lordvalium avatar Feb 01 '18 18:02 lordvalium

Hi, sure. I'll add it as a future work!

matteodanelli avatar Feb 06 '18 23:02 matteodanelli

Hi Matteo that would be amazing !

lordvalium avatar Feb 07 '18 17:02 lordvalium

Hello Mateo,

I have made my own portfolio and changed a few lines of your code. around line 354 I have added and edit some lines

          var cPrice= apiResult[j].price.replace("€", "");
           cPrice= cPrice.replace(",",".");
           var myWallet=(this.config.wallet[j] * cPrice).toFixed(2);
           var priceWrapper = document.createElement('td')
           var price = document.createElement('price')
           price.style.fontSize = this.config.fontSize
           price.innerHTML = this.config.wallet[j] + ' @ ' + apiResult[j].price.replace("EUR", "€") + ' = € ' + myWallet;

Then I have added in the config.js

	    {
			module: "MMM-cryptocurrency",
			position: "top_left",
			config: {
				currency: ['ripple', 'litecoin'],
				wallet: [251.688014,0.0382885],   // Added this line
                                conversion: 'EUR',
         ......

The wallet in config must be the same order as the currency above. It looks like this newset

SpoturDeal avatar Feb 09 '18 19:02 SpoturDeal

Thank you, nice idea. And in detail view? Meantime I Favorite Detail more because of The large portfolio. Nice idea to show the market cap with your Number of assets

lordvalium avatar Feb 11 '18 10:02 lordvalium

@lordvalium

I have got the solution

           var cPrice= currentCurrency.price.replace("€", "").trim();            //add this line around line 207
           cPrice= parseFloat(cPrice.replace(",","."));            // add this line
           var myWallet='€ '+(this.config.wallet[i] * cPrice ).toFixed(2);     // add this line
           
           var tdValues = [
               name,
               currentCurrency.price,
               myWallet                 //add this line
           ]

It is also necessary to get the alignment proper zo add this line

            for (var j = 0; j < tdValues.length; j++) {
                var tdWrapper = document.createElement('td')
                let currValue = tdValues[j]
                // If I am showing value then set color
                if (currValue.includes('%')) {
                    tdWrapper.style.color = this.colorizeChange(currValue.slice(0,-1))
                }
                tdWrapper.style.textAlign=(j>0?"right":"left");  //add this line
                tdWrapper.innerHTML = currValue
                trWrapper.appendChild(tdWrapper)                              
            }
            wrapper.appendChild(trWrapper)

Only add the lines I have marked the other lines are just to identify where to add This is how it will look

detail

I hope Matteo add this soon to his module

SpoturDeal avatar Feb 11 '18 10:02 SpoturDeal

@lordvalium

To add the total market cap of your portfolio you need to write a few lines as well

        tableHeader.style.textAlign="right";        // add this line for layout purpose
        wrapper.appendChild(tableHeader)    
        var marketCapMyWallet=0;                   // add this line  around line 197
        for (i = 0; i < data.length; i++) {
            marketCapMyWallet += parseFloat(currentCurrency.market_cap_eur);    //add this line
            var currentCurrency = data[i]

Then you need the add the data to the wrapper this is around line 240

     wrapper.appendChild(trWrapper)
        }
        var tableCaption = document.createElement('caption');                             // add this line
        tableCaption.innerHTML = "Total market cap: " + marketCapMyWallet;    // add this line
        wrapper.appendChild(tableCaption);       //add this line
        return wrapper

witcap

It gives the total market cap but I didn't do any formatting

SpoturDeal avatar Feb 11 '18 11:02 SpoturDeal

Very nice :) Thank you very much

This module is going to be one of the nicest and most intelligent ever. As other modules only take information from the internet, this one gets very interactive and is now heavily customizeable from the MM owner :)

lordvalium avatar Feb 11 '18 17:02 lordvalium

@lordvalium I am not sure what you mean. You can also write German if that's easier to explain.

SpoturDeal avatar Feb 11 '18 20:02 SpoturDeal

@SpoturDeal i think Matteo can better follow in English, but thank you!

You had the monetary amount in your code (# of assets * price per asset) The raw number of assets would be nice (or even selectable) what do you think?

lordvalium avatar Feb 11 '18 21:02 lordvalium

@lordvalium I think I know what you need.

Not to mess up Matteos great module I have added my own module based on Matteo's work you can find it at https://github.com/spoturdeal/MMM-crypto-portfolio

There you can add the wanted currencies logowithassets and how much you have in your wallet. In the config you can choose to show your assets and your portfolio.

SpoturDeal avatar Feb 12 '18 10:02 SpoturDeal

@SpoturDeal I've added your portfolio code. I do not have a certain coin but I do want to see its value change-over-time. In this case the portfolio value would be zero, the coin value would show correctly but the math results in the display of "€ NaN".

I made the following change by adding: ||0 var myWallet=(this.config.wallet[j] * cPrice || 0).toFixed(2);

as my column width is narrower and the graph width I use is only 150px, you'd also have to change to a smaller font: price.style.fontSize = 'small'

Now it shows zero. Code can stay the same for all coins/portfolios but IMHO it looks more consistent. :-)

edit: weird though, looking at your feb 9 comment, you have zero ETH and it shows zero. On my mirror it showed up as NaN... anyhow, it works now.

jinjirosan avatar Mar 26 '18 18:03 jinjirosan

@matteodanelli @SpoturDeal , great modul and great custom code. I just wanted to have my wallet stats and value in the same module so i take the code from @SpoturDeal and try to fix it in this module. I need to say i never have done anything like this so if this can be done better i would appreciate it. if you can tell me and this awesome community. This is what i have and for me is enough. I don't want to see more info or data.

Now you can see Crypto Prices, Portfolio amount and how much worth they are: MM

In the config.js you only need to add the line wallet:

	{
	module: "MMM-cryptocurrency",
	position: "top_left",
	config: {
		apikey: 'xxxx-xxxx-x-x-x-x--x-xxx',
		currency: ['bitcoin', 'ethereum'],
		conversion: 'EUR',
		logoHeaderText: 'Kryptobörse',
		significantDigits: '5',
		fontSize: 'x-large',
		headers: 'none',
		displayType: 'logo',
		wallet: [0.01951150,0.19834263],  //add this line!
		showGraphs: true
		},
	},

In the MMM-cryptocurrency.js add this lines to line 414 (maybe not every time the same line if someone have do changes before in the same .js!):

    //add this to line 414
        var cPrice = apiResult[j].price.replace("€", ""); //add this line
        var cPrice = cPrice.replace(".", "").replace(",", "."); //add this line
        var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
        var priceWrapper = document.createElement('td') //don't touch this!
        var price = document.createElement('price') //don't touch this!
        price.style.fontSize = this.config.fontSize //don't touch this!
        price.innerHTML = cPrice + '€ x ' + this.config.wallet[j] + ' = ' + myWallet + '€'; //Modify this line for custom view

Everything will be updated every single time when you call the API action automatically, i call it every 300000 ms (5m).

arcangeloerrico avatar Nov 12 '20 15:11 arcangeloerrico

Hi @arcangeloerrico,

what a coincidence. I've been trying to implement @SpoturDeal 's code for a few hours, especially in the detail view. But I am not good enough.

I resetet my coding and just added your code in line 414 and also adjusted the config.js. Unfortunately it doesn't work for me. I get the following picture when I use your code:

//add this to line 414
         var cPrice = apiResult[j].price.replace("€", ""); //add this line
         var cPrice = cPrice.replace(".", "").replace(",", "."); //add this line
         var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
         var priceWrapper = document.createElement('td') //don't touch this!
         var price = document.createElement('price') //don't touch this!
         price.style.fontSize = this.config.fontSize //don't touch this!
         price.innerHTML = cPrice + '€ x ' + this.config.wallet[j] + ' = ' + myWallet + '€'; //Modify this line for custom view

grafik

Any idea?

Thank you.

McNose avatar Nov 12 '20 18:11 McNose

Hi @arcangeloerrico,

what a coincidence. I've been trying to implement @SpoturDeal 's code for a few hours, especially in the detail view. But I am not good enough.

I resetet my coding and just added your code in line 414 and also adjusted the config.js. Unfortunately it doesn't work for me. I get the following picture when I use your code:

//add this to line 414
         var cPrice = apiResult[j].price.replace("€", ""); //add this line
         var cPrice = cPrice.replace(".", "").replace(",", "."); //add this line
         var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
         var priceWrapper = document.createElement('td') //don't touch this!
         var price = document.createElement('price') //don't touch this!
         price.style.fontSize = this.config.fontSize //don't touch this!
         price.innerHTML = cPrice + '€ x ' + this.config.wallet[j] + ' = ' + myWallet + '€'; //Modify this line for custom view

grafik

Any idea?

Thank you.

Hi, maybe just delete the first and last row and write it again (don't copy it) maybe it's a copy error while the problem seems to be in the "€" encoding. The correct amount a the end will be correct when you resolve this Problem with the "€" encoding.

arcangeloerrico avatar Nov 12 '20 18:11 arcangeloerrico

Just to be sure I deleted all rows and wrote them again. Still the same. Might it be a wrong editor? I changed the € to EUR and than it works (except the replacing of the first €, which is clear). But anyway it does not bulid the sum as well. It remains 0.00.

McNose avatar Nov 12 '20 19:11 McNose

Just to be sure I deleted all rows and wrote them again. Still the same. Might it be a wrong editor? I changed the € to EUR and than it works (except the replacing of the first €, which is clear). But anyway it does not bulid the sum as well. It remains 0.00.

Trow away the remplace on the first row and let my see what do you see then. I can't test it while I'm on Trip right now.

arcangeloerrico avatar Nov 12 '20 19:11 arcangeloerrico

If I commend the first row out, the module stays empty. So I just let it remain. Here is what I see: grafik

This is the code I use:

var cPrice = apiResult[j].price.replace("€", ""); 
var cPrice = cPrice.replace(".", "").replace(",", "."); 
var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
var priceWrapper = document.createElement('td')
var price = document.createElement('price')
price.style.fontSize = this.config.fontSize
price.innerHTML = cPrice + 'EUR x ' + this.config.wallet[j] + ' = ' + myWallet + 'EUR'; //Modify this line for custom view

McNose avatar Nov 12 '20 19:11 McNose

If I commend the first row out, the module stays empty. So I just let it remain. Here is what I see: grafik

This is the code I use:

var cPrice = apiResult[j].price.replace("€", ""); 
var cPrice = cPrice.replace(".", "").replace(",", "."); 
var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
var priceWrapper = document.createElement('td')
var price = document.createElement('price')
price.style.fontSize = this.config.fontSize
price.innerHTML = cPrice + 'EUR x ' + this.config.wallet[j] + ' = ' + myWallet + 'EUR'; //Modify this line for custom view

Yeah, the first row is important while you need the price from the API, this can't be deleted. Your problem ist that he didn't remplace the sign, when he can't remplace the sign the multiplicity operation didn't work. Delete from the first lane only (.remplace...) until the end and on innerHTML delete EUR and let me show the result please.

arcangeloerrico avatar Nov 12 '20 19:11 arcangeloerrico

Ah, I see.

But still no luck grafik

Code:

var cPrice = apiResult[j].price; 
var cPrice = cPrice.replace(".", "").replace(",", "."); 
var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
var priceWrapper = document.createElement('td')
var price = document.createElement('price')
price.style.fontSize = this.config.fontSize
price.innerHTML = cPrice + ' x ' + this.config.wallet[j] + ' = ' + myWallet + ' '; //Modify this line for custom view

McNose avatar Nov 12 '20 19:11 McNose

Ah, I see.

But still no luck grafik

Code:

var cPrice = apiResult[j].price; 
var cPrice = cPrice.replace(".", "").replace(",", "."); 
var myWallet = (this.config.wallet[j] * cPrice || 0).toFixed(2); //add this line ((2) change this number if you want to see more decimals)
var priceWrapper = document.createElement('td')
var price = document.createElement('price')
price.style.fontSize = this.config.fontSize
price.innerHTML = cPrice + ' x ' + this.config.wallet[j] + ' = ' + myWallet + ' '; //Modify this line for custom view

Now add to the first row .remplace("€", "") and should work, I think.

arcangeloerrico avatar Nov 12 '20 19:11 arcangeloerrico

If not try ('€' , ''), but the sign need to go or the multiplicity operation didn't work

arcangeloerrico avatar Nov 12 '20 19:11 arcangeloerrico

Hey, I did it. And I am really sorry. It was so simple. I just changed the editor and tried your code again. Now everything works. Really sorry. This is the first time my other editor did not work.

grafik

I hardly dare to ask, but did you also implement that for the detailed view?

I had already tried the @SpoturDeal code described above. In the wrong editor of course, but I'm not sure if it really still works.

Thank you for your perseverance.

McNose avatar Nov 12 '20 19:11 McNose

Yeah! I just do it for this view a the moment but I can try to implement it in the detailed view, what do you want to have? Just the same information but in the detailed view?

arcangeloerrico avatar Nov 12 '20 20:11 arcangeloerrico

Great! Thanks a lot. Yes, actually it is the same information. Like in the picure above: grafik

Maybe I would change the order of the rows, so it matches your view. Instead of price-asset-portfolio ----> price-portfolio-asset would fit better. And please don´t forget the total sum;-)

Awesome.

McNose avatar Nov 12 '20 20:11 McNose

I will take a look next week when I'm back and have some free time in the work. I will try my best.

arcangeloerrico avatar Nov 12 '20 20:11 arcangeloerrico

No need to hurry. Until then you made my day:-)

McNose avatar Nov 12 '20 20:11 McNose

@McNose Done!

I will try to tell you the changes that i do from my first post so you can do it quickly and without any problem because you have the same content like i do befor. And this time use the correct editor ; )

crypto_detailed

First you need to change the option in the config.js in: { module: "MMM-cryptocurrency", position: "top_center", config: { apikey: 'xxxx', currency: ['bitcoin', 'ethereum'], conversion: 'EUR', logoHeaderText: 'Kryptobörse', significantDigits: '5', fontSize: 'x-large', headers: 'none', headers: ['change24h', 'change1h', 'change7d'], // need this displayType: 'details', // need this wallet: [0.01951150,0.19834263], }, },

Second in MMM-cryptocurrency.js add the following lines (delete all the lines from SpoturDeal code to be sure you only use my code). Search for var tableHeaderValues [] and add the lines (line 162 for me):

    var tableHeaderValues = [
        this.translate('CURRENCY'),
        this.translate('PRICE'),

('Portfolio'), // add this line (don't need the option this.translate) ('Asset'), // add this line (don't need the option this.translate) ] then add the following code to var tdValues [] (line 195 for me, just after the for (xxx){} function):

	var myPrice=currentCurrency.price.replace("€","");				// add this line
	var myPrice=myPrice.replace(".", "").replace(",", ".");			// add this line
	var myWallet=(this.config.wallet[i]).toFixed(5);				// add this line 
	var myValue=(this.config.wallet[i]*myPrice).toFixed(2) + ' € ';	// add this line
	var tdValues = [
		name,
		 currentCurrency.price,
		myWallet,
		myValue
	];

and that is all if you don't have any problem ^^ Let me know if its work for your!

PD: the .toFixed(5) option is there while when I take it out no info will display. I think that is because I have the option significantDigits: '5' activated maybe if this option is deleted you don't need to put a number in .toFixed() but i didn't try this while I dont need to see more than 5 digit for my Portfolio and 2 Digits for the portfolio total value.

arcangeloerrico avatar Nov 18 '20 12:11 arcangeloerrico

@arcangeloerrico Awesome work! I used the correct editor and it works;-) I don´t use the "significantDigits" option, but let toFixed(5) untouched. Anyway it shows my 9 currencies. Do you think it is possible to add a "total" line and the end? It would be interessting to know which sum I own at the moment. Specially as btc explodes:-)

And can you change the layout of the row "Asset" a bit? Like in "Preis". In Preis it is 1.234,56€, but in "Asset" it is 1234.56€.

I don´t know how much work this is. But I am really impressed. Thank you.

McNose avatar Nov 19 '20 12:11 McNose

@arcangeloerrico Awesome work! I used the correct editor and it works;-) I don´t use the "significantDigits" option, but let toFixed(5) untouched. Anyway it shows my 9 currencies. Do you think it is possible to add a "total" line and the end? It would be interessting to know which sum I own at the moment. Specially as btc explodes:-)

And can you change the layout of the row "Asset" a bit? Like in "Preis". In Preis it is 1.234,56€, but in "Asset" it is 1234.56€.

I don't know how much work this is. But I am really impressed. Thank you.

I don't understand very well what you will do:

  • Do you want a total line that sum every Cryptocoin?
  • Change layout --> I can try that, maybe just need to convert back again. I need to convert "." and "," to null for the multiplication or this didn't work. I will give a check to this.
  • toFixed(5) problem --> can't tell you much to this is a commando and he should do it. Maybe a syntax error? it shows your the (2) good? or are both wrong?

arcangeloerrico avatar Nov 19 '20 12:11 arcangeloerrico

I just see that I misunderstood the toFixed Option. I changed it to two and I am fine now:-)

Yes, a total line that sums the Euro would be great. Like, if i have got BTC worth 20€ and ETH worth 40€ the line at the end should show "total 60€". My total portfolio sum. If you got more then two or three currencies it is hard to build the sum by taking a short look.

Concerning the layout, I just see that the row portfolio is 1234.56 as well.

McNose avatar Nov 19 '20 12:11 McNose