diff --git a/DQ-Trevel.js b/DQ-Trevel.js
index ce75d9b..8dcbc2e 100644
--- a/DQ-Trevel.js
+++ b/DQ-Trevel.js
@@ -41,7 +41,7 @@ var R = {}; // the Recurrent library
// helper function returns array of zeros of length n
// and uses typed arrays if available
var zeros = function(n) {
- if (typeof(n) === 'undefined' || isNaN(n)) {
+ if (typeof (n) === 'undefined' || isNaN(n)) {
return [];
}
if (typeof ArrayBuffer === 'undefined') {
@@ -1514,17 +1514,20 @@ var RL = {};
})(RL);
var Trevel = {
//settings you can change
- stop: false,
+ stop: true,
maxBet: 0.00001,
- minBet: 0.00000002,
+ minBet: 0.00000001,
swap: true,
betSpeed: 100,//change this on init
verbose: true,
isTesting: false,
+ newseed: '', // 'win' for change ever win, 'lose' for change every loss, blank for every roll
//money management
useKelly: false,//martingale performs better on live account!
+ korm: false,
kellyPercent: 5, //can't be more than 100 or less than 1
useMartingale: true, //if kelly is true this won't work
+
martingaleMultiplier: 2,
//bot settings, these are set automaticcally don't bother
currentBalance: 0,
@@ -1540,39 +1543,47 @@ var Trevel = {
lbProbability: 0,
hbCount: 0,
lbcount: 0,
+ hbw: 0,
+ hbl: 0,
+ lbw: 0,
+ lbl: 0,
nextBet: "",
- previousReward:0,
+ previousReward: 0,
addBet: function(bet, outcome) {
if (bet === "LB" && outcome === "Win") {
- Trevel.betHistory.push("LO");
- Trevel.betOutcomes.push("W");
- Trevel.totalWins++;
- Trevel.lbcount++;
+ this.betHistory.push("LO");
+ this.betOutcomes.push("W");
+ this.totalWins++;
+ this.lbcount++;
+ this.lbw++;
}
if (bet === "LB" && outcome === "Loose") {
- Trevel.betHistory.push("HI");
- Trevel.hbCount++;
- Trevel.betOutcomes.push("L");
+ this.betHistory.push("HI");
+ this.hbCount++;
+ this.betOutcomes.push("L");
+ this.lbl++;
}
if (bet === "HB" && outcome === "Win") {
- Trevel.betHistory.push("HI");
- Trevel.totalWins++;
- Trevel.hbCount++;
- Trevel.betOutcomes.push("W");
+ this.betHistory.push("HI");
+ this.totalWins++;
+ this.hbCount++;
+ this.betOutcomes.push("W");
+ this.hbw++;
}
if (bet === "HB" && outcome === "Loose") {
- Trevel.betHistory.push("LO");
- Trevel.lbcount++;
- Trevel.betOutcomes.push("L");
+ this.betHistory.push("LO");
+ this.lbcount++;
+ this.betOutcomes.push("L");
+ this.hbl++;
}
- Trevel.totalBets++;
+ this.totalBets++;
},
calculateProbabilities: function() {
- Trevel.hbProbability = Trevel.hbCount / Trevel.betHistory.length;
- Trevel.lbProbability = Trevel.lbcount / Trevel.betHistory.length;
- Trevel.winRate = Trevel.totalWins / Trevel.totalBets;
- if(Trevel.isTesting===false){
- Trevel.profit = Trevel.getProfit();
+ this.hbProbability = this.hbCount / this.betHistory.length;
+ this.lbProbability = this.lbcount / this.betHistory.length;
+ this.winRate = this.totalWins / this.totalBets;
+ if (this.isTesting === false) {
+ this.profit = this.getProfit();
}
},
getCurrentBalance: function() {
@@ -1590,58 +1601,64 @@ var Trevel = {
},
setOutcome: function(bet) {
if ($('#double_your_btc_bet_lose').html() !== '') {
- Trevel.addBet(bet, "Loose");
+ this.addBet(bet, "Loose");
+ if (this.newseed == 'lose') {
+ this.rSeed();
+ }
} else {
- Trevel.addBet(bet, "Win");
+ if (this.newseed == 'win') {
+ this.rSeed();
+ }
+ this.addBet(bet, "Win");
}
},
prepareBet: function() {
- Trevel.calculateProbabilities();
- if (Trevel.betHistory.length < 10) {
- if (Trevel.useMartingale === true && Trevel.betHistory.length>12) {
- if ($('#double_your_btc_bet_lose').html() !== '' && parseFloat($('#double_your_btc_stake').val()) * Trevel.martingaleMultiplier < Trevel.maxBet) {
- Trevel.setBetAmount((parseFloat($('#double_your_btc_stake').val()) * Trevel.martingaleMultiplier).toFixed(8));
+ this.calculateProbabilities();
+ if (this.betHistory.length < 10) {
+ if (this.useMartingale === true && this.betHistory.length > 12) {
+ if ($('#double_your_btc_bet_lose').html() !== '' && parseFloat($('#double_your_btc_stake').val()) * this.martingaleMultiplier < this.maxBet) {
+ this.setBetAmount((parseFloat($('#double_your_btc_stake').val()) * this.martingaleMultiplier).toFixed(8));
} else {
- Trevel.setBetAmount(Trevel.minBet);
+ this.setBetAmount(this.minBet);
}
}
} else {
- if (Trevel.useKelly === true && Trevel.betHistory.length>12) {
- Trevel.currentBalance = Trevel.getCurrentBalance();
+ if (this.useKelly === true && this.betHistory.length > 12) {
+ this.currentBalance = this.getCurrentBalance();
var currMulty = document.getElementById("double_your_btc_payout_multiplier").value;
- var kellyAmount = (((Trevel.currentBalance * Trevel.kellyPercent) / 100) * ((Trevel.winRate * currMulty - 1)) / (currMulty - 1)).toFixed(8);
- if (kellyAmount > 0 && kellyAmount < Trevel.maxBet) {
- Trevel.setBetAmount(kellyAmount);
+ var kellyAmount = (((this.currentBalance * this.kellyPercent) / 100) * ((this.winRate * currMulty - 1)) / (currMulty - 1)).toFixed(8);
+ if (kellyAmount > 0 && kellyAmount < this.maxBet) {
+ this.setBetAmount(kellyAmount);
} else {
- Trevel.setBetAmount(Trevel.minBet);
+ this.setBetAmount(this.minBet);
}
- } else if (Trevel.useMartingale === true && Trevel.betHistory.length>12) {
- if ($('#double_your_btc_bet_lose').html() !== '' && parseFloat($('#double_your_btc_stake').val()) * Trevel.martingaleMultiplier < Trevel.maxBet) {
- Trevel.setBetAmount((parseFloat($('#double_your_btc_stake').val()) * Trevel.martingaleMultiplier).toFixed(8));
+ } else if (this.useMartingale === true && this.betHistory.length > 12) {
+ if ($('#double_your_btc_bet_lose').html() !== '' && parseFloat($('#double_your_btc_stake').val()) * this.martingaleMultiplier < this.maxBet) {
+ this.setBetAmount((parseFloat($('#double_your_btc_stake').val()) * this.martingaleMultiplier).toFixed(8));
} else {
- Trevel.setBetAmount(Trevel.minBet);
+ this.setBetAmount(this.minBet);
}
}
}
},
placeBet: function() {
- if (Trevel.nextBet === "HB") {
- Trevel.placeHighBet();
- } else if (Trevel.nextBet === "LB") {
- Trevel.placeLowBet();
- } else if (Trevel.betHistory.length > 0 && Trevel.swap === true) {
- var prev = Trevel.betHistory[Trevel.betHistory.length - 1];
+ if (this.nextBet === "HB") {
+ this.placeHighBet();
+ } else if (this.nextBet === "LB") {
+ this.placeLowBet();
+ } else if (this.betHistory.length > 0 && this.swap === true) {
+ var prev = this.betHistory[this.betHistory.length - 1];
if (prev === "LO") {
- Trevel.placeHighBet();
+ this.placeHighBet();
} else {
- Trevel.placeLowBet();
+ this.placeLowBet();
}
} else {
- Trevel.placeLowBet();
+ this.placeLowBet();
}
},
getProfit: function() {
- return (Trevel.getCurrentBalance() - Trevel.startingBalance).toFixed(8);
+ return (this.getCurrentBalance() - this.startingBalance).toFixed(8);
},
getNumStates: function() {
return 8;
@@ -1658,55 +1675,55 @@ var Trevel = {
},
getPreviousBets: function() {
var hist = [];
- if (Trevel.betHistory.length > 12) {
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 1]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 2]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 3]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 4]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 5]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 6]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 7]));
- hist.push(Trevel.getSentiment(Trevel.betHistory[Trevel.betHistory.length - 8]));
+ if (this.betHistory.length > 12) {
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 1]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 2]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 3]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 4]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 5]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 6]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 7]));
+ hist.push(this.getSentiment(this.betHistory[this.betHistory.length - 8]));
} else {
hist = [0, 1, 0, 1, 0, 1, 0, 1]; //incase we just started...
}
return hist;
},
getAgentState: function() { //we'll observe the last 8 bets
- var s = Trevel.getPreviousBets();
+ var s = this.getPreviousBets();
return s;
},
getReward: function() {
var reward = 0;
- var out1=Trevel.betOutcomes[Trevel.betOutcomes.length - 1];
- var out2=Trevel.betOutcomes[Trevel.betOutcomes.length - 2];
- if(out1==="L"){
- if(Trevel.previousReward<0){
- reward=Trevel.previousReward;
- reward+=-0.03;
- if(out2==="L"){
- reward+=-0.03;
+ var out1 = this.betOutcomes[this.betOutcomes.length - 1];
+ var out2 = this.betOutcomes[this.betOutcomes.length - 2];
+ if (out1 === "L") {
+ if (this.previousReward < 0) {
+ reward = this.previousReward;
+ reward += -0.03;
+ if (out2 === "L") {
+ reward += -0.03;
}
}
- else{
- reward=-0.03;
- if(out2==="L"){
- reward+=-0.03;
+ else {
+ reward = -0.03;
+ if (out2 === "L") {
+ reward += -0.03;
}
}
}
- else{
- if(Trevel.previousReward>0){
- reward=Trevel.previousReward;
- reward+=0.01;
- if(out2==="W"){
- reward+=0.01;
+ else {
+ if (this.previousReward > 0) {
+ reward = this.previousReward;
+ reward += 0.01;
+ if (out2 === "W") {
+ reward += 0.01;
}
}
- else{
- reward=0.01;
- if(out2==="W"){
- reward+=0.01;
+ else {
+ reward = 0.01;
+ if (out2 === "W") {
+ reward += 0.01;
}
}
}
@@ -1717,23 +1734,81 @@ var Trevel = {
return Math.floor(Math.random() * (max - min + 1) + min);
},
getTestOutcome: function(random) {
- if (random % 2 == 0) {
+ if (random % 2 === 0) {
return "HI";
} else {
return "LO";
}
},
- //initialize Trevel
+ //random string for random seed
+ rString: function(length, chars) {
+ var result = '';
+ var length = 16;
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'
+ for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
+ return result;
+ },
+ //set client seed as random string
+ rSeed: function() {
+ $('#next_client_seed').val(this.rString());
+ },
+ //initialize this
init: function() {
- Trevel.startingBalance = Trevel.currentBalance = parseFloat($('#balance').html());
- Trevel.setBetAmount(Trevel.minBet);
- Trevel.stop = false;
- Trevel.swap = true;
- Trevel.betSpeed=3000;
+ this.startingBalance = this.currentBalance = parseFloat($('#balance').html());
+ this.setBetAmount(this.minBet);
+ this.stop = true;
+ this.swap = true;
+ this.betSpeed = 3000;
+ document.getElementById("free_play_link_li").innerHTML = 'START BOT';
+
+ },
+ // ask user config variables
+ config: function() {
+
+ //define temporary variables
+ var maxb = 0, minb = 0;
+
+ //prompt questions
+ maxb = prompt('Maximum bet stake in Satoshi', 1000);
+ this.maxBet = sattobtc(maxb);
+ minb = prompt('Minimum bet stake in Satoshi', 2);
+ this.minBet = sattobtc(minb);
+ this.martingaleMultiplier = prompt('Bet multiplier on lose', 2);
+ this.swap = prompt('True for swap enabled, false for disabled', 'true');
+ this.korm = prompt('True to enable Kelly, false to enabled martingale, leave blank for both', 'false');
+ this.newseed = prompt('Randomize client seed every "win", "lose", or leave blank for every roll', '');
+ this.betSpeed = prompt('Wait time before next bet is placed in ms', 3000);
+
+ //convert satoshi to btc
+ function sattobtc(sat) {
+ var btc = 0.00000001;
+ return sat * btc;
+ }
+ if (this.korm === 'true') {
+ this.useKelly = true;
+ this.useMartingale = false;
+ }
+ else if (this.korm === 'false') {
+ this.useMartingale = true;
+ this.useKelly = false;
+ }
+ else {
+ this.useKelly = this.useMartingale = true;
+ }
+ //start betting
+ startbetting();
+ },
+ stopbets: function() {
+ env.stop = true;
+ clearInterval(interval);
+ console.log('Bet session has been stopped, to start over click start.');
+ document.getElementById("free_play_link_li").innerHTML = 'START BOT';
+
+
}
};
//Deep Q learning with reinforceJS
-var spec = {}
+var spec = {};
spec.update = 'qlearn';
spec.gamma = 0.9;
spec.epsilon = 0.45;
@@ -1741,16 +1816,36 @@ spec.alpha = 0.01;
spec.experience_add_every = 12;
spec.experience_size = 100000;
spec.learning_steps_per_iteration = 24;
-spec.tderror_clamp = 0.7;
+spec.tderror_clamp = 0.7;
spec.num_hidden_units = 24;
// create an environment object
var env = Trevel;
+var interval = null;
if (env.isTesting === false) {
env.init();
}
// create the DQN agent
agent = new RL.DQNAgent(env, spec);
-setInterval(function() {
+
+// start betting function/agent interval
+function startbetting() {
+ console.log('Starting bet session, to stop click STOP BOT');
+ document.getElementById("free_play_link_li").innerHTML = 'STOP BOT';
+ env.stop = false;
+ interval = setInterval(function() { loop(); }, env.betSpeed);
+}
+console.clear();
+console.log('You are using Trevel, with ReinforceJS');
+console.log('If you shall notice, the Free BTC link has been replaced with a START/STOP BOT button.');
+console.log('Click it to set the config. Note: These settings are not persistent.');
+console.log('To change the default values for these settings, search the script for "prompt"');
+console.log('Enjoy');
+function loop() {
+ if (Trevel.newseed == '') {
+ env.rSeed();
+ }
+
+
if (env.stop === false) {
var state = env.getAgentState();
var action = agent.act(state);
@@ -1771,8 +1866,23 @@ setInterval(function() {
}
if (env.verbose === true) {
env.calculateProbabilities();
+ clear();
+
//console.log("Machine Bet: " + action + "{" + env.nextBet + "} isKelly: " + env.useKelly + " isMartingale: " + env.useMartingale);
- console.log("Profit: " + env.profit+" WinRate: " + (env.winRate*100).toFixed(2));
+
+ console.log("| Client Seed: " + $('#next_client_seed').val() + " | Lotto Tickets: " + $('#user_lottery_tickets').html() + " | Rewards Points: " + $('.user_reward_points').text());
+ console.log(" 8=========================== "+ env.totalBets + " ===========================D ~ ")
+ console.log("| Win Rate: " + (env.winRate * 100).toFixed(2) + " | Hi Win Rate: " + ((env.hbw / env.totalBets) * 100).toFixed(2) + " | Lo Win Rate: " + ((env.lbw / env.totalBets) * 100).toFixed(2) + " |");
+ console.log("|____________________________________________________________|");
+ console.log("| Total Wins: " + env.totalWins + " | Total Hi: " + env.hbCount + " | Hi Wins: " + env.hbw + " | Hi Loss " + env.hbl+ " |");
+ console.log("| Total Loss: " + (env.totalBets - env.totalWins) + " | Total Lo " + env.lbcount + " | Lo Wins: " + env.lbw + " | Lo Loss " + env.lbl+" |");
+ console.log("|____________________________________________________________|");
+ console.log("| Hi Probability: " + env.hbProbability.toFixed(2) + " | Lo Probability: " + env.lbProbability.toFixed(2) + " |");
+ console.log("|____________________________________________________________|");
+ console.log("| Last Bet: " + env.betHistory[env.betHistory.length - 1]+ " | Outcome: " + outcome+ " | Stake: "+ env.betAmount+ " |");
+ console.log("| Profit: " + env.profit + " | Balance: " + env.getCurrentBalance().toFixed(8)+ " |");
+ console.log("|____________________________________________________________|")
+
}
} else {
console.log("Action: " + action);
@@ -1791,10 +1901,10 @@ setInterval(function() {
outcome = "L";
}
env.calculateProbabilities();
- console.log("Winrate: " + (env.winRate*100).toFixed(2));
+ console.log("Winrate: " + (env.winRate * 100).toFixed(2));
}
var reward = env.getReward();
- if (reward == 0) {
+ if (reward === 0) {
if (outcome === "L") {
reward = -0.03;
} else {
@@ -1802,6 +1912,7 @@ setInterval(function() {
}
}
agent.learn(reward);
- env.previousReward=reward;
+ env.previousReward = reward;
}
-}, env.betSpeed);
\ No newline at end of file
+
+}