Presenting Codemonkeys php martingale bot:
A working bot and a good demonstration of our JSON API.
it supports blockchain.info, bitcoind, litecoind, ppcoind and terracoind
you do need to download the file: jsonRPCClient.php and place it in the same directory as this script for JSON calls to work.
Simply edit the settings in the section marked user defined settings and then run.
I am currently using it myself to test the new terracoin.
Install:Linuxinstall php.
create bot.php in your home directory.
# cd
# php ./bot.php
WindowsDownload and install the latest PHP windows installer:
http://windows.php.net/downloads/releases/php-5.3.21-nts-Win32-VC9-x86.msiInstall and follow the prompts, note optional web server component is not required.
create the file bot.api in c:\ (or a directory of your chosing).
open command prompt.
# cd \
# PHP bot.api
Configure:You must have the following in your bitcoin.conf, set your own password and username.
server=1
rpcpassword=password
rpcuser=user
then edit bot.php and adjust this section to match:
# -----------------------------------------------------------------------------
# Begin user defined settings
# -----------------------------------------------------------------------------
# SNIP All user settings go here :) see main code block below.
# -----------------------------------------------------------------------------
Bot:# *****************************************************************************
# Satoshi Roulette Bot
# *****************************************************************************
#
# references:
# https://bitcointalk.org/index.php?topic=137519.msg1512149#msg1512149
# http://blockchain.info/api/blockchain_wallet_api
include './jsonRPCClient.php';
global $address;
global $address_old;
global $bet;
global $min;
global $max;
global $max_old;
global $jackpot;
global $sleep;
global $user;
global $password;
global $coind;
global $blockchain;
global $turbo;
# -----------------------------------------------------------------------------
# Begin user defined settings
# -----------------------------------------------------------------------------
$turbo = 0; # enable turbo mode, for fast result checking using the latest recieved bitcoind txid.
# list of games to bet against.
$games = array("roulette-red", "roulette-black", "roulette-odd", "roulette-even", "jdice-052", "coinflip-heads", "coinflip-tails", "roulette-1to18", "roulette-19to36");
# exit settings
$percent_win = 100; # what % wallet increase to stop at
$percent_lose = 50; # what % wallet decrease to stop at
# bot settings
$mode = 'TRC'; # mode: BTC/ LTC/ PPC
$blockchain = 0; # 1 for using blockchain.info wallets, set mode to BTC
$min = 0.025; # if lower than the games min, the games min is used
$max = 100; # if higher than the games max, the games max is used
$goto_max = 1; # if the next bet greater than the games max bet, bet max. Used for collecting jackpots.
# bitcoind/ litecoind/ trcoind rpc connection settings
$ip = '127.0.0.1'; # coind ip
$user = 'user'; # coind rpc user
$password = 'password'; # coind rpc password
$port = 8866; # coind rpc port
# misc settings
$x = 2; # when a bet loses, the next bet = $bet * $x;
$sleep = 10; # sleep time: 10 seconds is optimal, 5 or lower for turbo.
# -----------------------------------------------------------------------------
# End user defined settings
# -----------------------------------------------------------------------------
$bet = 0;
$json_coind_url = "http://$user:$password@$ip:$port/";
$game_name = $games[0]; # start with first game in array
$balance = 0;
$jackpot = 0;
$address_old = '';
$gweedo = 1;
$json_coind_url = "http://$user:$password@$ip:$port/";
$address = '';
# *****************************************************************************
# Start
# *****************************************************************************
if(!$blockchain) # connect to coind via rpc if not using blockchain.info api
{
$coind = new jsonRPCClient($json_coind_url);
}
$start_balance = $balance = sprintf("%.4f", check_balance());
$win_balance = sprintf("%.4f", $start_balance * ((100+$percent_win) / 100));
$lose_balance = sprintf("%.4f", $start_balance * ((100-$percent_lose) / 100));
check_last();
echo
"===============================================================================
Satoshi Roulette - Martingale Bot - Mode $mode
===============================================================================
Target Balance: $win_balance $mode
Start Balance : $start_balance $mode
Stop Balance : $lose_balance $mode
";
if($turbo == 1)
{
echo "\nTURBO MODE\n";
}
echo "
-----------------------------------------------------------------------------
";
# load game info
$rand_keys = array_rand($games, 2); $game_name = $games[$rand_keys[0]];
$s = load_game($mode, $game_name);
if(!$bet) { $bet = $min; }
while(1)
{
# send bet
$bet_txid = send_bet($bet, $address);
echo date("H:i:s: ", time()) . "Balance: " . sprintf("%.4f", $balance) . " $mode, txid: $bet_txid, bet: " . sprintf("%.4f", $bet) . " $mode on $game_name ";
# wait for result
$result = get_result($mode, $bet_txid, $game_name);
# pre select next game
$rand_keys = array_rand($games, 2); $game_name = $games[$rand_keys[0]]; $s = load_game($mode, $game_name);
# check win / lose
if($result) # WIN
{
#echo $win_string;
echo " WIN\n";
$bet = $min;
}
else # LOSE
{
echo " LOSE\n";
$bet = 0 + sprintf("%.8f", $bet * $x);
if($bet > $max)
{
echo "[Hit Wall - Reseting]\n";
$bet = $min;
}
else if($goto_max && $bet * $x > $max)
{
$bet = $max;
}
}
# -----------------------------------------------------------------------------
# check exit :3
# -----------------------------------------------------------------------------
$balance = check_balance();
if($balance < $start_balance * (100-$percent_lose) / 100) # loss exit
{
echo "Exiting, Balance $balance is $percent_lose % lower than start balance $start_balance\n";
exit;
}
if($balance > $start_balance * (100+$percent_win) / 100 ) # profit exit
{
echo "Exiting, Balance $balance is $percent_win % higher than start balance $start_balance\n";
exit;
}
}
exit;
# *****************************************************************************
# done
# *****************************************************************************
# -----------------------------------------------------------------------------
# Load Game
function load_game($mode, $game_name)
{
$GLOBALS['jackpot'] = 0;
while(1)
{
$tmp = file_get_contents("http://satoshiroulette.com/api.php?game=$game_name&mode=$mode");
$game = json_decode($tmp);
if( isset($game->{'address'}) )
{
break;
}
else
{
print "JSON Reply:\n$tmp\n";
sleep(10);
}
}
$GLOBALS['address'] = $game->{'address'} ;
if(isset($game->{'jackpot'}))
{
$GLOBALS['jackpot'] = sprintf("%.8f", $game->{'jackpot'});
}
if($GLOBALS['min'] < $game->{'min_bet'} || !$GLOBALS['min'])
{
$GLOBALS['min'] = $game->{'min_bet'} ;
}
if($GLOBALS['min'] > $game->{'max_bet'})
{
$GLOBALS['min'] = $game->{'min_bet'} ;
}
if($GLOBALS['max'] > $game->{'max_bet'} || !$GLOBALS['max'])
{
$GLOBALS['max'] = $game->{'max_bet'};
}
}
# -----------------------------------------------------------------------------
# Get Balance
function check_balance()
{
if($GLOBALS['blockchain'])
{
$jsonurl = "https://blockchain.info/merchant/".$GLOBALS['user']."/balance?password=".$GLOBALS['password'];
$json = file_get_contents($jsonurl,0,null,null);
$json = json_decode($json);
return $json->{'balance'} / 100000000;
}
return $GLOBALS['coind']->getbalance('*', 0);
}
# -----------------------------------------------------------------------------
# wait for bet result
function get_result($mode, $bet_txid, $game_name)
{
$jsonurl = "http://satoshiroulette.com/log.api.php?txid=$bet_txid&mode=$mode";
$c = 0;
while(! isset($r->{$game_name}))
{
$c++;
# sleep straight away as its unlikely we bitcoin travels the speed of light
sleep($GLOBALS['sleep']);
# check local wallet for latest tx
$w = check_last();
if($w == 'WIN')
{
return 1;
}
else if ($w == 'LOSE')
{
return 0;
}
# check satoshiroulette.com API for win / lose
$r = json_decode(file_get_contents($jsonurl));
if(isset($r->{$game_name}))
{
return $r->{$game_name};
}
if($c == 6)
{
$c = 0;
print "|";
}
else
{
print "-";
}
}
}
# -----------------------------------------------------------------------------
# Bet
function send_bet($bet, $address)
{
if($GLOBALS['blockchain'])
{
$b = $bet * 100000000;
$jsonurl = "https://blockchain.info/merchant/".$GLOBALS['user']."/payment?password=".$GLOBALS['password']."&to=$address&amount=$b";
$bet_tx = json_decode(file_get_contents($jsonurl,0,null,null));
return $bet_tx->{'tx_hash'};
}
return $GLOBALS['coind']->sendtoaddress($address, (float) $bet );
}
function check_last()
{
if($GLOBALS['blockchain'] || !$GLOBALS['turbo'])
{
return 'NULL';
}
$r = $GLOBALS['coind']->listtransactions();
$l = count($r) - 1;
$cat = $r[$l]['category'];
$txid = $r[$l]['txid'];
$amount = $r[$l]['amount'];
if($cat == 'receive')
{
if($amount < $GLOBALS['bet'])
{
return 'LOSE';
}
else
{
return 'WIN';
}
}
return 'NULL';
}
?>