Advertisement
Guest User

Untitled

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