so anyhooo, i went and wrote this script yesterday for playing satoshidice martingale-style.
it was a fun exercise, and i figure i'll share my complete code in case others find it fun/useful/interesting/noteworthy.
require_once('jsonRPCClient.php');
$b = new jsonRPCClient('http://YOURUSERNAME:[email protected]:8332/');
define('MIN_BET', 0.01);
define('MAX_BET', 6);
define('ADDRESS', '1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp');
$bet = MIN_BET;
$total_fees = 0;
$count = 0;
$count_won = 0;
while (($bet <= MAX_BET) && ($count_won < 100))
{
$count++;
$balance_a = $b->getbalance('*', 0);
if (!isset($starting_balance)) $starting_balance = $balance_a;
$b->sendtoaddress(ADDRESS, (float) $bet);
$balance_b = $b->getbalance('*', 0);
$fee = $balance_a - $balance_b - $bet;
$total_fees += $fee;
$total_fees = number_format($total_fees,8,'.','')+0;
echo 'Game #'.$count."\n";
echo 'Balance: ' . $balance_a." ";
echo 'Bet: '. $bet." ";
echo 'Fee: '. (number_format($fee, 8, '.', '') +0) . " ";
echo 'Total Fees: '. $total_fees. "\n";
echo 'Balance: ' . $balance_b . " ".'Waiting';
$balance_c = 0;
while ($balance_b >= $balance_c)
{
sleep(4);
$balance_c = $b -> getbalance('*', 0);
echo '.';
}
echo "\nBalance: $balance_c ";
$diff = $balance_c - $balance_b;
if ($diff > $bet)
{
$bet = MIN_BET;
$count_won++;
echo "Win! ($count_won out of $count)\n";
}
else
{
$bet *= 2;
echo 'Lose!'."\n";
}
echo "\n";
}
echo 'Starting Balance: '.$starting_balance."\n";
echo 'Ending Balance : '. $balance_c."\n";
echo 'Total Fees: '. $total_fees."\n";
$amt_won = $balance_c - $starting_balance;
echo 'Net Profit: '. (number_format($amt_won,8,'.','') + 0). "\n\n";
output looks something like...
Game #1
Balance: 11.37567619 Bet: 0.01 Fee: 0.0005 Total Fees: 0.0005
Balance: 11.36517619 Waiting...
Balance: 11.36521708 Lose!
Game #2
Balance: 11.36521708 Bet: 0.02 Fee: 0.0005 Total Fees: 0.001
Balance: 11.34471708 Waiting.........
Balance: 11.34479886 Lose!
Game #3
Balance: 11.34479886 Bet: 0.04 Fee: 0.0005 Total Fees: 0.0015
Balance: 11.30429886 Waiting...
Balance: 11.38554886 Win! (1 out of 3)
Game #4
Balance: 11.38554886 Bet: 0.01 Fee: 0.0005 Total Fees: 0.002
Balance: 11.37504886 Waiting.....
Balance: 11.37508975 Lose!
with a summary at the end somewhat like this:
Starting Balance: 11.37567619
Ending Balance : 11.42477259
Total Fees: 0.006
Net Profit: 0.0490964
it's designed to run from the command-line by the way. it'll still work from a browser, but you may want to swap all the "\n" with '
' or something.
warning: the martingale method of betting isn't foolproof. this script may cause you to lose your entire balance.
warning 2: even if the martingale method of betting
were foolproof, my php code may not be... use at your own risk.
if you like this and want to send me a few bits for the effort, 1CxzfAQo2UK9rppeQNvNmAFhApPqmdVR8y