Advertisement
jazzocode

Gnome's Web GUI All-In-One Addons (Minus Advanced Exchange)

Mar 22nd, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Graphing-Tracker.js
  2. //Graphing-Tracker.js
  3. //Graphing-Tracker.js
  4. (function(){
  5.     var util = {};
  6.  
  7.     //=========================================
  8.     //===============  SETTINGS  ==============
  9.     //=========================================
  10.  
  11.     util.graphMinutes = 15; //how many minutes of graph to show?
  12.     util.extendGraphColumn = true; //if you set more than 10 minutes, set this to true.
  13.     util.drawZeroLine = true; //display line at purchase price
  14.     util.drawSellThreshold = true; //draw
  15.     util.zeroLineColor = '#333';
  16.     util.sellThresholdColor = '#ff5';
  17.     util.graphLineColor = '#00f';
  18.  
  19.     // --- border percentages add padding to the top or bottom of the graph based on the height of the box.
  20.     // --- the percentages are percent out of the original max to min spread.
  21.  
  22.     util.topOffsetPercentage = 2; // value between 60 and 2;
  23.     util.bottomOffsetPercentage = 2; // value between 60 and 2;
  24.  
  25.     // --- the below settings are experimental... please let me know if they aren't working and you're using them.
  26.  
  27.     util.testHangWarning = false; // --- true to enable hang warnings; false to disable.
  28.     util.hangThreshold = 15; // --- the number of ticks with an identical price that will cause a hang warning alert.
  29.     util.percentHanging = .9; // --- percentage of items needed to appear to hang before a warning is given
  30.     util.hangWarningMessage = '{n} Prices seem to be stagnant... did the bot hang?'; // --- hang message
  31.  
  32.     util.displayMarketCap = true;
  33.     //=========================================
  34.     //===========  END SETTINGS  ==============
  35.     //=========================================
  36.  
  37.     util.coinMarketCapAPI = 'https://api.coinmarketcap.com/v1/global/';
  38.     util.msPerDataFrame = 12900; //assumed average time
  39.     util.topOffsetPercentage = Math.min( 60, Math.max( 2, util.topOffsetPercentage ));
  40.     util.bottomOffsetPercentage = Math.min( 60, Math.max( 2, util.bottomOffsetPercentage ));
  41.     util.graphFrames = ((util.graphMinutes || 5) * 6) >> 0;
  42.     util.hangThreshold = Math.min( 999, Math.max( 1, util.hangThreshold ));
  43.     util.percentHanging = Math.min( 1, Math.max( .001, util.percentHanging ));
  44.  
  45.     util.createHiDPICanvas = function( w, h, ratio, elementUse ) {
  46.         if( !window.PIXEL_RATIO ) {
  47.             window.PIXEL_RATIO = ( function () {
  48.                 var ctx = document.createElement( "canvas" ).getContext( "2d" ),
  49.                 dpr = window.devicePixelRatio || 1,
  50.                 bsr = ctx.webkitBackingStorePixelRatio ||
  51.                         ctx.mozBackingStorePixelRatio ||
  52.                         ctx.msBackingStorePixelRatio ||
  53.                         ctx.oBackingStorePixelRatio ||
  54.                         ctx.backingStorePixelRatio || 1;
  55.  
  56.                 return dpr / bsr;
  57.             })();
  58.         }
  59.         if ( !ratio ) { ratio = window.PIXEL_RATIO; }
  60.         var can = ( Array.isArray( elementUse ) ? elementUse[0] : elementUse );
  61.         can.width = w * ratio;
  62.         can.height = h * ratio;
  63.         can.style.width = w + "px";
  64.         can.style.height = h + "px";
  65.         can.getContext( "2d" ).setTransform( ratio, 0, 0, ratio, 0, 0 );
  66.         return can;
  67.     };
  68.  
  69.     util.graph = function( drawZero, drawProfit ) {
  70.         this.stats = {
  71.             totalSamples: util.graphFrames,
  72.             profitLine: .01,
  73.             data: []
  74.         };
  75.         this.stats.data = new Array( this.stats.totalSamples );
  76.         this.stats.data = this.stats.data.join( ',' ).split( ',' ).map( function() { return null; });
  77.         this.drawZero = drawZero;
  78.         this.drawProfit = drawProfit;
  79.     };
  80.  
  81.     util.graph.prototype.setSelector = function( selector ) {
  82.         this.destination = selector[0];
  83.  
  84.         var width = selector.width();
  85.         var height = selector.height();
  86.  
  87.         var canvas = $( '#myCanvas' );
  88.         var self = this;
  89.         if( canvas.length < 1 ) {
  90.             $( 'body' ).append( '<div style="position:absolute;display:none;"><canvas id="myCanvas"></canvas></div>' );
  91.             var canvas = $( '#myCanvas' );
  92.             canvas = util.createHiDPICanvas( width, height, 1, canvas[0] );
  93.             util.canvas = canvas;
  94.             util.canvasContext = canvas.getContext( '2d' );
  95.         }
  96.         this.canvas = canvas;
  97.     };
  98.  
  99.     util.graph.prototype.updateStats = function( value, sellTrigger ) {
  100.         this.stats.data.push( value );
  101.         this.stats.profitLine = sellTrigger;
  102.         this.stats.data.shift(); // remove the oldest value
  103.     };
  104.  
  105.     util.graph.prototype.drawStats = function() {
  106.         var ctx = util.canvasContext;
  107.         var size = this.destination.getBoundingClientRect();
  108.         var totalRun = this.stats.totalSamples;
  109.  
  110.         if( util.extendGraphColumn && size.width < totalRun ) {
  111.             this.destination.style['width'] = totalRun+'px';
  112.             size.width = totalRun;
  113.         }
  114.  
  115.         if( util.canvas == undefined || util.canvas.height == undefined ) {
  116.             return;
  117.         }
  118.  
  119.         if( size.width != util.canvas.width || size.height != util.canvas.height ) {
  120.             util.canvas = util.createHiDPICanvas(size.width, size.height, 1, $( '#myCanvas' )[0] );
  121.             util.canvasContext = util.canvas.getContext( '2d' );
  122.         }
  123.         ctx.clearRect( 0, 0, size.width, size.height );
  124.         var first = true;
  125.         var range = { min: 1e8, max: -1e8, size: 0 };
  126.         this.stats.data.forEach( function( c ){
  127.             if( c !== null ) {
  128.                 range.min = Math.min( c, range.min );
  129.                 range.max = Math.max( c, range.max );
  130.             }
  131.         });
  132.  
  133.         if( this.drawZero ) {
  134.             range.min = Math.min( range.min, 0 );
  135.             range.max = Math.max( range.max, 0 );
  136.         }
  137.  
  138.         if( this.drawProfit ) {
  139.             range.max = Math.max( range.max, this.stats.profitLine );
  140.             range.min = Math.min( range.min, this.stats.profitLine );
  141.         }
  142.  
  143.         range.size = range.max - range.min;
  144.  
  145.         range.max += range.size * (util.topOffsetPercentage / 100);
  146.         range.min -= range.size * (util.bottomOffsetPercentage / 100);
  147.  
  148.         range.size = range.max - range.min;
  149.  
  150.         if( util.drawZeroLine && this.drawZero ) {
  151.             var percent = Math.abs(range.max - 0) / range.size;
  152.             ctx.strokeStyle = util.zeroLineColor;
  153.             ctx.fillStyle = util.zeroLineColor;
  154.             ctx.lineWidth = 1;
  155.             ctx.font = '12px calibri';
  156.             ctx.fillText( '0%', 0, (percent * size.height >> 0) + .5 );
  157.             ctx.beginPath();
  158.             ctx.moveTo( 20, (percent * size.height >> 0) + .5 );
  159.             ctx.lineTo( size.width, (percent * size.height >> 0) + .5 );
  160.             ctx.stroke();
  161.         }
  162.  
  163.         if( util.drawSellThreshold && this.drawProfit ) {
  164.             var percent = Math.abs(range.max - this.stats.profitLine) / range.size;
  165.             ctx.strokeStyle = util.sellThresholdColor;
  166.             ctx.lineWidth = 1;
  167.             ctx.beginPath();
  168.             ctx.moveTo( 0, (percent * size.height >> 0) +.5 );
  169.             ctx.lineTo( size.width, (percent * size.height >> 0) +.5 );
  170.             ctx.stroke();
  171.         }
  172.  
  173.         ctx.strokeStyle = util.graphLineColor;
  174.         ctx.lineWidth = 1;
  175.         ctx.beginPath();
  176.         var first = true;
  177.         var index = 0;
  178.         for( var i = 0; i < totalRun; i++ ) {
  179.             if( this.stats.data[i] != null && this.stats.data[i] != '' ) {
  180.                 if( first ) {
  181.                     first = false;
  182.                     ctx.moveTo( (index/totalRun * size.width) , (size.height - (( this.stats.data[i] - range.min ) / range.size * size.height )));
  183.                 } else {
  184.                     ctx.lineTo( (index/totalRun * size.width) , (size.height - (( this.stats.data[i] - range.min ) / range.size * size.height )));
  185.                 }
  186.                 index++;
  187.             } /*else if( this.stats.data[i] == '' ) {
  188.                 if( !first ) {
  189.                     ctx.stroke();
  190.                     first = true;
  191.                 }
  192.                 index++;
  193.             }*/
  194.         }
  195.         ctx.stroke();
  196.         var res = 'url(' + util.canvas.toDataURL() + ')';
  197.  
  198.         this.destination.style['backgroundImage'] = res;
  199.         this.destination.style['backgroundRepeat'] = 'no-repeat';
  200.  
  201.     };
  202.  
  203.     var containers = {
  204.         dca: {
  205.             dataName: 'dcaLogData',
  206.             name: 'dtDcaLogs',
  207.             statName: 'profit',
  208.             childDestination: 'profit',
  209.             drawZero: true,
  210.             drawProfit: true,
  211.             hangCheck: true,
  212.             pairAppend: ''
  213.         },
  214.         pairs: {
  215.             dataName: 'gainLogData',
  216.             name: 'dtPairsLogs',
  217.             statName: 'profit',
  218.             childDestination: 'profit',
  219.             drawZero: true,
  220.             drawProfit: true,
  221.             hangCheck: true,
  222.             pairAppend: ''
  223.         },
  224.         pbl: {
  225.             dataName: 'bbBuyLogData',
  226.             name: 'dtPossibleBuysLog',
  227.             statName: 'currentValue',
  228.             childDestination: 'current-value',
  229.             drawZero: false,
  230.             drawProfit: false,
  231.             hangCheck: true,
  232.             pairAppend: '_PBL'
  233.         },
  234.         dust: {
  235.             dataName: 'dustLogData',
  236.             name: 'dtDustLogs',
  237.             statName: 'profit',
  238.             childDestination: 'profit',
  239.             drawZero: true,
  240.             drawProfit: false,
  241.             hangCheck: false,
  242.             pairAppend: '_DUST'
  243.         },
  244.         pending: {
  245.             dataName: 'pendingLogData',
  246.             name: 'dtPendingLogs',
  247.             statName: 'profit',
  248.             childDestination: 'profit',
  249.             drawZero: true,
  250.             drawProfit: true,
  251.             hangCheck: false,
  252.             pairAppend: '_PEND'
  253.         }
  254.     };
  255.  
  256.     var pairData = {};
  257.  
  258.     var freshPairCutoff = 60000;
  259.     function tick( data ) {
  260.         if( util.displayMarketCap ) {
  261.             displayMarketCap();
  262.         }
  263.         var now = Date.now();
  264.  
  265.         var hangStats = {signaled: 0, max: 0};
  266.  
  267.         var keys = Object.keys( pairData );
  268.         for( var i = 0; i < keys.length; i++ ) {
  269.             if( now - pairData[keys[i]].lastTick > freshPairCutoff ) {
  270.                 delete pairData[keys[i]];
  271.             }
  272.         }
  273.  
  274.         var dataTypes = Object.keys( containers );
  275.         for( var i = 0; i < dataTypes.length; i++ ) {
  276.             var source = data[containers[dataTypes[i]].dataName];
  277.             for( var j = 0; j < source.length; j++ ) {
  278.                 var pair = source[j].market + containers[dataTypes[i]].pairAppend;
  279.                 if( pairData[pair] == undefined ) {
  280.                     pairData[pair] = {
  281.                         lastTick: now,
  282.                         graph: new util.graph( containers[dataTypes[i]].drawZero, containers[dataTypes[i]].drawProfit )
  283.                     };
  284.                     var cachedData = getCacheData( pair );
  285.                     for( var z = 0; z < cachedData.length; z++ ) {
  286.                         pairData[pair].graph.updateStats( cachedData[z], 0 );
  287.                     }
  288.                 } else {
  289.                     pairData[pair].lastTick = now;
  290.                 }
  291.                 pairData[pair].graph.updateStats(
  292.                     source[j][containers[dataTypes[i]].statName] / 100, //current profit
  293.                     (source[j].triggerValue || 0) / 100 //sell threshold
  294.                 );
  295.                 setCacheData( pair, pairData[pair].graph.stats.data, pairData[pair].lastTick );
  296.                 if( util.testHangWarning && containers[dataTypes[i]].hangCheck ) {
  297.                     hangStats.max++;
  298.                     var result = hangCheck( pairData[pair] );
  299.                     if( result >= util.hangThreshold ) {
  300.                         console.log( pair + ' is signaling a hang.');
  301.                         hangStats.signaled++;
  302.                     }
  303.                 }
  304.             }
  305.         }
  306.  
  307.         if( util.testHangWarning && hangStats.max > 0 && hangStats.signaled / hangStats.max >= util.percentHanging ) {
  308.             alert( util.hangWarningMessage.replace( '{n}', hangStats.signaled ));
  309.         }
  310.     }
  311.  
  312.     function hangCheck( pair ) {
  313.         var start = pair.graph.stats.totalSamples - 1;
  314.         var runs = {};
  315.         var lastValue = null;
  316.         var run = 0;
  317.         for( var i = pair.graph.stats.totalSamples-1; i > -1; i-- ) {
  318.             var curValue = pair.graph.stats.data[i];
  319.             if( curValue != null && curValue != '' && lastValue == null ) {
  320.                 lastValue = curValue;
  321.  
  322.                 run++;
  323.             } else if( curValue == lastValue ) {
  324.                 run++;
  325.             } else if( lastValue != null ) {
  326.                 return run;
  327.             }
  328.         }
  329.         return 0;
  330.     }
  331.  
  332.     function render() {
  333.  
  334.         var renderTypes = Object.keys( containers );
  335.         for( var i = 0; i < renderTypes.length; i++ ) {
  336.             var curContainer = containers[renderTypes[i]];
  337.             var curParent = $( '#' + curContainer.name );
  338.             if( curParent.width() != 100 ) {
  339.                 var curParent = $( '#' + curContainer.name + ' tbody tr' );
  340.                 for( var j = 0; j < curParent.length; j++ ) {
  341.                     var curType = $( curParent[j] ).children( '.market' ).children( 'a' ).html();
  342.                     var cur = pairData[curType+curContainer.pairAppend];
  343.                     if( cur !== undefined ) {
  344.                         //we can render it!
  345.                         cur.graph.setSelector( $( curParent[j] ).children( '.' + curContainer.childDestination ));
  346.                         cur.graph.drawStats();
  347.                     }
  348.                 }
  349.                 return; // --- we rendered this one, dont render any others.
  350.             }
  351.         }
  352.     }
  353.  
  354.     function setCacheData( key, values, lastTick ) {
  355.         var graphing = localStorage.getItem('graphing');
  356.         if( graphing == null ) {
  357.             graphing = {};
  358.         } else {
  359.             graphing = JSON.parse( graphing );
  360.         }
  361.  
  362.         var store = [];
  363.         for( var i = 0; i < values.length; i++ ) {
  364.             if( values[i] == null || values[i] == '' ) {
  365.                 // do nothing
  366.             } else {
  367.                 store.push(parseFloat(values[i].toFixed(4)));
  368.             }
  369.         }
  370.  
  371.         graphing[key] = {time: lastTick, values: store};
  372.  
  373.         localStorage.setItem( 'graphing', JSON.stringify( graphing ));
  374.     }
  375.  
  376.     function getCacheData( key ) {
  377.         var graphing = localStorage.getItem('graphing');
  378.         if( graphing == null ) {
  379.             graphing = {};
  380.         } else {
  381.             graphing = JSON.parse( graphing );
  382.         }
  383.  
  384.         if( graphing[key] != undefined ) {
  385.             var elapsedTime = Date.now() - graphing[key].time;
  386.             var ticksElapsed = (elapsedTime / util.msPerDataFrame) >> 0;
  387.             var results = graphing[key].values;
  388.             for( var i = 0; i < ticksElapsed; i++ ) {
  389.                 results.push(null);
  390.             }
  391.             return results;
  392.         }
  393.         return [];
  394.     }
  395.  
  396.  
  397.  
  398.     function displayMarketCap() {
  399.         $.get( util.coinMarketCapAPI, function( data ) {
  400.             if( data && data.total_market_cap_usd ) {
  401.                 var value = data.total_market_cap_usd.toLocaleString( 'en', { useGrouping: true });
  402.                 var delta = 0;
  403.                 var exists = $( '#nMCAPTotal' );
  404.                 if( exists.length ) {
  405.                     exists.attr( 'title', value ).html( value );
  406.                 } else {
  407.                     $('.monitor-summary').append('<li class="list-inline-item tdbitcoin font-16 ticker-text"><label id="nMCAP" data-toggle="tooltip" data-placement="bottom" title="Total Crypto MarketCap" data-original-title="Total Crypto MarketCap">MCAP</label>: <span id="nMCAPTotal" title="'+value+'">'+value+'</span></li>');
  408.                     // --- coinmarketcap does not currently return the 24hr % change, so save this for when it does.
  409.                     //$('.monitor-summary').append('<li class="list-inline-item tdbitcoin font-16 ticker-text"><label id="nMarket" data-toggle="tooltip" data-placement="bottom" title="Total Crypto MarketCap" data-original-title="Total Crypto MarketCap">MCAP</label>: <span id="nMarketPrice" title="'+value+'">'+value+'</span>&nbsp;<span id="nMarketPercChange" title="'+delta+' %" class="text-danger">('+delta+' %)</span></li>');
  410.                 }
  411.             }
  412.         });
  413.     }
  414.  
  415.     // listen to AJAX requests:
  416.  
  417.     function addXMLRequestCallback( callback ) {
  418.         var oldSend, i;
  419.         if( XMLHttpRequest.callbacks ) {
  420.             // we've already overridden send() so just add the callback
  421.             XMLHttpRequest.callbacks.push( callback );
  422.         } else {
  423.             // create a callback queue
  424.             XMLHttpRequest.callbacks = [callback];
  425.             // store the native send()
  426.             oldSend = XMLHttpRequest.prototype.send;
  427.             // override the native send()
  428.             XMLHttpRequest.prototype.send = function() {
  429.  
  430.                 for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) {
  431.                     XMLHttpRequest.callbacks[i]( this );
  432.                 }
  433.                 // call the native send()
  434.                 oldSend.apply( this, arguments );
  435.             };
  436.         }
  437.     }
  438.  
  439.     addXMLRequestCallback( function( xhr ) {
  440.         xhr.onreadystatechange = function() {
  441.             if( xhr.readyState == 4 && xhr.status == 200 ) {
  442.                 if( xhr.responseURL.indexOf( 'data' ) > -1 ) {
  443.                     var data = JSON.parse( xhr.response );
  444.                     tick( data );
  445.                 }
  446.             }
  447.         };
  448.     });
  449.  
  450.     $( "body" ).on( 'DOMSubtreeModified', "#dvLastUpdatedOn", function() {
  451.         render();
  452.     });
  453.     $( ".dca-log,.dust-log,.pairs-log,.possible-buys-log,.pending-log" ).on( "click", function(){
  454.         setTimeout( function(){ render(); }, 100 );
  455.     });
  456. })();
  457.  
  458.  
  459. //Estimated-Percent-Gain.js
  460. //Estimated-Percent-Gain.js
  461. //Estimated-Percent-Gain.js
  462. function estimateYesterdayPercent() {
  463.     var previousTCV = $("#mTotalCurrentVal").text() - $("#mTodayProfit").text();
  464.     var prevPercentCalc = ($("#mYesterdayProfit").text()/previousTCV*100).toFixed(2);
  465.     var prevPercent = prevPercentCalc + '%';
  466.     if ($("#mYesterdayProfit").text() !== "")
  467.     {
  468.         if ($("#mYesterdayProfitPCTValue").text() === "") {
  469.         $("span.market-price-calculations.text-profityd").append('<br><label class="usd-value"><span class="full-text">Estimated Percent Gain&nbsp;</span><span class="short-text">Est. % Gain&nbsp;</span></label><span class="mb-0  main-text" id="mYesterdayProfitPCTValue" title="'+prevPercent+'">'+prevPercent+'</span>');
  470.         } else {
  471.             $("#mYesterdayProfitPCTValue").attr("title",prevPercent);
  472.             $("#mYesterdayProfitPCTValue").text(prevPercent);
  473.         }
  474.     }
  475. }
  476.  
  477. function estimatePercent() {
  478.     var todayPercentCalc = ($("#mTodayProfit").text()/$("#mTotalCurrentVal").text()*100).toFixed(2);
  479.     var todayPercent = todayPercentCalc + '%';
  480.     $(".usd-value").css({'margin-bottom':'0px'});
  481.     if ($("#mTodayProfit").text() !== "")
  482.     {
  483.         if ($("#mTodayProfitPCTValue").text() === "") {
  484.         $("span.market-price-calculations.text-profittd").append('<br><label class="usd-value"><span class="full-text">Estimated Percent Gain&nbsp;</span><span class="short-text">Est. % Gain&nbsp;</span></label><span class="mb-0  main-text" id="mTodayProfitPCTValue" title="'+todayPercent+'">'+todayPercent+'</span>');
  485.         } else {
  486.             $("#mTodayProfitPCTValue").attr("title",todayPercent);
  487.             $("#mTodayProfitPCTValue").text(todayPercent);
  488.         }
  489.     }
  490. }
  491.  
  492. estimateYesterdayPercent();
  493. $("body").on('DOMSubtreeModified', "#mYesterdayProfitUSDValue", function() {
  494.     estimateYesterdayPercent();
  495. });
  496.  
  497. estimatePercent();
  498. $("body").on('DOMSubtreeModified', "#mTodayProfitUSDValue", function() {
  499.     estimatePercent();
  500. });
  501.  
  502.  
  503.  
  504. //USD-Estimate.js
  505. //USD-Estimate.js
  506. //USD-Estimate.js
  507. function estimate() {
  508.     var btc1 = $('#nMarketPrice').attr("title");
  509.     $("#dtDcaLogs th.total-cost").text('Estimated Value');
  510.     $('.summary-table').removeClass('col-md-3').removeClass('col-md-4').addClass('col-md-4');
  511.     //DCA
  512.     if ($('#dtDcaLogs thead').length > 0) {
  513.         if ($('#dtDcaLogs thead .est-usd').length < 1) {
  514.             $('#dtDcaLogs thead tr').append('<th class="text-right est-usd all sorting" rowspan="1" colspan="1" style="width: 92px;">Estimated Value</th>');
  515.         };
  516.         $('#dtDcaLogs tbody tr').each(function() {
  517.             $(this).find('.est-usd').remove();
  518.             $(this).append('<td class="text-right est-usd all"></td>');
  519.             var num1 = $(this).find('.current-value').html().split("<br>")[1];
  520.             var num2 = $(this).find('.current-value').html().split("<br>")[0];
  521.             var calc = num2 - num1;
  522.             var btc = calc.toFixed(8);
  523.             var usd = btc * btc1;
  524.             var difference = usd.toFixed(2);
  525.             var sta = num2 * btc1;
  526.             var total = sta.toFixed(2);
  527.             if (difference > 0) {
  528.                 $(this).find('.est-usd').html('<span style="color:#05b16f;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
  529.             } else {
  530.                 $(this).find('.est-usd').html('<span style="color:#d85353;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
  531.             }
  532.         });
  533.         $("#dcLogDifference").find('b').remove();
  534.         $("#dcLogTotalCurrentVal").find('b').remove();
  535.         $("#dcLogRealCost").find('b').remove();
  536.         var val = $('#dcLogTotalCurrentVal').text();
  537.         var bou = $('#dcLogRealCost').text();
  538.         var calc = val - bou;
  539.         var btc = calc.toFixed(8);
  540.         var est = bou * btc1;
  541.         var bought = est.toFixed(2);
  542.         var usd = btc * btc1;
  543.         var difference = usd.toFixed(2);
  544.         var sta = val * btc1;
  545.         var total = sta.toFixed(2);
  546.         $("#dcLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
  547.         $("#dcLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
  548.         $("#dcLogRealCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
  549.     }
  550.     //Pairs
  551.     if ($('#dtPairsLogs thead').length > 0) {
  552.         if ($('#dtPairsLogs thead .est-usd').length < 1) {
  553.             $('#dtPairsLogs thead tr').append('<th class="text-right est-usd all sorting" rowspan="1" colspan="1" style="width: 92px;">Estimated Value</th>');
  554.         }
  555.         $('#dtPairsLogs tbody tr').each(function() {
  556.             $(this).find('.est-usd').remove();
  557.             $(this).append('<td class=" text-right est-usd all"></td>');
  558.             var num1 = $(this).find('.bought-cost').text();
  559.             var num2 = $(this).find('.current-value').text();
  560.             var calc = num2 - num1;
  561.             var btc = calc.toFixed(8);
  562.             var usd = btc * btc1;
  563.             var difference = usd.toFixed(2);
  564.             var sta = num2 * btc1;
  565.             var total = sta.toFixed(2);
  566.             if (difference > 0) {
  567.                 $(this).find('.est-usd').html('<span style="color:#05b16f;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
  568.             } else {
  569.                 $(this).find('.est-usd').html('<span style="color:#d85353;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
  570.             }
  571.         });
  572.         $("#pairsLogDifference").find('b').remove();
  573.         $("#pairsLogTotalCurrentVal").find('b').remove();
  574.         $("#pairsLogRealCost").find('b').remove();
  575.         var val = $('#pairsLogTotalCurrentVal').text();
  576.         var bou = $('#pairsLogRealCost').text();
  577.         var calc = val - bou;
  578.         var btc = calc.toFixed(8);
  579.         var est = bou * btc1;
  580.         var bought = est.toFixed(2);
  581.         var usd = btc * btc1;
  582.         var difference = usd.toFixed(2);
  583.         var sta = val * btc1;
  584.         var total = sta.toFixed(2);
  585.         $("#pairsLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
  586.         $("#pairsLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
  587.         $("#pairsLogRealCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
  588.     }
  589.     //Dust
  590.     if ($('#dtDustLogs thead').length > 0) {
  591.         if ($('#dtDustLogs thead .est-usd').length < 1) {
  592.             $('#dtDustLogs thead tr').append('<th class="text-right est-usd all sorting" rowspan="1" colspan="1" style="width: 92px;">Estimated Value</th>');
  593.         }
  594.         $('#dtDustLogs tbody tr').each(function() {
  595.             $(this).find('.est-usd').remove();
  596.             $(this).append('<td class=" text-right est-usd all"></td>');
  597.             var num1 = $(this).find('.bought-cost').text();
  598.             var num2 = $(this).find('.current-value').text();
  599.             var calc = num2 - num1;
  600.             var btc = calc.toFixed(8);
  601.             var usd = btc * btc1;
  602.             var difference = usd.toFixed(2);
  603.             var sta = num2 * btc1;
  604.             var total = sta.toFixed(2);
  605.             if (difference > 0) {
  606.                 $(this).find('.est-usd').html('<span style="color:#05b16f;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
  607.             } else {
  608.                 $(this).find('.est-usd').html('<span style="color:#d85353;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
  609.             }
  610.         });
  611.         $("#dustLogDifference").find('b').remove();
  612.         $("#dustLogTotalCurrentVal").find('b').remove();
  613.         $("#dustLogRealCost").find('b').remove();
  614.         var val = $('#dustLogTotalCurrentVal').text();
  615.         var bou = $('#dustLogRealCost').text();
  616.         var calc = val - bou;
  617.         var btc = calc.toFixed(8);
  618.         var est = bou * btc1;
  619.         var bought = est.toFixed(2);
  620.         var usd = btc * btc1;
  621.         var difference = usd.toFixed(2);
  622.         var sta = val * btc1;
  623.         var total = sta.toFixed(2);
  624.         $("#dustLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
  625.         $("#dustLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
  626.         $("#dustLogRealCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
  627.     }
  628.     //Sales
  629.     if ($('#dtSalesLog thead').length > 0) {
  630.         $("#salesLogDifference").find('b').remove();
  631.         $("#salesLogTotalCurrentVal").find('b').remove();
  632.         $("#salesLogBoughtCost").find('b').remove();
  633.         var val = $('#salesLogTotalCurrentVal').text();
  634.         var bou = $('#salesLogBoughtCost').text();
  635.         var calc = val - bou;
  636.         var btc = calc.toFixed(8);
  637.         var est = bou * btc1;
  638.         var bought = est.toFixed(2);
  639.         var usd = btc * btc1;
  640.         var difference = usd.toFixed(2);
  641.         var sta = val * btc1;
  642.         var total = sta.toFixed(2);
  643.         $("#salesLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
  644.         $("#salesLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
  645.         $("#salesLogBoughtCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
  646.     }  
  647.     //Balance
  648.     $('.ticker-text').css('position','relative');
  649.     $('#nBalanceVal span').remove();
  650.     var btc = $('#nBalanceVal').attr("title");
  651.     var usd = btc * btc1;
  652.     var total = usd.toFixed(2);
  653.     $('#nBalanceVal').append('<span style="display:inline-block;position:absolute;bottom:-8px;right:0;font-size: 10px">($'+total+')</span>');
  654.     //Current
  655.     $('#nTotalCurrentVal span').remove();
  656.     var btc = $('#nTotalCurrentVal').attr("title");
  657.     var usd = btc * btc1;
  658.     var total = usd.toFixed(2);
  659.     $('#nTotalCurrentVal').append('<span style="display:inline-block;position:absolute;bottom:-8px;right:0;font-size: 10px">($'+total+')</span>');
  660.     //Pending
  661.     $('#nTotalPendingVal span').remove();
  662.     var btc = $('#nTotalPendingVal').attr("title");
  663.     var usd = btc * btc1;
  664.     var total = usd.toFixed(2);
  665.     $('#nTotalPendingVal').append('<span style="display:inline-block;position:absolute;bottom:-8px;right:0;font-size: 10px">($'+total+')</span>');
  666. }
  667. $("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
  668.     estimate();
  669. });
  670. $(".dca-log, .pairs-log, .dust-log, .sales-log").on("click", function() {
  671.     setTimeout(function() {
  672.         estimate();
  673.     }, 100);
  674. });
  675. $( document ).ready(function() {
  676.     setTimeout(function() {
  677.         estimate();
  678.     }, 100);
  679. });
  680.  
  681.  
  682. //Convert-Time-AM-PM.js
  683. //Convert-Time-AM-PM.js
  684. //Convert-Time-AM-PM.js
  685. var ConvertLogDates = {
  686.     init: function () {
  687.         var _parent = this;
  688.         $("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
  689.             if ($('#dtDcaLogs').text() !== "")
  690.                 _parent.convertDCADates();
  691.  
  692.             if ($('#dtPairsLogs').text() !== "")
  693.                 _parent.convertPairsDates();
  694.  
  695.             if ($('#dtSalesLog').text() !== "")
  696.                 _parent.convertSalesLogDates();
  697.  
  698.             if ($('#dtDustLogs').text() !== "")
  699.                 _parent.convertDustLogDates();
  700.         });
  701.         $("body").on('DOMSubtreeModified', "#dvCurrentUTCTime", function() {
  702.             _parent.convertLocalTimeToAMPM();
  703.         });
  704.  
  705.         $(document).on("click",".dca-log, .pairs-log, .dust-log, .sales-log, th.date.all, .page-link, .page-item, .sorting_asc, .sorting_desc", function() {
  706.                 setTimeout(function(){
  707.                     if ($('#dtSalesLog').text() !== "")
  708.                         _parent.convertSalesLogDates();
  709.                     if ($('#dtDcaLogs').text() !== "")
  710.                         _parent.convertDCADates();
  711.                     if ($('#dtPairsLogs').text() !== "")
  712.                         _parent.convertPairsDates();
  713.                     if ($('#dtDustLogs').text() !== "")
  714.                         _parent.convertDustLogDates();
  715.                 },100);
  716.         });
  717.     },
  718.     calcNewDate: function(t) {
  719.         var originalDate = $(t).find("td.date.all").text(),
  720.              militaryTime = originalDate.split('(')[0].split(' ')[1],
  721.              mDY = originalDate.split(' ')[0],
  722.              day = originalDate.split('(')[1].split(')')[0],
  723.              amPmTime = this.toDate(militaryTime,"h:m").toLocaleString('en-US',
  724.               { hour: 'numeric', minute: 'numeric', hour12: true }),
  725.              newDate = mDY + ' ' + amPmTime + ' (' + day +')';
  726.              return (originalDate.indexOf('M') != '-1')?originalDate:newDate;
  727.     },
  728.     convertLocalTimeToAMPM: function () {
  729.       var time = this.toDate($("#dvCurrentTime").text(),"h:m"),
  730.        currentServerLocalAMPMTime = time.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });
  731.         $("#dvCurrentTime").hide();
  732.         if ($("#dvCurrentUTCTime").text() !== "")
  733.         {
  734.             if ($("#dvCurrentAMPMTime").text() === "") {
  735.                 $("#dvCurrentTime").after("<span id='dvCurrentAMPMTime'>"+ currentServerLocalAMPMTime +"</span>");
  736.             } else {
  737.                 $("#dvCurrentAMPMTime").text(currentServerLocalAMPMTime);
  738.             }
  739.         }
  740.     },
  741.     convertPairsDates: function () {
  742.         var _parent = this;
  743.         $('#dtPairsLogs tbody tr').each(function() {
  744.             var newDate = _parent.calcNewDate(this);
  745.             $(this).find("td.date.all").text(newDate);
  746.         });
  747.     },
  748.     convertDCADates: function () {
  749.         var _parent = this;
  750.         $('#dtDcaLogs tbody tr').each(function() {
  751.             var newDate = _parent.calcNewDate(this);
  752.             $(this).find("td.date.all").text(newDate);
  753.         });
  754.     },
  755.     convertSalesLogDates: function () {
  756.         var _parent = this;
  757.         $('#dtSalesLog tbody tr').each(function() {
  758.             var newDate = _parent.calcNewDate(this);
  759.             $(this).find("td.date.all").text(newDate);
  760.         });
  761.     },
  762.     convertDustLogDates: function () {
  763.         var _parent = this;
  764.         $('#dtDustLogs tbody tr').each(function() {
  765.             var newDate = _parent.calcNewDate(this);
  766.             $(this).find("td.date.all").text(newDate);
  767.         });
  768.     },
  769.     toDate: function (dStr,format) {
  770.         var now = new Date();
  771.         if (format == "h:m") {
  772.             now.setHours(dStr.substr(0,dStr.indexOf(":")));
  773.             now.setMinutes(dStr.substr(dStr.indexOf(":")+1));
  774.             now.setSeconds(0);
  775.             return now;
  776.         }else
  777.             return "Invalid Format";
  778.     }
  779. };
  780. ConvertLogDates.init();
  781.  
  782.  
  783.  
  784. //Net-Income.js
  785. //Net-Income.js
  786. //Net-Income.js
  787. (function() {
  788.     'use strict';
  789.     $( document ).ready(function() {
  790.  
  791.             //Add a new tile for net income
  792.     var tile =' <div class="text-right">\
  793.              <h3 class=" m-t-10 text-profittd main-text">\
  794.                <b class="counter" id="mTodayNetProfit" title=""></b>\
  795.                <span class="market m-l-5">ETH</span>\
  796.              </h3>\
  797.              <p class="mb-0 text-profittd main-text">Net Profit Today</p>\
  798.              <span class="market-price-calculations text-profittd">\
  799.                <label class="usd-value">\
  800.                  <span class="full-text">Estimated USD Value</span>\
  801.                  <span class="short-text">Est. USD Value</span>\
  802.                </label>\
  803.                <span class="mb-0  main-text" id="mTodayNetProfitUSDValue" title=""></span>\
  804.              </span>\
  805.            </div>\
  806.            <div class="clearfix"></div>\
  807.            ';
  808.     $('#mTodayProfit').parent().parent().parent().append(tile);
  809.         //Get data
  810.         function refresh()
  811.         {
  812.         $.getJSON( "monitoring/data?_="+ (new Date().getTime()), function( data ) {
  813.   var ETH_USD =data.ETHUSDTPrice;
  814.   var profitToday = data.totalProfitToday;
  815.   var todayLoss = getTodayBags(data);
  816.   var todayNetProfit = parseFloat(profitToday) - todayLoss;
  817.   var todayNetUSD = parseFloat($('#mTodayProfitUSDValue').text())*(todayNetProfit/profitToday);
  818.         //console.log('Today profit in coin:'+ profitToday);
  819.         //console.log('Today loss in coin:'+ todayLoss);
  820.         //console.log('Today net profit in coin:'+ todayNetProfit.toFixed(8));
  821.         //console.log('Today net profit in usd:'+todayNetUSD.toFixed(2));
  822.   $('#mTodayNetProfit').text(todayNetProfit.toFixed(8));
  823.   $('#mTodayNetProfitUSDValue').text(todayNetUSD.toFixed(2));
  824. });
  825.         }
  826.         setInterval( refresh,5000);
  827.    });
  828.  
  829.    function isToday(date)
  830.    {
  831.        var tdate = new Date(date.date.year,date.date.month-1,date.date.day, date.time.hour, date.time.minute, date.time.second,0);
  832.  
  833.        var now = new Date();
  834.        tdate = new Date(tdate.getTime()-now.getTimezoneOffset()*60*1000);
  835.        //console.log(now.getFullYear()+'/'+now.getMonth()+'/'+now.getDate());
  836.        return now.getFullYear()==tdate.getFullYear()&&now.getMonth()==tdate.getMonth()&&now.getDate()==tdate.getDate();
  837.     }
  838. function getTodayBags(data){
  839.     var sum = 0.0;
  840.     //Add Pairs Log
  841.     for(i=0; i<data.gainLogData.length; i++)
  842.     {
  843.         var coin = data.gainLogData[i];
  844.         if(isToday(coin.averageCalculator.firstBoughtDate))
  845.         {
  846.         sum = sum + (coin.averageCalculator.totalCost - coin.currentPrice * coin.averageCalculator.totalAmount);
  847.           //  console.log(coin.averageCalculator.firstBoughtDate.date.year+'/'+coin.averageCalculator.firstBoughtDate.date.month+'/'+coin.averageCalculator.firstBoughtDate.date.day);
  848.           //console.log(coin.market+" today loss  is "+ (coin.currentPrice * coin.averageCalculator.totalAmount - coin.averageCalculator.totalCost));
  849.         }
  850.     }
  851.  
  852.     //Add DCA Log
  853.     for(i=0; i<data.dcaLogData.length; i++)
  854.     {
  855.         var coin = data.dcaLogData[i];
  856.         if(isToday(coin.averageCalculator.firstBoughtDate))
  857.         {
  858.         sum = sum + (coin.averageCalculator.totalCost - coin.currentPrice * coin.averageCalculator.totalAmount);
  859.         //console.log(coin.market+" today loss is "+ (coin.currentPrice * coin.averageCalculator.totalAmount - coin.averageCalculator.totalCost));
  860.         }
  861.     }
  862.     //console.log('Total loss:'+sum);
  863.     return sum;
  864. }
  865. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement