Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active May 31, 2023 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsetzer/1b367205c08e03ff9e801f62be2b84ef to your computer and use it in GitHub Desktop.
Save dsetzer/1b367205c08e03ff9e801f62be2b84ef to your computer and use it in GitHub Desktop.
const baseBet = 1 * 100 // how many satoshis to bet initially
const target = 1.75 // target multiplier
const betMultiplier = 3.06 // what to multiply the bet size by when we lose a wager
const MAX_BET = 2000 * 100 // maximum bet amount to stop script at (satoshis)
const MAX_GAMES = -1 // maximum number of games to play before stopping (set to -1 for unlimited)
const BET_SPEED = 500 // 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