From 925383df63b81d31ba6c30bcf320c89c683b5fe5 Mon Sep 17 00:00:00 2001 From: Steve Jain Date: Thu, 18 Apr 2019 11:18:33 -0400 Subject: [PATCH 1/6] Fix table on main markets page Make all altcoin prices show as BTC with fixed 8 decimals, just like the software. --- js/markets.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/js/markets.js b/js/markets.js index 00ea4992..cec6f364 100644 --- a/js/markets.js +++ b/js/markets.js @@ -78,6 +78,22 @@ function roundToSigFigs( num ) { } } +//get btc price +function getAssetBTCPrice( price, ticker ) { + + var assetBTCPrice = parseFloat( price ); + if( ticker.startsWith( 'btc' ) ) { + return assetBTCPrice.toFixed(2); + } else { + if( assetBTCPrice < 1 ) { + return assetBTCPrice.toFixed(8); + } else { + return assetBTCPrice.toFixed(2); + } + } + +} + //fill past trades table function getTrades( pair ) { @@ -110,10 +126,9 @@ function getTrades( pair ) { $( '' ).append( $( '' ).html( tradeDate.format( dateFormat ) ), $( '' ).text( val.direction + ' ' + buildTicker( val.market ) ), - $( '' ).text( roundToSigFigs( val.price ) + ( val.payment_method.startsWith('BLOCK_CHAINS') ? ' BTC' : ' ' + buildTicker( val.market ) ) ), + $( '' ).text( getAssetBTCPrice( val.price, val.market ) + ( val.payment_method.startsWith('BLOCK_CHAINS') ? ' BTC' : ' ' + buildTicker( val.market ) ) ), $( '' ).text( ( val.payment_method.startsWith('BLOCK_CHAINS') ? roundToSigFigs( val.volume ) : roundToSigFigs( val.amount ) ) ), $( '' ).text( ( val.payment_method.startsWith('BLOCK_CHAINS') ? roundToSigFigs( val.amount ) : roundToSigFigs( val.volume ) ) + ' ' + buildTicker( val.market ) ) - ).appendTo( '#trade-history-body' ); }); @@ -296,6 +311,7 @@ function buildData( jsonUrl ){ rangeSelectorZoom: '' } }); + // create the chart Highcharts.stockChart( 'container', { From b3e64bb3b8157dc859190782dc53d8817b85773f Mon Sep 17 00:00:00 2001 From: Steve Jain Date: Thu, 18 Apr 2019 12:52:39 -0400 Subject: [PATCH 2/6] Fix offers tables in markets section On individual currency pages. --- js/markets.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/js/markets.js b/js/markets.js index cec6f364..641ddb4e 100644 --- a/js/markets.js +++ b/js/markets.js @@ -197,32 +197,32 @@ function getOffers( pair ){ if( pair.startsWith( "btc" ) ) { $( '' ).append( $( '' ).text( 'Price' ), - $( '' ).text( 'Offer Amount (BTC)' ), - $( '' ).text( 'Offer Price (' + ( buildTicker( pair ) + ')' ) ), + $( '' ).text( 'Amount (BTC)' ), + $( '' ).text( 'Amount (' + ( buildTicker( pair ) + ')' ) ), ).appendTo('#buy-offers-header'); $( '' ).append( $( '' ).text( 'Price' ), - $( '' ).text( 'Offer Amount (BTC)' ), - $( '' ).text( 'Offer Price (' + ( buildTicker( pair ) + ')' ) ), + $( '' ).text( 'Amount (BTC)' ), + $( '' ).text( 'Amount (' + ( buildTicker( pair ) + ')' ) ), ).appendTo( '#sell-offers-header' ); } else { $( '' ).append( $( '' ).text( 'Price' ), - $( '' ).text( 'Offer Amount (' + buildTicker( pair ) + ')' ), - $( '' ).text( 'Offer Price (BTC)' ), + $( '' ).text( 'Amount (' + buildTicker( pair ) + ')' ), + $( '' ).text( 'Amount (BTC)' ), ).appendTo('#buy-offers-header'); $( '' ).append( $( '' ).text( 'Price' ), - $( '' ).text( 'Offer Amount (' + buildTicker( pair ) + ')' ), - $( '' ).text( 'Offer Price (BTC)' ), + $( '' ).text( 'Amount (' + buildTicker( pair ) + ')' ), + $( '' ).text( 'Amount (BTC)' ), ).appendTo( '#sell-offers-header' ); } $.each( data[pair].buys, function( key, val ) { $( '' ).append( - $( '' ).text( roundToSigFigs( parseFloat( val.price ) ) ), + $( '' ).text( pair.startsWith( "btc" ) ? parseFloat( val.price ).toFixed(2) : parseFloat( val.price ).toFixed(8) ), $( '' ).text( roundToSigFigs( parseFloat( val.amount ) ) ), $( '' ).text( roundToSigFigs( parseFloat( val.volume ) ) ), ).appendTo('#buy-offers-body'); @@ -230,7 +230,7 @@ function getOffers( pair ){ $.each( data[pair].sells, function( key, val ) { $( '' ).append( - $( '' ).text( roundToSigFigs( parseFloat( val.price ) ) ), + $( '' ).text( pair.startsWith( "btc" ) ? parseFloat( val.price ).toFixed(2) : parseFloat( val.price ).toFixed(8) ), $( '' ).text( roundToSigFigs( parseFloat( val.amount ) ) ), $( '' ).text( roundToSigFigs( parseFloat( val.volume ) ) ), ).appendTo( '#sell-offers-body' ); From 149bd9d24562dcd597c7bcd780f455b6ccce20af Mon Sep 17 00:00:00 2001 From: Steve Jain Date: Fri, 19 Apr 2019 08:31:19 -0400 Subject: [PATCH 3/6] Fix trade history charts Display price in btc with fixed 8 digits of precision. --- js/markets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/markets.js b/js/markets.js index 641ddb4e..e85d6729 100644 --- a/js/markets.js +++ b/js/markets.js @@ -169,7 +169,7 @@ function getTrades( pair ) { $( '' ).append( $( '' ).text( tradeDate.format( dateFormat ) ), $( '' ).text( val.direction + ' ' + actionTicker ), - $( '' ).text( roundToSigFigs( parseFloat( val.price ) ) ), + $( '' ).text( ( val.payment_method.startsWith('BLOCK_CHAINS') ? parseFloat( val.price ).toFixed(8) : roundToSigFigs( parseFloat( val.price ) ) ) ), $( '' ).text( ( val.payment_method.startsWith('BLOCK_CHAINS') ? roundToSigFigs( val.volume ) : roundToSigFigs( val.amount ) ) ), $( '' ).text( ( val.payment_method.startsWith('BLOCK_CHAINS') ? roundToSigFigs( val.amount ) : roundToSigFigs( val.volume ) ) ) ).appendTo('#trade-history-body' ); From 9f301732fdbf7aa5a86064bc0d55250f16fc6c8d Mon Sep 17 00:00:00 2001 From: Steve Jain Date: Fri, 19 Apr 2019 08:50:31 -0400 Subject: [PATCH 4/6] Fix graph titles to match pricing with tables --- js/markets.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/js/markets.js b/js/markets.js index e85d6729..82b78494 100644 --- a/js/markets.js +++ b/js/markets.js @@ -50,16 +50,23 @@ function buildTicker( pair ) { function buildChartTitle( valueFinal, pair ) { + + var chartTitle = ''; + if( pair !== 'btc' ) { - var suffix = ''; - suffix = ' ' + buildTicker( pair ) + ''; - if( !pair.startsWith( "btc" ) ) { - valueFinal = Math.round( ( 1 / valueFinal ) * 100 ) / 100; + + if( pair.startsWith( "btc" ) ) { + suffix = ' ' + buildTicker( pair ) + ''; + chartTitle = '1 BTC' + '' + valueFinal.toFixed(2) + ' ' + buildTicker( pair ) + ''; + } else { + chartTitle = '1 ' + buildTicker( pair ) + '' + '' + valueFinal.toFixed(8) + ' BTC'; } - return '1 BTC' + '' + roundToSigFigs( valueFinal ) + '' + suffix; + } else { - return 'Volume and' + 'Trades'; + chartTitle = 'Volume and' + 'Trades'; } + + return chartTitle; } From ab7392e6063f7ac0da8761376b85120550bbe787 Mon Sep 17 00:00:00 2001 From: Steve Jain Date: Fri, 19 Apr 2019 11:29:14 -0400 Subject: [PATCH 5/6] Fix chart titles, data series, and tooltips --- js/markets.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/js/markets.js b/js/markets.js index 82b78494..fee58567 100644 --- a/js/markets.js +++ b/js/markets.js @@ -254,6 +254,10 @@ function getOffers( pair ){ function buildData( jsonUrl ){ var jsonUrl = ""; + var seriesTitle1 = 'Price'; + var avg = []; + var volume = []; + var volumeFiat = []; if( !pair || pair === 'all' ) { @@ -272,11 +276,8 @@ function buildData( jsonUrl ){ $.getJSON( jsonUrl, function( data ) { //split the data set into hloc and volume - var seriesTitle1 = 'Price'; - var dataLength = data.length; - var avg = []; var volume = []; - for( var i = 0; i < dataLength; i += 1 ) { + for( var i = 0; i < data.length; i += 1 ) { if( pair === 'btc' ) { @@ -293,17 +294,26 @@ function buildData( jsonUrl ){ seriesTitle1 = '# of trades'; } else { + if( pair.startsWith( "btc" ) ) { avg.push([ data[i][0] * 1000, // the date data[i][7] // the average ]); + + volumeFiat.push([ + data[i][0] * 1000, // the date + data[i][6] // the volume_left + ]); + } else { + avg.push([ data[i][0] * 1000, // the date - ( 1 / data[i][7] ) // the average + ( data[i][7] ) // the average ]); } + volume.push([ data[i][0] * 1000, // the date data[i][6] // the volume_right @@ -311,8 +321,6 @@ function buildData( jsonUrl ){ } } - - Highcharts.setOptions({ lang: { rangeSelectorZoom: '' @@ -385,7 +393,7 @@ function buildData( jsonUrl ){ }, title: { - text: buildChartTitle(data[dataLength-1][7], pair), + text: buildChartTitle(data[data.length-1][7], pair), align: 'left', x:20, y:30, @@ -439,7 +447,7 @@ function buildData( jsonUrl ){ { labels: { y: -5, - x: -48, + x: -58, //align: 'left', //x: -140, //enabled: false, @@ -498,11 +506,10 @@ function buildData( jsonUrl ){ series: [ { - type: 'area', type: 'line', name: seriesTitle1, tooltip: { - pointFormat: '{series.name}: ' + ' ' + ( pair === 'btc' ? '{point.y:.0f}' : '{point.y:.2f}' ) + '', + pointFormat: '{series.name}: ' + ' ' + ( pair === 'btc' ? '{point.y:.0f}' : ( pair.startsWith('btc') ? '{point.y:.2f}' : '{point.y:.8f}' ) ) + '', }, data: avg, yAxis: 1, @@ -527,10 +534,10 @@ function buildData( jsonUrl ){ name: 'Volume', tooltip: { pointFormatter: function() { - return '' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 2, '.', ',') + ' ' + buildTicker( pair ) + ''; + return '' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 2, '.', ',') + ( pair.startsWith('btc') ? ' ' + buildTicker(pair) : ' BTC' ) + ''; } }, - data: volume, + data: ( pair.startsWith('btc') ? volumeFiat: volume ), color: '#bbb', states: { hover: { color: '#aaa', duration: 0 } }, yAxis: 1, From c63ce809d07fc555d2e942b8c7f1423e77e27b30 Mon Sep 17 00:00:00 2001 From: Steve Jain Date: Fri, 19 Apr 2019 12:01:51 -0400 Subject: [PATCH 6/6] Fix bug with volume on main markets page --- js/markets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/markets.js b/js/markets.js index fee58567..6171d937 100644 --- a/js/markets.js +++ b/js/markets.js @@ -537,7 +537,7 @@ function buildData( jsonUrl ){ return '' + this.series.name + ': ' + Highcharts.numberFormat(this.y, 2, '.', ',') + ( pair.startsWith('btc') ? ' ' + buildTicker(pair) : ' BTC' ) + ''; } }, - data: ( pair.startsWith('btc') ? volumeFiat: volume ), + data: ( pair === 'btc' ? volume : ( pair.startsWith('btc') ? volumeFiat : volume ) ), color: '#bbb', states: { hover: { color: '#aaa', duration: 0 } }, yAxis: 1,