From 21746e5953fef485e16efcb186d9254e9cb8ea19 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 25 Apr 2016 11:19:45 +0200 Subject: [PATCH] history: allow to watch local price/balance also show graphes even if the wallet is not installed (like BTC or LTC) + yaamp "core" function to know if a coin is watched --- web/yaamp/core/backend/markets.php | 18 ++++++++- web/yaamp/core/functions/yaamp.php | 5 +++ web/yaamp/modules/site/coin_results.php | 13 +++++-- .../site/results/graph_market_balance.php | 39 ++++++++++++------- .../site/results/graph_market_prices.php | 18 +++++++-- 5 files changed, 70 insertions(+), 23 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index f53d63d..9532bfc 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -100,6 +100,16 @@ function BackendWatchMarkets($marketname=NULL) $mh->balance = dboscalar("SELECT SUM(balance) AS btc FROM balances"); $mh->save(); continue; + } else if ($coin->installed) { + // "yiimp" prices and balance history + $mh = new db_market_history; + $mh->time = time(); + $mh->idcoin = $coin->id; + $mh->idmarket = NULL; + $mh->price = $coin->price; + $mh->price2 = $coin->price2; + $mh->balance = $coin->balance; + $mh->save(); } // user watched currencies @@ -115,7 +125,6 @@ function BackendWatchMarkets($marketname=NULL) $mh->price2 = $market->price2; $mh->balance = (double) ($market->balance) + (double) ($market->ontrade); $mh->save(); - //debuglog("{$coin->symbol} {$market->name} market history"); } } } @@ -530,7 +539,12 @@ function updateCCexMarkets() } if ($market->disabled < 9) $market->disabled = !$ticker['IsActive']; - if ($symbol == 'DCR') $market->disabled = 9; // manually disabled + + // manually disabled, wrong api data since months + if ($symbol == 'DCR') { + $market->delete(); + continue; + } $market->save(); diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index f88e7b4..f23548d 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -242,6 +242,11 @@ function yaamp_hashrate_step() return 300; } +function yaamp_watched_coin($symbol) +{ + return (strpos(",".YIIMP_WATCH_CURRENCIES.",", ",$symbol,") !== false); +} + function yaamp_profitability($coin) { if(!$coin->difficulty) return 0; diff --git a/web/yaamp/modules/site/coin_results.php b/web/yaamp/modules/site/coin_results.php index a85b38b..7710bc6 100644 --- a/web/yaamp/modules/site/coin_results.php +++ b/web/yaamp/modules/site/coin_results.php @@ -52,7 +52,7 @@ echo << end; -$list = getdbolist('db_markets', "coinid={$coin->id} ORDER BY disabled, priority, price DESC"); +$list = getdbolist('db_markets', "coinid={$coin->id} ORDER BY disabled, priority DESC, price DESC"); $bestmarket = getBestMarket($coin); foreach($list as $market) @@ -175,8 +175,13 @@ echo ''.$coin->algo.''; if(!$info) { - echo "ERROR $remote->error"; - echo ""; + echo 'ERROR '.$remote->error.''; + echo ''.bitcoinvaluetoa($coin->price).''; + echo ''; + echo "
"; + if (yaamp_watched_coin($coin->symbol)) { + $this->renderPartial('coin_market_graph', array('coin'=>$coin)); + } return; } @@ -426,6 +431,6 @@ if (empty($sums)) { echo ''; -if (strpos(YIIMP_WATCH_CURRENCIES, $coin->symbol) !== false) { +if (yaamp_watched_coin($coin->symbol)) { $this->renderPartial('coin_market_graph', array('coin'=>$coin)); } diff --git a/web/yaamp/modules/site/results/graph_market_balance.php b/web/yaamp/modules/site/results/graph_market_balance.php index 8866ffe..53c8fb1 100644 --- a/web/yaamp/modules/site/results/graph_market_balance.php +++ b/web/yaamp/modules/site/results/graph_market_balance.php @@ -11,7 +11,7 @@ $t = time() - 7*24*60*60; $markets = dbolist("SELECT M.id AS id, M.name AS name, MIN(MH.balance) AS min, MAX(MH.balance) AS max FROM market_history MH LEFT JOIN markets M ON M.id = MH.idmarket WHERE MH.idcoin=$id AND MH.time>$t AND NOT M.disabled - GROUP BY M.id, M.name"); + GROUP BY M.id, M.name HAVING max > 0"); $stackedMax = (double) 0; @@ -23,26 +23,39 @@ foreach ($markets as $m) { $stats = getdbolist('db_market_history', "time>$t AND idmarket={$market->id} ORDER BY time"); $max = 0; - foreach($stats as $histo) - { - $d = date('Y-m-d H:i:s', $histo->time); + foreach($stats as $histo) { + $d = date('Y-m-d H:i', $histo->time); $series[$m['name']][] = array($d, (double) bitcoinvaluetoa($histo->balance)); $max = max($max, $histo->balance); } - if ($histo && $market->balance && $market->balancetime > $histo->time) { - $d = date('Y-m-d H:i:s', $market->balancetime); - $series[$m['name']][] = array($d, (double) bitcoinvaluetoa($market->balance)); - $max = max($max, $market->balance); - } - $stackedMax += $max; - if ($max == 0 && !empty($stats)) { - unset($series[$m['name']]); - } } +// "yiimp" balance + +$stats = getdbolist('db_market_history', "time>$t AND idcoin={$id} AND idmarket IS NULL ORDER BY time"); + +$max = 0; +foreach($stats as $histo) { + $d = date('Y-m-d H:i', $histo->time); + $series['yiimp'][] = array($d, (double) bitcoinvaluetoa($histo->balance)); + $max = max($max, $histo->balance); +} +$stackedMax += $max; + +// Stacked graph specific : seems to require same amount of points :/ +$max = 0; +foreach ($series as $serie) { + $max = max($max, count($serie)); +} +foreach ($series as $name => $serie) { + $n = count($serie); + for ($i = count($serie); $i < $max; $i++) { + array_unshift($series[$name], $series[$name][0]); + } +} echo json_encode(array( 'data'=>array_values($series), diff --git a/web/yaamp/modules/site/results/graph_market_prices.php b/web/yaamp/modules/site/results/graph_market_prices.php index 4d37018..d8269fc 100644 --- a/web/yaamp/modules/site/results/graph_market_prices.php +++ b/web/yaamp/modules/site/results/graph_market_prices.php @@ -8,10 +8,11 @@ if (!$coin) return; $t = time() - 7*24*60*60; -$markets = dbolist("SELECT M.id AS id, M.name, MIN(MH.price) AS min, MAX(MH.price) AS max +$markets = dbolist("SELECT M.id AS id, M.name, M.priority, MIN(MH.price) AS min, MAX(MH.price) AS max FROM market_history MH LEFT JOIN markets M ON M.id = MH.idmarket WHERE MH.idcoin=$id AND MH.time>$t AND NOT M.disabled - GROUP BY M.id, M.name"); + GROUP BY M.id, M.name, M.priority + ORDER BY M.priority DESC"); $min = 999999999; $max = 0; @@ -25,12 +26,12 @@ foreach ($markets as $m) { foreach($stats as $histo) { - $d = date('Y-m-d H:i:s', $histo->time); + $d = date('Y-m-d H:i', $histo->time); $series[$m['name']][] = array($d, (double) bitcoinvaluetoa($histo->price)); } if ($histo && $market->pricetime && $market->pricetime > $histo->time) { - $d = date('Y-m-d H:i:s', $market->pricetime); + $d = date('Y-m-d H:i', $market->pricetime); $series[$m['name']][] = array($d, (double) bitcoinvaluetoa($market->price)); } @@ -43,6 +44,15 @@ if ($min == 999999999) { $min = 0; } +// "yiimp" price + +$stats = getdbolist('db_market_history', "time>$t AND idcoin={$id} AND idmarket IS NULL ORDER BY time"); +foreach($stats as $histo) { + $d = date('Y-m-d H:i', $histo->time); + $series['yiimp'][] = array($d, (double) bitcoinvaluetoa($histo->price)); + $max = max($max, $histo->price); +} + echo json_encode(array( 'data'=>array_values($series), 'labels'=>array_keys($series),