Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Created January 30, 2019 14:07
Show Gist options
  • Save dsetzer/822758181782ef0954f55ec865dfb2b1 to your computer and use it in GitHub Desktop.
Save dsetzer/822758181782ef0954f55ec865dfb2b1 to your computer and use it in GitHub Desktop.
var baseBet = 0.8 * 100 // how many satoshis to bet initially
var target = 5.4 // target multiplier
var betMultiplier = 1.2 // what to multiply the bet size by when we lose a wager
const MAX_BET = 10000 * 100 // maximum bet amount to stop script at (satoshis)
const MAX_GAMES = 2000 // maximum number of games to play before stopping (set to -1 for unlimited)
const BET_SPEED = 16 // time between bets in (ex 500 = 500ms = 0.5s)
const CLIENT_SEED = "fortuna"
let running = true
try {
const { server_seed_hash } = await this.newSeedPair()
}catch(e){
if(e == "Error: EXISTING_SEED_TRIPLE_UNUSED"){
await this.skip()
await this.newSeedPair()
}else{
this.log(`[ERROR] Failure setting seed (${e})`)
running = false
}
}
await this.setClientSeed(CLIENT_SEED)
await this.log(`[INFO] Set client seed to: ${CLIENT_SEED}`)
let lossCount = 0
let gameNum = 0
await this.log(`Starting martingale with a base bet of ${baseBet/100} bits.`)
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++
if(lossCount > 8){
target -= Math.min(1, ((lossCount - 13) * 0.08))
}
this.log(`Lost bet. Multiplying bet size by ${betMultiplier} for new bet size of ${bet/100} bits.`)
} else { // win
lossCount = 0
target = 5.4
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.max(100, 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