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