· 7 years ago · Oct 09, 2018, 02:02 AM
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> <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//Advanced-Exchange.js
460//Advanced-Exchange.js
461//Advanced-Exchange.js
462function AdvancedExchange() {
463 $("table td.market.all a").each(function() {
464 var value = $(this).attr("href");
465 var exchanges = ["BTC", "ETH", "BNB", "USDT"];
466 var newSymbol = "";
467 var exchange = "BINANCE";
468 var queryParams = new URLSearchParams($(this).prop("search"));
469
470 var symbolParam = queryParams.get("symbol");
471 if (symbolParam == null) { // Try to parse for Bittrex
472 exchange = "BITTREX";
473 var symbolParam = queryParams.get("MarketName");
474 symbolParam = symbolParam.split("-").reverse().join("");
475 }
476
477 $.each(exchanges, (function(i, exchange) {
478 var parts = symbolParam.split(exchange);
479
480 if(parts[1] === "") {
481 newSymbol = parts[0].replace("_", "") + "_" + exchange;
482 return false;
483 }
484 }));
485
486 $(this).siblings(".trading-view").remove();
487 $(this).unwrap("span");
488 $(this).wrap("<span class=\"market-wrapper\" style=\"white-space:nowrap;\"></span>");
489 $(this).parent().append("<span class=\"trading-view\" style=\"margin-left:5px;\"><a href=\"https://www.tradingview.com/chart/?symbol=" + exchange + ":" + symbolParam.replace("_", "") + "\" target=\"_blank\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"25\"viewBox=\"0 0 33 19\"><path fill=\"#3BB3E4\" d=\"M29.032 7.382a5.47 5.47 0 0 1 .963 2.872A4.502 4.502 0 0 1 28.5 19H6a5.98 5.98 0 0 1-4.222-1.737l9.546-7.556c.35.187.75.293 1.176.293a2.49 2.49 0 0 0 1.066-.238l4.55 3.981a2.5 2.5 0 1 0 4.711-.157l6.205-6.204zm-1.414-1.414l-6.204 6.204A2.494 2.494 0 0 0 20.5 12a2.49 2.49 0 0 0-1.066.238l-4.55-3.981a2.5 2.5 0 1 0-4.801-.118L.608 15.638A6 6 0 0 1 6.061 7a8.001 8.001 0 0 1 15.625-1.227A5.474 5.474 0 0 1 24.5 5c1.157 0 2.231.358 3.118.968z\"></path></svg></a></span>");
490
491 queryParams.set("symbol", newSymbol);
492
493 $(this).attr("href", value.replace("www.binance.com/trade.html","www.binance.com/tradeDetail.html"));
494 $(this).prop("search", "?" + queryParams.toString());
495 });
496}
497
498$("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
499 AdvancedExchange();
500});
501$(".dca-log, .pairs-log, .dust-log, .sales-log, .pending-log, .possible-buys-log").on("click", function() {
502 setTimeout(function(){ AdvancedExchange(); }, 100 );
503});
504
505//Estimated-Percent-Gain.js
506//Estimated-Percent-Gain.js
507//Estimated-Percent-Gain.js
508function estimateYesterdayPercent() {
509 var previousTCV = $("#mTotalCurrentVal").text() - $("#mTodayProfit").text();
510 var prevPercentCalc = ($("#mYesterdayProfit").text()/previousTCV*100).toFixed(2);
511 var prevPercent = prevPercentCalc + '%';
512 if ($("#mYesterdayProfit").text() !== "")
513 {
514 if ($("#mYesterdayProfitPCTValue").text() === "") {
515 $("span.market-price-calculations.text-profityd").append('<br><label class="usd-value"><span class="full-text">Estimated Percent Gain </span><span class="short-text">Est. % Gain </span></label><span class="mb-0 main-text" id="mYesterdayProfitPCTValue" title="'+prevPercent+'">'+prevPercent+'</span>');
516 } else {
517 $("#mYesterdayProfitPCTValue").attr("title",prevPercent);
518 $("#mYesterdayProfitPCTValue").text(prevPercent);
519 }
520 }
521}
522
523function estimatePercent() {
524 var todayPercentCalc = ($("#mTodayProfit").text()/$("#mTotalCurrentVal").text()*100).toFixed(2);
525 var todayPercent = todayPercentCalc + '%';
526 $(".usd-value").css({'margin-bottom':'0px'});
527 if ($("#mTodayProfit").text() !== "")
528 {
529 if ($("#mTodayProfitPCTValue").text() === "") {
530 $("span.market-price-calculations.text-profittd").append('<br><label class="usd-value"><span class="full-text">Estimated Percent Gain </span><span class="short-text">Est. % Gain </span></label><span class="mb-0 main-text" id="mTodayProfitPCTValue" title="'+todayPercent+'">'+todayPercent+'</span>');
531 } else {
532 $("#mTodayProfitPCTValue").attr("title",todayPercent);
533 $("#mTodayProfitPCTValue").text(todayPercent);
534 }
535 }
536}
537
538estimateYesterdayPercent();
539$("body").on('DOMSubtreeModified', "#mYesterdayProfitUSDValue", function() {
540 estimateYesterdayPercent();
541});
542
543estimatePercent();
544$("body").on('DOMSubtreeModified', "#mTodayProfitUSDValue", function() {
545 estimatePercent();
546});
547
548
549
550//USD-Estimate.js
551//USD-Estimate.js
552//USD-Estimate.js
553function estimate() {
554 var btc1 = $('#nMarketPrice').attr("title");
555 $("#dtDcaLogs th.total-cost").text('Estimated Value');
556 $('.summary-table').removeClass('col-md-3').removeClass('col-md-4').addClass('col-md-4');
557 //DCA
558 if ($('#dtDcaLogs thead').length > 0) {
559 if ($('#dtDcaLogs thead .est-usd').length < 1) {
560 $('#dtDcaLogs thead tr').append('<th class="text-right est-usd all sorting" rowspan="1" colspan="1" style="width: 92px;">Estimated Value</th>');
561 };
562 $('#dtDcaLogs tbody tr').each(function() {
563 $(this).find('.est-usd').remove();
564 $(this).append('<td class="text-right est-usd all"></td>');
565 var num1 = $(this).find('.current-value').html().split("<br>")[1];
566 var num2 = $(this).find('.current-value').html().split("<br>")[0];
567 var calc = num2 - num1;
568 var btc = calc.toFixed(8);
569 var usd = btc * btc1;
570 var difference = usd.toFixed(2);
571 var sta = num2 * btc1;
572 var total = sta.toFixed(2);
573 if (difference > 0) {
574 $(this).find('.est-usd').html('<span style="color:#05b16f;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
575 } else {
576 $(this).find('.est-usd').html('<span style="color:#d85353;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
577 }
578 });
579 $("#dcLogDifference").find('b').remove();
580 $("#dcLogTotalCurrentVal").find('b').remove();
581 $("#dcLogRealCost").find('b').remove();
582 var val = $('#dcLogTotalCurrentVal').text();
583 var bou = $('#dcLogRealCost').text();
584 var calc = val - bou;
585 var btc = calc.toFixed(8);
586 var est = bou * btc1;
587 var bought = est.toFixed(2);
588 var usd = btc * btc1;
589 var difference = usd.toFixed(2);
590 var sta = val * btc1;
591 var total = sta.toFixed(2);
592 $("#dcLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
593 $("#dcLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
594 $("#dcLogRealCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
595 }
596 //Pairs
597 if ($('#dtPairsLogs thead').length > 0) {
598 if ($('#dtPairsLogs thead .est-usd').length < 1) {
599 $('#dtPairsLogs thead tr').append('<th class="text-right est-usd all sorting" rowspan="1" colspan="1" style="width: 92px;">Estimated Value</th>');
600 }
601 $('#dtPairsLogs tbody tr').each(function() {
602 $(this).find('.est-usd').remove();
603 $(this).append('<td class=" text-right est-usd all"></td>');
604 var num1 = $(this).find('.bought-cost').text();
605 var num2 = $(this).find('.current-value').text();
606 var calc = num2 - num1;
607 var btc = calc.toFixed(8);
608 var usd = btc * btc1;
609 var difference = usd.toFixed(2);
610 var sta = num2 * btc1;
611 var total = sta.toFixed(2);
612 if (difference > 0) {
613 $(this).find('.est-usd').html('<span style="color:#05b16f;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
614 } else {
615 $(this).find('.est-usd').html('<span style="color:#d85353;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
616 }
617 });
618 $("#pairsLogDifference").find('b').remove();
619 $("#pairsLogTotalCurrentVal").find('b').remove();
620 $("#pairsLogRealCost").find('b').remove();
621 var val = $('#pairsLogTotalCurrentVal').text();
622 var bou = $('#pairsLogRealCost').text();
623 var calc = val - bou;
624 var btc = calc.toFixed(8);
625 var est = bou * btc1;
626 var bought = est.toFixed(2);
627 var usd = btc * btc1;
628 var difference = usd.toFixed(2);
629 var sta = val * btc1;
630 var total = sta.toFixed(2);
631 $("#pairsLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
632 $("#pairsLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
633 $("#pairsLogRealCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
634 }
635 //Dust
636 if ($('#dtDustLogs thead').length > 0) {
637 if ($('#dtDustLogs thead .est-usd').length < 1) {
638 $('#dtDustLogs thead tr').append('<th class="text-right est-usd all sorting" rowspan="1" colspan="1" style="width: 92px;">Estimated Value</th>');
639 }
640 $('#dtDustLogs tbody tr').each(function() {
641 $(this).find('.est-usd').remove();
642 $(this).append('<td class=" text-right est-usd all"></td>');
643 var num1 = $(this).find('.bought-cost').text();
644 var num2 = $(this).find('.current-value').text();
645 var calc = num2 - num1;
646 var btc = calc.toFixed(8);
647 var usd = btc * btc1;
648 var difference = usd.toFixed(2);
649 var sta = num2 * btc1;
650 var total = sta.toFixed(2);
651 if (difference > 0) {
652 $(this).find('.est-usd').html('<span style="color:#05b16f;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
653 } else {
654 $(this).find('.est-usd').html('<span style="color:#d85353;"><i style="color:#98a6ad;font-style:normal;">$' + total + '</i><br>$' + difference + '</span>');
655 }
656 });
657 $("#dustLogDifference").find('b').remove();
658 $("#dustLogTotalCurrentVal").find('b').remove();
659 $("#dustLogRealCost").find('b').remove();
660 var val = $('#dustLogTotalCurrentVal').text();
661 var bou = $('#dustLogRealCost').text();
662 var calc = val - bou;
663 var btc = calc.toFixed(8);
664 var est = bou * btc1;
665 var bought = est.toFixed(2);
666 var usd = btc * btc1;
667 var difference = usd.toFixed(2);
668 var sta = val * btc1;
669 var total = sta.toFixed(2);
670 $("#dustLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
671 $("#dustLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
672 $("#dustLogRealCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
673 }
674 //Sales
675 if ($('#dtSalesLog thead').length > 0) {
676 $("#salesLogDifference").find('b').remove();
677 $("#salesLogTotalCurrentVal").find('b').remove();
678 $("#salesLogBoughtCost").find('b').remove();
679 var val = $('#salesLogTotalCurrentVal').text();
680 var bou = $('#salesLogBoughtCost').text();
681 var calc = val - bou;
682 var btc = calc.toFixed(8);
683 var est = bou * btc1;
684 var bought = est.toFixed(2);
685 var usd = btc * btc1;
686 var difference = usd.toFixed(2);
687 var sta = val * btc1;
688 var total = sta.toFixed(2);
689 $("#salesLogDifference").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:5px">($' + difference + ')</b>');
690 $("#salesLogTotalCurrentVal").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + total + ')</b>');
691 $("#salesLogBoughtCost").prepend('<b style="color:#98a6ad;font-weight:400;margin-right:8px">($' + bought + ')</b>');
692 }
693 //Balance
694 $('.ticker-text').css('position','relative');
695 $('#nBalanceVal span').remove();
696 var btc = $('#nBalanceVal').attr("title");
697 var usd = btc * btc1;
698 var total = usd.toFixed(2);
699 $('#nBalanceVal').append('<span style="display:inline-block;position:absolute;bottom:-8px;right:0;font-size: 10px">($'+total+')</span>');
700 //Current
701 $('#nTotalCurrentVal span').remove();
702 var btc = $('#nTotalCurrentVal').attr("title");
703 var usd = btc * btc1;
704 var total = usd.toFixed(2);
705 $('#nTotalCurrentVal').append('<span style="display:inline-block;position:absolute;bottom:-8px;right:0;font-size: 10px">($'+total+')</span>');
706 //Pending
707 $('#nTotalPendingVal span').remove();
708 var btc = $('#nTotalPendingVal').attr("title");
709 var usd = btc * btc1;
710 var total = usd.toFixed(2);
711 $('#nTotalPendingVal').append('<span style="display:inline-block;position:absolute;bottom:-8px;right:0;font-size: 10px">($'+total+')</span>');
712}
713$("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
714 estimate();
715});
716$(".dca-log, .pairs-log, .dust-log, .sales-log").on("click", function() {
717 setTimeout(function() {
718 estimate();
719 }, 100);
720});
721$( document ).ready(function() {
722 setTimeout(function() {
723 estimate();
724 }, 100);
725});
726
727
728//Convert-Time-AM-PM.js
729//Convert-Time-AM-PM.js
730//Convert-Time-AM-PM.js
731var ConvertLogDates = {
732 init: function () {
733 var _parent = this;
734 $("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
735 if ($('#dtDcaLogs').text() !== "")
736 _parent.convertDCADates();
737
738 if ($('#dtPairsLogs').text() !== "")
739 _parent.convertPairsDates();
740
741 if ($('#dtSalesLog').text() !== "")
742 _parent.convertSalesLogDates();
743
744 if ($('#dtDustLogs').text() !== "")
745 _parent.convertDustLogDates();
746 });
747 $("body").on('DOMSubtreeModified', "#dvCurrentUTCTime", function() {
748 _parent.convertLocalTimeToAMPM();
749 });
750
751 $(document).on("click",".dca-log, .pairs-log, .dust-log, .sales-log, th.date.all, .page-link, .page-item, .sorting_asc, .sorting_desc", function() {
752 setTimeout(function(){
753 if ($('#dtSalesLog').text() !== "")
754 _parent.convertSalesLogDates();
755 if ($('#dtDcaLogs').text() !== "")
756 _parent.convertDCADates();
757 if ($('#dtPairsLogs').text() !== "")
758 _parent.convertPairsDates();
759 if ($('#dtDustLogs').text() !== "")
760 _parent.convertDustLogDates();
761 },100);
762 });
763 },
764 calcNewDate: function(t) {
765 var originalDate = $(t).find("td.date.all").text(),
766 militaryTime = originalDate.split('(')[0].split(' ')[1],
767 mDY = originalDate.split(' ')[0],
768 day = originalDate.split('(')[1].split(')')[0],
769 amPmTime = this.toDate(militaryTime,"h:m").toLocaleString('en-US',
770 { hour: 'numeric', minute: 'numeric', hour12: true }),
771 newDate = mDY + ' ' + amPmTime + ' (' + day +')';
772 return (originalDate.indexOf('M') != '-1')?originalDate:newDate;
773 },
774 convertLocalTimeToAMPM: function () {
775 var time = this.toDate($("#dvCurrentTime").text(),"h:m"),
776 currentServerLocalAMPMTime = time.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });
777 $("#dvCurrentTime").hide();
778 if ($("#dvCurrentUTCTime").text() !== "")
779 {
780 if ($("#dvCurrentAMPMTime").text() === "") {
781 $("#dvCurrentTime").after("<span id='dvCurrentAMPMTime'>"+ currentServerLocalAMPMTime +"</span>");
782 } else {
783 $("#dvCurrentAMPMTime").text(currentServerLocalAMPMTime);
784 }
785 }
786 },
787 convertPairsDates: function () {
788 var _parent = this;
789 $('#dtPairsLogs tbody tr').each(function() {
790 var newDate = _parent.calcNewDate(this);
791 $(this).find("td.date.all").text(newDate);
792 });
793 },
794 convertDCADates: function () {
795 var _parent = this;
796 $('#dtDcaLogs tbody tr').each(function() {
797 var newDate = _parent.calcNewDate(this);
798 $(this).find("td.date.all").text(newDate);
799 });
800 },
801 convertSalesLogDates: function () {
802 var _parent = this;
803 $('#dtSalesLog tbody tr').each(function() {
804 var newDate = _parent.calcNewDate(this);
805 $(this).find("td.date.all").text(newDate);
806 });
807 },
808 convertDustLogDates: function () {
809 var _parent = this;
810 $('#dtDustLogs tbody tr').each(function() {
811 var newDate = _parent.calcNewDate(this);
812 $(this).find("td.date.all").text(newDate);
813 });
814 },
815 toDate: function (dStr,format) {
816 var now = new Date();
817 if (format == "h:m") {
818 now.setHours(dStr.substr(0,dStr.indexOf(":")));
819 now.setMinutes(dStr.substr(dStr.indexOf(":")+1));
820 now.setSeconds(0);
821 return now;
822 }else
823 return "Invalid Format";
824 }
825};
826ConvertLogDates.init();
827
828
829
830//Net-Income.js
831//Net-Income.js
832//Net-Income.js
833(function() {
834 'use strict';
835 $( document ).ready(function() {
836
837 //Add a new tile for net income
838 var tile =' <div class="text-right">\
839 <h3 class=" m-t-10 text-profittd main-text">\
840 <b class="counter" id="mTodayNetProfit" title=""></b>\
841 <span class="market m-l-5">ETH</span>\
842 </h3>\
843 <p class="mb-0 text-profittd main-text">Net Profit Today</p>\
844 <span class="market-price-calculations text-profittd">\
845 <label class="usd-value">\
846 <span class="full-text">Estimated USD Value</span>\
847 <span class="short-text">Est. USD Value</span>\
848 </label>\
849 <span class="mb-0 main-text" id="mTodayNetProfitUSDValue" title=""></span>\
850 </span>\
851 </div>\
852 <div class="clearfix"></div>\
853 ';
854 $('#mTodayProfit').parent().parent().parent().append(tile);
855 //Get data
856 function refresh()
857 {
858 $.getJSON( "monitoring/data?_="+ (new Date().getTime()), function( data ) {
859 var ETH_USD =data.ETHUSDTPrice;
860 var profitToday = data.totalProfitToday;
861 var todayLoss = getTodayBags(data);
862 var todayNetProfit = parseFloat(profitToday) - todayLoss;
863 var todayNetUSD = parseFloat($('#mTodayProfitUSDValue').text())*(todayNetProfit/profitToday);
864 //console.log('Today profit in coin:'+ profitToday);
865 //console.log('Today loss in coin:'+ todayLoss);
866 //console.log('Today net profit in coin:'+ todayNetProfit.toFixed(8));
867 //console.log('Today net profit in usd:'+todayNetUSD.toFixed(2));
868 $('#mTodayNetProfit').text(todayNetProfit.toFixed(8));
869 $('#mTodayNetProfitUSDValue').text(todayNetUSD.toFixed(2));
870});
871 }
872 setInterval( refresh,5000);
873 });
874
875 function isToday(date)
876 {
877 var tdate = new Date(date.date.year,date.date.month-1,date.date.day, date.time.hour, date.time.minute, date.time.second,0);
878
879 var now = new Date();
880 tdate = new Date(tdate.getTime()-now.getTimezoneOffset()*60*1000);
881 //console.log(now.getFullYear()+'/'+now.getMonth()+'/'+now.getDate());
882 return now.getFullYear()==tdate.getFullYear()&&now.getMonth()==tdate.getMonth()&&now.getDate()==tdate.getDate();
883 }
884function getTodayBags(data){
885 var sum = 0.0;
886 //Add Pairs Log
887 for(i=0; i<data.gainLogData.length; i++)
888 {
889 var coin = data.gainLogData[i];
890 if(isToday(coin.averageCalculator.firstBoughtDate))
891 {
892 sum = sum + (coin.averageCalculator.totalCost - coin.currentPrice * coin.averageCalculator.totalAmount);
893 // console.log(coin.averageCalculator.firstBoughtDate.date.year+'/'+coin.averageCalculator.firstBoughtDate.date.month+'/'+coin.averageCalculator.firstBoughtDate.date.day);
894 //console.log(coin.market+" today loss is "+ (coin.currentPrice * coin.averageCalculator.totalAmount - coin.averageCalculator.totalCost));
895 }
896 }
897
898 //Add DCA Log
899 for(i=0; i<data.dcaLogData.length; i++)
900 {
901 var coin = data.dcaLogData[i];
902 if(isToday(coin.averageCalculator.firstBoughtDate))
903 {
904 sum = sum + (coin.averageCalculator.totalCost - coin.currentPrice * coin.averageCalculator.totalAmount);
905 //console.log(coin.market+" today loss is "+ (coin.currentPrice * coin.averageCalculator.totalAmount - coin.averageCalculator.totalCost));
906 }
907 }
908 //console.log('Total loss:'+sum);
909 return sum;
910}
911})();
912
913function AdvancedExchange() {
914// Modifies Binance coin links to Advanced view, and adds icon link to TradingView for ProfitTrailer v2 GUI
915 $("table td.market a").each(function() {
916 var value = $(this).attr("href");
917 var exchanges = ["BTC", "ETH", "BNB", "USDT"];
918 var newSymbol = "";
919 var exchange = "BINANCE";
920 var queryParams = new URLSearchParams($(this).prop("search"));
921
922 var symbolParam = queryParams.get("symbol");
923 if (symbolParam === null) { // Try to parse for Bittrex
924 exchange = "BITTREX";
925 symbolParam = queryParams.get("MarketName");
926 symbolParam = symbolParam.split("-").reverse().join("");
927 }
928
929 $.each(exchanges, (function(i, exchange) {
930 var parts = symbolParam.split(exchange);
931
932 if(parts[1] === "") {
933 newSymbol = parts[0].replace("_", "") + "_" + exchange;
934 return false;
935 }
936 }));
937
938 $(this).siblings(".trading-view").remove();
939 $(this).unwrap("span");
940 $(this).wrap("<span class=\"market-wrapper\" style=\"white-space:nowrap;\"></span>");
941 $(this).parent().append("<span class=\"trading-view\" style=\"margin-left:5px;\"><a href=\"https://www.tradingview.com/chart/?symbol=" + exchange + ":" + symbolParam.replace("_", "") + "\" target=\"_blank\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"25\"viewBox=\"0 0 33 19\"><path fill=\"#3BB3E4\" d=\"M29.032 7.382a5.47 5.47 0 0 1 .963 2.872A4.502 4.502 0 0 1 28.5 19H6a5.98 5.98 0 0 1-4.222-1.737l9.546-7.556c.35.187.75.293 1.176.293a2.49 2.49 0 0 0 1.066-.238l4.55 3.981a2.5 2.5 0 1 0 4.711-.157l6.205-6.204zm-1.414-1.414l-6.204 6.204A2.494 2.494 0 0 0 20.5 12a2.49 2.49 0 0 0-1.066.238l-4.55-3.981a2.5 2.5 0 1 0-4.801-.118L.608 15.638A6 6 0 0 1 6.061 7a8.001 8.001 0 0 1 15.625-1.227A5.474 5.474 0 0 1 24.5 5c1.157 0 2.231.358 3.118.968z\"></path></svg></a></span>");
942
943 queryParams.set("symbol", newSymbol);
944
945 $(this).attr("href", value.replace("www.binance.com/trade.html","www.binance.com/tradeDetail.html"));
946 $(this).prop("search", "?" + queryParams.toString());
947 });
948}
949
950$("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
951 AdvancedExchange();
952});
953$(".has-submenu").on("click", function() {
954 setTimeout(function(){ AdvancedExchange(); }, 100 );
955});
956
957//Estimated USD difference for Profit Trailer 2.0
958//Created by ProfitTanker#0156 - If you need any help send me a DM.
959function estimate() {
960 //Pairs
961 if ($('#dtPairsLogs thead').length > 0) {
962 $('#dtPairsLogs tbody tr').each(function() {
963 $(this).find('b').remove();
964 var difference = ($(this).find('td.bought-cost:last .current-value').text().replace("$", "").replace(",", "") - $(this).find('td.bought-cost:last .bought-cost').text().replace("$", "").replace(",", "")).toFixed(2);
965 var difference2 = ($(this).find('td.current-value.blue-color:first .current-value').text().replace("$", "").replace(",", "") - $(this).find('td.current-value.blue-color:first .bought-cost').text().replace("$", "").replace(",", "")).toFixed(8);
966 if (difference2 > 0) {
967 $(this).find('td.bought-cost:last .bought-cost').append('<b style="color:#05b16f;border-top: 1px solid;"><br>$' + difference.toLocaleString() + '</b>');
968 $(this).find('td.current-value.blue-color:first .bought-cost').append('<b style="color:#05b16f;border-top: 1px solid;"><br>' + difference2 + '</b>');
969 } else {
970 $(this).find('td.bought-cost:last .bought-cost').append('<b style="color:#d85353;border-top: 1px solid;"><br>$' + difference.toLocaleString() + '</b>');
971 $(this).find('td.current-value.blue-color:first .bought-cost').append('<b style="color:#d85353;border-top: 1px solid;"><br>' + difference2 + '</b>');
972 }
973 });
974 }
975 //DCA
976 if ($('#dtDcaLogs thead').length > 0) {
977 $('#dtDcaLogs tbody tr').each(function() {
978 $(this).find('b').remove();
979 var difference = ($(this).find('td.current-value:last .current-value').text().replace("$", "").replace(",", "") - $(this).find('td.current-value:last .bought-cost').text().replace("$", "").replace(",", "")).toFixed(2);
980 var difference2 = ($(this).find('td.current-value.blue-color:first .current-value').text().replace("$", "").replace(",", "") - $(this).find('td.current-value.blue-color:first .bought-cost').text().replace("$", "").replace(",", "")).toFixed(8);
981 if (difference2 > 0) {
982 $(this).find('td.current-value:last').append('<b style="color:#05b16f;border-top: 1px solid;"><br>$' + difference.toLocaleString() + '</b>');
983 $(this).find('td.current-value.blue-color:first').append('<b style="color:#05b16f;border-top: 1px solid;"><br>' + difference2 + '</b>');
984 } else {
985 $(this).find('td.current-value:last').append('<b style="color:#d85353;border-top: 1px solid;"><br>$' + difference.toLocaleString() + '</b>');
986 $(this).find('td.current-value.blue-color:first').append('<b style="color:#d85353;border-top: 1px solid;"><br>' + difference2 + '</b>');
987 }
988 });
989 }
990 //Dust
991 if ($('#dtDustLogs thead').length > 0) {
992 $('#dtDustLogs tbody tr').each(function() {
993 $(this).find('b').remove();
994 var difference = ($(this).find('td.bought-cost .current-value').text().replace("$", "").replace(",", "") - $(this).find('td.bought-cost .bought-cost').text().replace("$", "").replace(",", "")).toFixed(2);
995 var difference2 = ($(this).find('td.blue-color.current-value:first .current-value').text().replace("$", "").replace(",", "") - $(this).find('td.blue-color.current-value:first .bought-cost').text().replace("$", "").replace(",", "")).toFixed(8);
996 if (difference2 > 0) {
997 $(this).find('td.bought-cost .bought-cost').append('<b style="color:#05b16f;border-top: 1px solid;"><br>$' + difference.toLocaleString() + '</b>');
998 $(this).find('td.blue-color.current-value:first').append('<b style="color:#05b16f;border-top: 1px solid;"><br>' + difference2 + '</b>');
999 } else {
1000 $(this).find('td.bought-cost .bought-cost').append('<b style="color:#d85353;border-top: 1px solid;"><br>$' + difference.toLocaleString() + '</b>');
1001 $(this).find('td.blue-color.current-value:first').append('<b style="color:#d85353;border-top: 1px solid;"><br>' + difference2 + '</b>');
1002 }
1003 });
1004 }
1005}
1006$("body").on('DOMSubtreeModified', "#dvLastUpdatedOn", function() {
1007 estimate();
1008});
1009$('#topNav a').on("click", function() {
1010 setTimeout(function() {
1011 estimate();
1012 }, 100);
1013});