SHOW:
|
|
- or go back to the newest paste.
| 1 | var streakSecurity = 4; // Number of loss streaks you want to be safe for | |
| 2 | var risk = 0.5; // Fraction of your bankroll you'll lose if a loss streak of streakSecurity + 1 occurs | |
| 3 | // Range: 0.01 - 1 || Higher = more risk/reward, lower = less risk/reward | |
| 4 | // Recommend range: 0.25 - 0.75 | |
| 5 | ||
| 6 | var restartOnMaxLossStreak = true; // (true/false) If true, bot will reinitialize baseBet and cashout amount | |
| 7 | // when a loss streak of streakSecurity + 1 occurs, otherwise it'll just stop | |
| 8 | // NOTE: if risk = 1, restarting may not be possible | |
| 9 | ||
| 10 | var simulation = true; // (true/false) Setting this to true will make the bot to simulate a betting run | |
| 11 | // If you've changed any of the user settings, it's always recommended to test... | |
| 12 | // ...your changes by letting the bot run in simulator mode for a bit | |
| 13 | ||
| 14 | var simMsg = simulation ? '(SIMULATION) ' : ''; // This will appear in the console logs when running in simulator mode | |
| 15 | ||
| 16 | var newItem = document.createElement("form");
| |
| 17 | var form = document.getElementsByTagName("body")[0]; // Get the <ul> element to insert a new node
| |
| 18 | list.insertBefore(newItem, list.childNodes[0]); // Insert <li> before the first child of <ul> | |
| 19 | ||
| 20 | /* | |
| 21 | * Initialize global settings and counters (don't touch at all) | |
| 22 | */ | |
| 23 | var firstGame = true, | |
| 24 | numWins = 0, | |
| 25 | numLosses = 0, | |
| 26 | maxWinStreak = 0, | |
| 27 | maxLossStreak = 0, | |
| 28 | currentWinStreak = 0, | |
| 29 | currentLossStreak = 0, | |
| 30 | totalSatoshiProfit = 0, | |
| 31 | currentGameID = -1, | |
| 32 | currentCashout = 0, | |
| 33 | currentBitBet = 0, | |
| 34 | currentSatoshiBet = 0, | |
| 35 | roundedSatoshiBet = 0, | |
| 36 | lastResult = 'NOT_PLAYED'; // NOT_PLAYED, WON, LOST | |
| 37 | ||
| 38 | var startingBalance = engine.getBalance(); // in satoshi | |
| 39 | ||
| 40 | /* | |
| 41 | * Initialize game settings (don't touch unless you know what you're doing) | |
| 42 | */ | |
| 43 | var baseCashout = 1.13; | |
| 44 | var lossMultiplier = 4; // Increase base bet by this factor on loss | |
| 45 | var cashoutAmounts = | |
| 46 | [baseCashout, 1.25, 1.31, 1.33, 1.33]; // Cashout amount for current game are determined by... | |
| 47 | // ...indexing cashoutAmounts with currentLossTreak | |
| 48 | // NOTE: Length must be equal to streakSecurity + 1 | |
| 49 | ||
| 50 | var riskFactor = 0; | |
| 51 | for (var i = 0; i <= streakSecurity; i++) // need to sum all of the bet multipliers to... | |
| 52 | { // ...determine what the bankroll is divided by
| |
| 53 | riskFactor += Math.pow(lossMultiplier, i); | |
| 54 | }; | |
| 55 | ||
| 56 | /* | |
| 57 | * Helper function to calculate the bet amount | |
| 58 | * based on current balance and user settings | |
| 59 | */ | |
| 60 | function calcBaseBet() | |
| 61 | {
| |
| 62 | var currentBal = engine.getBalance(); | |
| 63 | return (risk * currentBal) / riskFactor; | |
| 64 | } | |
| 65 | ||
| 66 | // Calculate initialBaseBet (in satoshi) based on the user settings | |
| 67 | var initialBaseBet = calcBaseBet(); | |
| 68 | ||
| 69 | console.log('========================== EngiNerds\'s BustaBit Bot ==========================');
| |
| 70 | console.log('My username is: ' + engine.getUsername());
| |
| 71 | console.log('Starting balance: ' + (startingBalance/100).toFixed(2) + ' bits');
| |
| 72 | console.log('Risk Tolerance: ' + (risk * 100).toFixed(2) + '%');
| |
| 73 | console.log('Inital base bet: ' + Math.round(initialBaseBet/100) + ' bits (real value ' + (initialBaseBet/100).toFixed(2) + ')');
| |
| 74 | ||
| 75 | if (simulation) { console.log('=========================== SIMULATION MODE ENABLED =========================='); };
| |
| 76 | ||
| 77 | engine.on('game_starting', function(data)
| |
| 78 | {
| |
| 79 | if (!firstGame) // Display stats only after first game played | |
| 80 | {
| |
| 81 | console.log('==============================');
| |
| 82 | console.log('[Stats] Session Profit: ' + (totalSatoshiProfit/100).toFixed(2) + ' bits');
| |
| 83 | console.log('[Stats] Profit Percentage: ' + ((((totalSatoshiProfit + startingBalance) / startingBalance) - 1) * 100).toFixed(3) + '%');
| |
| 84 | console.log('[Stats] Total Wins: ' + numWins + ' | Total Losses: ' + numLosses);
| |
| 85 | console.log('[Stats] Max Win Streak: ' + maxWinStreak + ' | Max Loss Streak: ' + maxLossStreak);
| |
| 86 | } | |
| 87 | else | |
| 88 | {
| |
| 89 | firstGame = false; | |
| 90 | } | |
| 91 | ||
| 92 | currentGameID = data.game_id; | |
| 93 | console.log('=========== New Game ===========');
| |
| 94 | console.log(simMsg + '[Bot] Game #' + currentGameID); | |
| 95 | ||
| 96 | if (lastResult === 'LOST' && !firstGame) // The stupid game crashed before we could cash out | |
| 97 | {
| |
| 98 | if (currentLossStreak <= streakSecurity) // We lost, but it's okay, we've got it covered | |
| 99 | {
| |
| 100 | currentSatoshiBet *= 4; | |
| 101 | currentCashout = cashoutAmounts[currentLossStreak]; | |
| 102 | } | |
| 103 | else // *sigh* We were hoping this wouldn't happen, but it is gambling after all... | |
| 104 | {
| |
| 105 | if (restartOnMaxLossStreak) // start betting over again with recalculated base bet | |
| 106 | {
| |
| 107 | currentSatoshiBet = calcBaseBet(); | |
| 108 | currentCashout = baseCashout; | |
| 109 | currentLossStreak = 0; | |
| 110 | ||
| 111 | console.warn(simMsg + '[Bot] Streak security surpassed, reinitializing bet amount to ' + Math.round(currentSatoshiBet/100)); | |
| 112 | } | |
| 113 | else // Stop betting for now to lick our wounds | |
| 114 | {
| |
| 115 | console.warn(simMsg + '[Bot] Betting stopped after streak security was surpassed'); | |
| 116 | engine.stop(); | |
| 117 | } | |
| 118 | } | |
| 119 | } | |
| 120 | else if (firstGame) // Let's get this show on the road | |
| 121 | {
| |
| 122 | currentSatoshiBet = initialBaseBet; | |
| 123 | currentCashout = baseCashout; | |
| 124 | } | |
| 125 | else // Sweet, we won! Adjust the bet based on our balance | |
| 126 | {
| |
| 127 | currentSatoshiBet = calcBaseBet(); | |
| 128 | currentCashout = baseCashout; | |
| 129 | } | |
| 130 | ||
| 131 | currentBitBet = Math.round(currentSatoshiBet/100); | |
| 132 | roundedSatoshiBet = Math.round(currentBitBet * 100); | |
| 133 | ||
| 134 | if (currentBitBet > 0) | |
| 135 | {
| |
| 136 | console.log(simMsg + '[Bot] Betting ' + currentBitBet + ' bits, cashing out at ' + currentCashout + 'x'); | |
| 137 | } | |
| 138 | else | |
| 139 | {
| |
| 140 | console.warn(simMsg + '[Bot] Base bet rounds to 0. Balance considered too low to continue.'); | |
| 141 | engine.stop(); | |
| 142 | } | |
| 143 | ||
| 144 | if (!simulation) | |
| 145 | {
| |
| 146 | if (currentSatoshiBet <= engine.getBalance()) // Ensure we have enough to bet | |
| 147 | {
| |
| 148 | engine.placeBet(roundedSatoshiBet, Math.round(currentCashout * 100), false); | |
| 149 | } | |
| 150 | else if (!simulation) // Whoops, we ran out of money | |
| 151 | {
| |
| 152 | console.warn(simMsg + '[Bot] Insufficent funds to continue betting...stopping'); | |
| 153 | engine.stop(); | |
| 154 | } | |
| 155 | } | |
| 156 | }); | |
| 157 | ||
| 158 | engine.on('cashed_out', function(data)
| |
| 159 | {
| |
| 160 | if (data.username === engine.getUsername()) | |
| 161 | {
| |
| 162 | var lastProfit = (roundedSatoshiBet * (data.stopped_at/100)) - roundedSatoshiBet; | |
| 163 | console.log('[Bot] Successfully cashed out at ' + (data.stopped_at/100) + 'x (+' + (lastProfit/100).toFixed(2) + ')');
| |
| 164 | ||
| 165 | // Update global counters for win | |
| 166 | lastResult = 'WON'; | |
| 167 | numWins++; | |
| 168 | currentWinStreak++; | |
| 169 | currentLossStreak = 0; | |
| 170 | totalSatoshiProfit += lastProfit; | |
| 171 | maxWinStreak = (currentWinStreak > maxWinStreak) ? currentWinStreak : maxWinStreak; | |
| 172 | } | |
| 173 | }); | |
| 174 | ||
| 175 | engine.on('game_crash', function(data)
| |
| 176 | {
| |
| 177 | if (data.game_crash < (currentCashout * 100) && !firstGame) | |
| 178 | {
| |
| 179 | console.log(simMsg + '[Bot] Game crashed at ' + (data.game_crash/100) + 'x (-' + currentBitBet + ')'); | |
| 180 | ||
| 181 | // Update global counters for loss | |
| 182 | lastResult = 'LOST'; | |
| 183 | numLosses++; | |
| 184 | currentLossStreak++; | |
| 185 | currentWinStreak = 0; | |
| 186 | totalSatoshiProfit -= roundedSatoshiBet; | |
| 187 | ||
| 188 | maxLossStreak = (currentLossStreak > maxLossStreak) ? currentLossStreak : maxLossStreak; | |
| 189 | } | |
| 190 | else if (data.game_crash >= (currentCashout * 100) && simulation && !firstGame) | |
| 191 | {
| |
| 192 | var lastProfit = (roundedSatoshiBet * currentCashout) - roundedSatoshiBet; | |
| 193 | console.log(simMsg + '[Bot] Successfully cashed out at ' + currentCashout + 'x (+' + (lastProfit/100).toFixed(2) + ')'); | |
| 194 | ||
| 195 | // Update global counters for win | |
| 196 | lastResult = 'WON'; | |
| 197 | numWins++; | |
| 198 | currentWinStreak++; | |
| 199 | currentLossStreak = 0; | |
| 200 | totalSatoshiProfit += lastProfit; | |
| 201 | maxWinStreak = (currentWinStreak > maxWinStreak) ? currentWinStreak : maxWinStreak; | |
| 202 | } | |
| 203 | }); |