mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-30 07:10:35 +00:00
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
This commit is contained in:
parent
e6365fcc93
commit
21746e5953
5 changed files with 70 additions and 23 deletions
|
@ -100,6 +100,16 @@ function BackendWatchMarkets($marketname=NULL)
|
||||||
$mh->balance = dboscalar("SELECT SUM(balance) AS btc FROM balances");
|
$mh->balance = dboscalar("SELECT SUM(balance) AS btc FROM balances");
|
||||||
$mh->save();
|
$mh->save();
|
||||||
continue;
|
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
|
// user watched currencies
|
||||||
|
@ -115,7 +125,6 @@ function BackendWatchMarkets($marketname=NULL)
|
||||||
$mh->price2 = $market->price2;
|
$mh->price2 = $market->price2;
|
||||||
$mh->balance = (double) ($market->balance) + (double) ($market->ontrade);
|
$mh->balance = (double) ($market->balance) + (double) ($market->ontrade);
|
||||||
$mh->save();
|
$mh->save();
|
||||||
//debuglog("{$coin->symbol} {$market->name} market history");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,7 +539,12 @@ function updateCCexMarkets()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($market->disabled < 9) $market->disabled = !$ticker['IsActive'];
|
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();
|
$market->save();
|
||||||
|
|
||||||
|
|
|
@ -242,6 +242,11 @@ function yaamp_hashrate_step()
|
||||||
return 300;
|
return 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function yaamp_watched_coin($symbol)
|
||||||
|
{
|
||||||
|
return (strpos(",".YIIMP_WATCH_CURRENCIES.",", ",$symbol,") !== false);
|
||||||
|
}
|
||||||
|
|
||||||
function yaamp_profitability($coin)
|
function yaamp_profitability($coin)
|
||||||
{
|
{
|
||||||
if(!$coin->difficulty) return 0;
|
if(!$coin->difficulty) return 0;
|
||||||
|
|
|
@ -52,7 +52,7 @@ echo <<<end
|
||||||
</tr></thead><tbody>
|
</tr></thead><tbody>
|
||||||
end;
|
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);
|
$bestmarket = getBestMarket($coin);
|
||||||
foreach($list as $market)
|
foreach($list as $market)
|
||||||
|
@ -175,8 +175,13 @@ echo '<td>'.$coin->algo.'</td>';
|
||||||
|
|
||||||
if(!$info)
|
if(!$info)
|
||||||
{
|
{
|
||||||
echo "<td colspan=8>ERROR $remote->error</td>";
|
echo '<td colspan="5">ERROR '.$remote->error.'</td>';
|
||||||
echo "</tr></tbody></table>";
|
echo '<td>'.bitcoinvaluetoa($coin->price).'</td>';
|
||||||
|
echo '<td colspan="2">';
|
||||||
|
echo "</tr></tbody></table><br/>";
|
||||||
|
if (yaamp_watched_coin($coin->symbol)) {
|
||||||
|
$this->renderPartial('coin_market_graph', array('coin'=>$coin));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,6 +431,6 @@ if (empty($sums)) {
|
||||||
|
|
||||||
echo '</tbody></table></div>';
|
echo '</tbody></table></div>';
|
||||||
|
|
||||||
if (strpos(YIIMP_WATCH_CURRENCIES, $coin->symbol) !== false) {
|
if (yaamp_watched_coin($coin->symbol)) {
|
||||||
$this->renderPartial('coin_market_graph', array('coin'=>$coin));
|
$this->renderPartial('coin_market_graph', array('coin'=>$coin));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
$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
|
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
|
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;
|
$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");
|
$stats = getdbolist('db_market_history', "time>$t AND idmarket={$market->id} ORDER BY time");
|
||||||
|
|
||||||
$max = 0;
|
$max = 0;
|
||||||
foreach($stats as $histo)
|
foreach($stats as $histo) {
|
||||||
{
|
$d = date('Y-m-d H:i', $histo->time);
|
||||||
$d = date('Y-m-d H:i:s', $histo->time);
|
|
||||||
$series[$m['name']][] = array($d, (double) bitcoinvaluetoa($histo->balance));
|
$series[$m['name']][] = array($d, (double) bitcoinvaluetoa($histo->balance));
|
||||||
|
|
||||||
$max = max($max, $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;
|
$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(
|
echo json_encode(array(
|
||||||
'data'=>array_values($series),
|
'data'=>array_values($series),
|
||||||
|
|
|
@ -8,10 +8,11 @@ if (!$coin) return;
|
||||||
|
|
||||||
$t = time() - 7*24*60*60;
|
$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
|
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
|
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;
|
$min = 999999999;
|
||||||
$max = 0;
|
$max = 0;
|
||||||
|
@ -25,12 +26,12 @@ foreach ($markets as $m) {
|
||||||
|
|
||||||
foreach($stats as $histo)
|
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));
|
$series[$m['name']][] = array($d, (double) bitcoinvaluetoa($histo->price));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($histo && $market->pricetime && $market->pricetime > $histo->time) {
|
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));
|
$series[$m['name']][] = array($d, (double) bitcoinvaluetoa($market->price));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +44,15 @@ if ($min == 999999999) {
|
||||||
$min = 0;
|
$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(
|
echo json_encode(array(
|
||||||
'data'=>array_values($series),
|
'data'=>array_values($series),
|
||||||
'labels'=>array_keys($series),
|
'labels'=>array_keys($series),
|
||||||
|
|
Loading…
Add table
Reference in a new issue