Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
session_start();
//////////////////////////////////////////////////////////
function get_data($url) {
$ch = curl_init();
$timeout = 15;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36');
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
//////////////////////////////////////////////////////////
function btc_usd() {
if ( $_SESSION['btc_usd'] ) {
return $_SESSION['btc_usd'];
}
else {
$json_string = 'https://api.coinbase.com/v2/prices/spot?currency=USD';
$jsondata = @get_data($json_string);
$data = json_decode($jsondata, TRUE);
$_SESSION['btc_usd'] = number_format( $data['data']['amount'], 2, '.', '');
return $_SESSION['btc_usd'];
}
}
/////////////////////////////////////////////////////////////
function steem_market() {
if ( $_SESSION['steem_btc'] ) {
return $_SESSION['steem_btc'];
}
else {
$json_string = 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-STEEM';
$jsondata = @get_data($json_string);
$data = json_decode($jsondata, TRUE);
if (is_array($data) || is_object($data)) {
foreach ($data as $key => $value) {
if ( $key == 'result' ) {
$_SESSION['steem_btc'] = $data[$key]["Last"];
return $_SESSION['steem_btc'];
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
function trim_array($data) {
foreach ( $data as $key => $value ) {
$data[$key] = trim(remove_formatting($value));
}
return $data;
}
///////////////////////////////////////////////////////////////////////////////
function remove_formatting($data) {
$data = preg_replace("/ /i", "", $data); // Space
$data = preg_replace("/ /i", "", $data); // Tab
$data = preg_replace("/,/i", "", $data); // Comma
return $data;
}
///////////////////////////////////////////////////////////////////////////////
function powerdown_usd($data) {
global $steam_market;
return ( $data * $steam_market * btc_usd() );
}
///////////////////////////////////////////////////////////////////////////////
function steempower_time($speed, $time) {
global $_POST, $steam_market;
$powertime = NULL;
$steem_total = NULL;
$usd_total = NULL;
if ( $time == 'minute' ) {
$powertime = $speed;
}
elseif ( $time == 'hour' ) {
$powertime = ($speed * 60);
}
elseif ( $time == 'day' ) {
$powertime = ($speed * 60 * 24);
}
elseif ( $time == 'week' ) {
$powertime = ($speed * 60 * 24 * 7);
}
elseif ( $time == 'month' ) {
$powertime = ($speed * 60 * 24 * 30);
}
elseif ( $time == '2month' ) {
$powertime = ($speed * 60 * 24 * 60);
}
elseif ( $time == '3month' ) {
$powertime = ($speed * 60 * 24 * 90);
}
elseif ( $time == '6month' ) {
$powertime = ($speed * 60 * 24 * 180);
}
elseif ( $time == '9month' ) {
$powertime = ($speed * 60 * 24 * 270);
}
elseif ( $time == 'year' ) {
$powertime = ($speed * 60 * 24 * 365);
}
elseif ( $time == '15month' ) {
$powertime = ($speed * 60 * 24 * 450);
}
elseif ( $time == '18month' ) {
$powertime = ($speed * 60 * 24 * 540);
}
$powertime_usd = ( $powertime * $steam_market * btc_usd() );
$steem_total = ( $powertime + $_POST['sp_total'] );
$usd_total = ( $steem_total * $steam_market * btc_usd() );
$power_purchased = ( $_POST['sp_purchased'] / $steem_total );
$power_earned = ( $_POST['sp_earned'] / $steem_total );
$power_interest = 1 - ( $power_purchased + $power_earned );
$powerdown_total = ( $steem_total / 104 );
$powerdown_purchased = ( $powerdown_total * $power_purchased );
$powerdown_earned = ( $powerdown_total * $power_earned );
$powerdown_interest = ( $powerdown_total * $power_interest );
//echo $power_purchased;
//echo $power_earned;
//echo $power_interest;
?>
<div class='result'>
<h2> Interest Per <?=ucfirst($time)?> </h2>
<ul>
<li><b><?=number_format( $powertime, 3, '.', ',')?> STEEM</b> <i>in interest</i>, after a <?=$time?> time period = <b>$<?=number_format( $powertime_usd, 2, '.', ',')?></b></li>
<li><b><?=number_format( $steem_total, 3, '.', ',')?> STEEM</b> <i>in total</i>, including original vested amount = <b>$<?=number_format( $usd_total, 2, '.', ',')?></b></li>
</ul>
<table border='1' cellpadding='10' cellspacing='0'>
<caption><b>A Power Down Weekly Payout At This Time Would Be (rounded to nearest cent):</b></caption>
<thead>
<tr>
<th class='normal'> Purchased </th>
<th class='normal'> Earned </th>
<th class='normal'> Interest </th>
<th> Total </th>
</tr>
</thead>
<tbody>
<tr>
<td> <?=number_format( $powerdown_purchased, 3, '.', ',')?> STEEM = $<?=number_format( powerdown_usd($powerdown_purchased), 2, '.', ',')?> </td>
<td> <?=number_format( $powerdown_earned, 3, '.', ',')?> STEEM = $<?=number_format( powerdown_usd($powerdown_earned), 2, '.', ',')?> </td>
<td> <?=number_format( $powerdown_interest, 3, '.', ',')?> STEEM = $<?=number_format( powerdown_usd($powerdown_interest), 2, '.', ',')?> </td>
<td> <b><?=number_format( $powerdown_total, 3, '.', ',')?> STEEM</b> = <b>$<?=number_format( powerdown_usd($powerdown_total), 2, '.', ',')?></b> </td>
</tr>
</tbody>
</table>
</div>
<?php
}
//////////////////////////////////////////////////////////////////////////////////////
// Trim whitespace
$_POST = trim_array($_POST);
// Get STEEM value
$steam_market = steem_market();
?><html>
<head>
<title>STEEM Power Interest Rate / Power Down Weekly Payout Calculator</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<style>
body {
margin: 30px;
}
.result {
margin: 7px; border: 2px solid black; padding: 7px;
}
.normal {
font-weight: normal;
}
</style>
</head>
<body>
<h1>STEEM Power Interest Rate / Power Down Weekly Payout Calculator</h1>
<p>1 STEEM = <?=$steam_market?> BTC ($<?=number_format( ( $steam_market * btc_usd() ), 8, '.', ',')?>)</p>
<p>
<form action='' method='post'>
<p><input type='text' name='sp_purchased' value='<?=$_POST['sp_purchased']?>' placeholder="STEEM Power Purchased (from Bittrex trading etc)" size='45' /></p>
<p><input type='text' name='sp_earned' value='<?=$_POST['sp_earned']?>' placeholder="STEEM Power Earned (voting and posting)" size='45' /></p>
<p><input type='text' name='sp_total' value='<?=$_POST['sp_total']?>' placeholder="Current Total STEEM Power (including interest)" size='45' /></p>
<p><input type='text' name='interest_speed' value='<?=$_POST['interest_speed']?>' placeholder="STEEM Power Interest Per Minute" size='45' /></p>
<p><b style='color: red;'>To easily determine your current interest rate:</b>
<ul>
<li>Click the refresh / reload button on your browser at your steemit wallet page, and note the STEEM Power amount</li>
<li>Wait exactly 5 minutes and refresh / reload again, and note the new STEEM Power amount</li>
<li>Delete value #1 from value #2, and divide by 5</li>
</ul>
</p>
<p><input type='submit' value='Calculate Interest / Power Down Weekly Payout Amounts Over Time' /></p>
</form>
</p>
<?php
if ( $_POST['interest_speed'] ) {
?>
<p style='color: red; font-weight: bold;'>Your <i>current</i> STEEM Power interest rate results (USD value / STEEM interest rate <i>may change significantly over long periods of time</i>):</p>
<?php
steempower_time($_POST['interest_speed'], 'minute');
steempower_time($_POST['interest_speed'], 'hour');
steempower_time($_POST['interest_speed'], 'day');
steempower_time($_POST['interest_speed'], 'week');
steempower_time($_POST['interest_speed'], 'month');
steempower_time($_POST['interest_speed'], '2month');
steempower_time($_POST['interest_speed'], '3month');
steempower_time($_POST['interest_speed'], '6month');
steempower_time($_POST['interest_speed'], '9month');
steempower_time($_POST['interest_speed'], 'year');
steempower_time($_POST['interest_speed'], '15month');
steempower_time($_POST['interest_speed'], '18month');
}
?>
<div align='center' style='margin: 15px;'><a href='https://gist.github.com/taoteh1221/33f5e97e4c53c45044cc9ee1ef898b99' target='_blank'>Download the Source Code</a></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment