Bitcoin Forum
April 24, 2017, 03:18:22 PM
 Welcome, Guest. Please login or register. 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length
 News: If the forum does not load normally for you, please send me a traceroute.
 Home Help Search Donate Login Register
 Pages: [1] 2 3 4 5 6 7 8  All
 Author Topic: PHP martingale bot for satoshiDICE  (Read 31653 times)
payb.tc
Hero Member

Offline

Activity: 812

 May 09, 2012, 01:33:27 AM

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.

Code:
<?php
require_once('jsonRPCClient.php');

define('MIN_BET'0.01);
define('MAX_BET'6);

\$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;

\$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(\$fee8'.''') +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...

Code:
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:

Code:
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 '<br/>' 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
1493047102
Hero Member

Offline

Posts: 1493047102

Ignore
 1493047102

1493047102
 Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1493047102
Hero Member

Offline

Posts: 1493047102

Ignore
 1493047102

1493047102
 Report to moderator
Hero Member

Offline

Activity: 784

bitcoin hundred-aire

 May 09, 2012, 01:35:11 AM

move to gambling forum?

Also, nice work, I might use the damn thing soon

(BFL)^2 < 0
SkRRJyTC
Legendary

Offline

Activity: 994

 May 09, 2012, 01:36:10 AM

I love Satoshidice.  Fun as hell.  That being said... Scripting a -EV game is bad news...lol
bearbones
Sr. Member

Offline

Activity: 317

 May 09, 2012, 02:10:39 AM

woah, woah, woah, forgot to mention:

THIS NEEDS IT'S OWN WALLET!

i couldn't get this to run properly from an 'account' within a wallet, because when SD sends payments it ends up going unpredictably in all of your accounts...

so this is running from it's own instance of bitcoind, it's own wallet, with nothing else accessing it.

Correct me if I'm missing something, but wouldn't this be solved by using 'sendfrom' instead of 'sendtoaddress'?

Feed Ze Birds Pay and get paid for tweets
Coinapult Send Bitcoins easily over email or text message
Stephen Gornick
Legendary

Offline

Activity: 2128

 May 09, 2012, 02:42:35 AM

I love Satoshidice.  Fun as hell.  That being said... Scripting a -EV game is bad news...lol

New to the gaming field, had to look it up:

- http://en.wikipedia.org/wiki/Expected_value

mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 03:32:42 AM

I think you just invented a new kind of bitcoin mining.

those balances are real by the way... i started with exactly 10 btc.

...and expect to finish with approximately 0 btc once i've finished playing with this bot

Nice work, I was doing the same thing in perl last night (I use a modified martingale system).

I will post up my simulator tonight when I get home. I had some issues with GD Graph Lines generating graphed output (hates the negatives) so graphing the csv output is not supported yet.

I have to stress as someone who loves gambling and runs his own system these all fail and fail hard eventually.
You need to set a modest target profit then bail out when you hit it.

Using the vanilla martingale system with a x2 multiplier when the reward is *1.94 and not *2 will set you up to lose. I see you are using the 48.8281% chance 2.031x multiplier, this overcomes the issue while reducing odds in your favor.

I also have a spreadsheet on zoho docs I will share and post later (supposed to be working ), it plots out cumlative win, % odds of getting that far into the system.

Ive run my system at casino's on roulette and seen 14 straight blacks whens and last night when running sims against satoishi I saw 22 losses in a row - it can happen, be warned.

great script, Im going to use it as a reference to finish off mine (could not test last night due to the site being down).

mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 03:39:05 AM

https://sheet.zoho.com/public/mem.namefix/memtingale-basic-sim

martingale sim in a spreadsheet for those that are interested.

I will post the perl sim tonight (allows simulating as many rounds as needed, 20'000 is usually what i run).
It dumps output to a nice html 9then opens in firefox) file and csv.

publio
Member

Offline

Activity: 64

 May 09, 2012, 03:41:57 AM

As with any gambling venture, there is a chance of profits.. but there's an even greater chance of losses.

I hope no one will be misguided by that spreadsheet.

JoelKatz
Legendary

Offline

Activity: 1470

Democracy is vulnerable to a 51% attack.

 May 09, 2012, 03:47:04 AM

Martingale changes the odds from a very high chance of losing a small amount of money to a very small chance of losing a large amount of money. It can't change the house edge though, so the higher the chances of a profit, the higher the losses in the unlikely event of a loss.

A typical Martingale progression, for example, needs a \$10,000 bankroll to give you a 99.85% chance of winning \$10. In the very unlikely case that you lose, though, you'll lose your entire bankroll. If you don't have that large a bankroll, you can't lose as much. But the odds that you will lose your entire bankroll go up.

I am an employee of Ripple.
1Joe1Katzci1rFcsr9HH7SLuHVnDy2aihZ BM-NBM3FRExVJSJJamV9ccgyWvQfratUHgN
mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 03:51:35 AM

out of curiosity i went to random.org (with my browser) and manually pulled 20,000 numbers (0 or 1) to see how often there were long runs of the same number.
there were only about 4 or 5 which had 12+ and i think around 25 or so which had 10+

10 will put you at 1024btc and a total cumaltive bet of 2047 BTC (1024+512+256+128+64=32+16+8+4+1) with a profit of 32.744btc.

i hope anyone that takes my code and changes it will consider sharing their modifications publicly.
good luck with it!

Well mine is perl, but Im happy to share.
I think sim's will be really useful here to stop people hurting themselves

