Skip to content

Commit 2e29898

Browse files
committed
Price diff for 30d added.
1 parent 8c7ad25 commit 2e29898

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

service/lib/ethplorer.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ public function getTokensTop($limit = 50, $criteria = 'trade', $updateCache = fa
14161416
'volumePrevious' => 0
14171417
);
14181418
$result = $this->oCache->get($cache, false, true);
1419-
if($updateCache || (FALSE === $result)){
1419+
if($updateCache){
14201420
$aTokens = $this->getTokens();
14211421
$result = array();
14221422
$total = 0;
@@ -1584,11 +1584,21 @@ public function getTokensTop($limit = 50, $criteria = 'trade', $updateCache = fa
15841584
if($criteria == 'count') $sortMethod = '_sortByTxCount';
15851585
usort($result, array($this, $sortMethod));
15861586

1587+
$aPrevTotals = $this->oCache->get('top_tokens_totals', FALSE, TRUE);
1588+
$prevTokensNum = 0;
1589+
if(FALSE !== $aPrevTotals){
1590+
$prevTokensNum = $aPrevTotals['tokensWithPrice'];
1591+
}
1592+
if($aTotals['tokensWithPrice'] < $prevTokensNum) $aTotals['tokensWithPrice'] = $prevTokensNum;
1593+
if(($criteria != 'count') && ($aTotals['tokensWithPrice'] > $topLimit)){
1594+
$tokensLimit = $aTotals['tokensWithPrice'];
1595+
}else{
1596+
$tokensLimit = $topLimit;
1597+
}
1598+
15871599
$res = [];
15881600
foreach($result as $i => $item){
1589-
if($i < $topLimit){
1590-
// $item['percentage'] = round(($item['volume'] / $total) * 100);
1591-
1601+
if($i < $tokensLimit){
15921602
// get tx's other trends
15931603
if(($item['address'] != self::ADDRESS_ETH) && $criteria == 'count'){
15941604
unset($aPeriods[0]);
@@ -1613,20 +1623,18 @@ public function getTokensTop($limit = 50, $criteria = 'trade', $updateCache = fa
16131623
$res[] = $item;
16141624
}
16151625
}
1626+
16161627
$aTotals['ts'] = time();
1617-
$aPrevTotals = $this->oCache->get('top_tokens_totals', FALSE, TRUE);
1618-
$prevTokensNum = 0;
1619-
if(FALSE !== $aPrevTotals){
1620-
$prevTokensNum = $aPrevTotals['tokensWithPrice'];
1621-
}
1622-
if($aTotals['tokensWithPrice'] < $prevTokensNum) $aTotals['tokensWithPrice'] = $prevTokensNum;
16231628
$result = array('tokens' => $res, 'totals' => $aTotals);
16241629
$this->oCache->save($cache, $result);
16251630
$this->oCache->save('top_tokens_totals', $aTotals);
16261631
}
1632+
if(FALSE === $result){
1633+
$result = array('tokens' => array());
1634+
}
16271635

16281636
$res = [];
1629-
if($limit < $topLimit){
1637+
if($limit > 0 && $limit < $topLimit){
16301638
foreach($result['tokens'] as $i => $item){
16311639
if($i < $limit){
16321640
$res[] = $item;
@@ -2127,7 +2135,7 @@ public function getBlockTransactions($block, $showZero = false){
21272135

21282136
public function getTokenPrice30d($address){
21292137
$result = FALSE;
2130-
$aTokensTop = $this->getTokensTop(100, 'cap');
2138+
$aTokensTop = $this->getTokensTop(-1, 'cap');
21312139
if(is_array($aTokensTop) && isset($aTokensTop['tokens'])){
21322140
foreach($aTokensTop['tokens'] as $aToken){
21332141
if(($aToken['address'] == $address) && isset($aToken['cap-30d-previous']) && $aToken['cap-30d-previous'] > 0){

0 commit comments

Comments
 (0)