Reworking some script

Got a piece of code. This code as a part of the plugin for browser, waiting for the right course to make a bet on a website. In case bet is successful - make a bet with the same sum. In case bet is lost - double it until it wins.

So my question is how to add the same procedure (which is waits for the right moment before make a bet) to the second stage of code, where the bet is getting doubled by losing the first one and putting in game instantly without waiting for the right moment.

var ns2, ds, bet = {time: false, sum: 0, up:false, course:0,
		go: function(tm){
			var trend = 'down';
			this.sum = Math.min(this.sum, MAX_bet);
			if (this.up)
				trend ='up';
var req = '[{"data":[{"amount":'+this.sum+',"duration":'+TIME*60+',"dir":"'+trend+'","type":"'+tipo+'"...}]';
		} };

		if (!ds)
		ds = new WebSocket("wss://");
if (!ns2){
		ns2 = new WebSocket("wss://");
		ns2.onopen = function() {
		ns2.onmessage = function(event) {
			var mes = JSON.parse(
			// getting current course
			if (mes.time){
				if (!bet.time){
					bet.time = mes.time+ TIME*60;
					bet.course = mes.close;
				}else if(mes.time >= bet.time){
					// make a bet
					bet.time = mes.time + TIME*60;
					if (bet.course != mes.close){
						var dir_up = ((mes.close - bet.course) > 0);
						if (dir_up==bet.up)
							bet.sum = MIN_bet;
					    bet.sum = Math.max(MIN_bet, (bet.sum*2));
						bet.course = mes.close;
						bet.up = dir_up;
		};	// * ns2.onmessage

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.