x2.5 - x3.7 Is the range of my secret multiplier (well close) as can be seen in the spreadsheet linked.. x2 = fools game of a 2x reward, ever increasing bets to win your original 2x your original bet back.

Good luck all.

There are some good stories of millionaires bankrupting  themselves by playing the martingale system to the bitter end at a casino (hot tip, casino's cheat).

mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 03:53:23 AM

Martingale changes the odds from a very high chance of losing a small amount of money to a very small chance of losing a large amount of money. It can't change the house edge though, so the higher the chances of a profit, the higher the losses in the unlikely event of a loss.

Thats why I think playing a martingales system is for fools, you need to increase the reward as the risk increases.
3x instead of 2x is fun - dangerous but fun

Nachtwind
Hero Member

Offline

Activity: 700

 May 09, 2012, 06:50:47 AM

A PowerShell Version:

Code:
Write-Host "Satoshidice"

\$min_bet = 0.01
\$max_bet = 0.1

\$bet = \$min_bet
\$total_fees = 0
\$count = 0
\$count_won = 0

\$starting_balance = ./bitcoind getbalance

while (\$bet -le \$max_bet -AND \$count_won -le 100) {

\$count ++
\$balance_a = ./bitcoind getbalance

\$balance_b = ./bitcoind getbalance

\$fee = \$balance_a - \$balance_b - \$bet
\$total_fees += \$fee

Write-Host "Game: \$count"
Write-Host "Balance: \$balance_a"
Write-Host "Bet: \$bet"
Write-Host "Fee: \$fee"
Write-Host "Total Fees: \$total_fees"
Write-Host –NoNewLine "Balance: \$balance_b Waiting "

\$balance_c = 0
\$last_c = 0

while (\$balance_b -ge \$balance_c)
{
\$balance_c = ./bitcoind getbalance

if(  (\$balance_c -eq \$last_c) -OR (\$last_c -eq 0) )
{
Write-Host –NoNewLine "."
}else
{
Write-Host "Balance: \$balance_c"
}

\$last_c = \$balance_c

}

\$diff = \$balance_c - \$balance_b

if (\$diff -gt \$bet)
{
\$bet = \$min_bet
\$count_won = \$count_won + 1
Write-Host "Win! (\$count_won out of \$count)"
}else
{
\$bet = \$bet * 2
Write-Host "Lose!"
}

Write-Host ""
}

If someone thinks this is worth a donation... 1J66vZHf1oFPHFhjFBtbEqxkJahdF3vetu

Thanks payb.tc for your nice PHP Script :0) Donation on the way
Nachtwind
Hero Member

Offline

Activity: 700

 May 09, 2012, 07:11:40 AM

Thanks payb.tc for your nice PHP Script :0) Donation on the way

thanks very much

i'm not even sure i've heard of PowerShell... it looks a lot like php.

Powershelll is, simplified, Bash for Windows. Much nicer scripting than with old Batch files
mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 07:16:46 AM

A PowerShell Version:
~~SNIP~~
If someone thinks this is worth a donation... 1J66vZHf1oFPHFhjFBtbEqxkJahdF3vetu

Thanks payb.tc for your nice PHP Script :0) Donation on the way

thats some nice powershell there

Powershell is microsofts attempt to return to unix roots and its not a bad start at it either.
The amount of stuff you can now automate/script via powershell (outlook accounts, AD operations etc) is fantastic.

Nachtwind
Hero Member

Offline

Activity: 700

 May 09, 2012, 07:25:09 AM

That IS a problem i just noticed myself after running a few games.. i wonder - how can you get 0-Conf balances via command line
bitcoind getbalance '*' 0 returns 0.000000 for me
Nachtwind
Hero Member

Offline

Activity: 700

 May 09, 2012, 07:29:38 AM

That IS a problem i just noticed myself after running a few games.. i wonder - how can you get 0-Conf balances via command line
bitcoind getbalance '*' 0 returns 0.000000 for me

i don't know but i'm going to take a quick guess... have you tried without the single quotes?
bitcoind getbalance * 0

Everything just ends up with 0.00000 or "type mismatch" - only singlequotes worked so far... i keep trying and will update my script
Nachtwind
Hero Member

Offline

Activity: 700

 May 09, 2012, 07:49:41 AM

same thing.. i either get the confirmed balance or no balance ><
mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 07:50:50 AM

im using the json API - I highly recommend it.

my pseudo code for determining if bet received.

Code:
# \$last_bet = \$bet;
# transaction_arr = get last N transactions;

# if(\$transaction_arr[0] < 0)
#   (negative number, sent transaction, loop and wait).
# else
#   must be a positive transaction, money recieved.
# \$latest = \$transaction_arr[0];

# confirm from address (satoshidice use same address for recieving and sending for each game).
# if(\$latest == \$last_bet * \$reward)
#   won, reset bets, loop
# else
# if (\$latest == \$last_bet * 0.004089)
#   lost, \$bet *= \$bet_multiplier, loop

Nachtwind
Hero Member

Offline

Activity: 700

 May 09, 2012, 07:59:04 AM

would use the RPC.. but havent figured out how to use that in MSH so far Under Linux and PHP its not a real problem..
mem
Hero Member

Offline

Activity: 644

Herp Derp PTY LTD

 May 09, 2012, 12:04:08 PM

link to my simulator, https://bitcointalk.org/index.php?topic=80361.msg889950#msg889950

good for simulating 20'000+ rounds

 Pages: [1] 2 3 4 5 6 7 8  All
 « previous topic next topic »