Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active November 17, 2021 22:31
Show Gist options
  • Save dsetzer/e7c11d2d5c4690a9b882671903c7fa58 to your computer and use it in GitHub Desktop.
Save dsetzer/e7c11d2d5c4690a9b882671903c7fa58 to your computer and use it in GitHub Desktop.
bustadice script
const baseBet = 2 * 100 // how many satoshis to bet initially
const target = 9.09 // target multiplier
const betMultiplier = 1.7 // what to multiply the bet size by when we lose a wager
const MAX_BET = 7000 * 100 // maximum bet amount to stop script at (satoshis)
const MAX_GAMES = 50 // maximum number of games to play before stopping (set to -1 for unlimited)
const BET_SPEED = 2000 // time between bets in (ex 500 = 500ms = 0.5s)
let lossCount = 0
this.log(`Starting martingale with a base bet of ${baseBet/100} bits.`)
let running = true
let gameNum = 0
while (running) {
let bet = betSize(lossCount)
if (MAX_GAMES !== -1 && gameNum >= MAX_GAMES) {
// stop after playing max num of games
this.log(`Stopped after playing ${MAX_GAMES} games.`)
running = false
} else if (bet >= MAX_BET) {
// stop if bet amount reaches max bet
this.log(`Stopped due to max bet exceeded (${baseBet/100} bits.`)
running = false
} else {
// make the bet and wait for the result
const { multiplier } = await this.bet(bet, target)
if (multiplier < target) { // loss
lossCount++
this.log(`Lost bet. Multiplying bet size by ${betMultiplier} for new bet size of ${bet/100} bits.`)
} else { // win
lossCount = 0
this.log(`Won bet. Setting bet size to ${baseBet/100} bits.`)
}
}
gameNum++
await sleep(BET_SPEED)
}
function betSize(lossCount) {
const bet = baseBet * Math.pow(betMultiplier, lossCount)
return Math.round(bet / 100) * 100
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment