View difference between Paste ID: 5Stp9KPr and NV4Nwm69
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
#  run.py
5
#  
6
#  Copyright 2013 [mad]Berry <[email protected]>
7
#  
8
#  This program is free software; you can redistribute it and/or modify
9
#  it under the terms of the GNU General Public License as published by
10
#  the Free Software Foundation; either version 2 of the License, or
11
#  (at your option) any later version.
12
#  
13
#  This program is distributed in the hope that it will be useful,
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
#  GNU General Public License for more details.
17
#  
18
#  You should have received a copy of the GNU General Public License
19
#  along with this program; if not, write to the Free Software
20
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
#  MA 02110-1301, USA.
22
#  
23
###
24
25
### Please send donations to [mad]Berry:
26
#btc: 1Q2QDC78uaGgkm4r3G5YzZSriPv7KMUuQU
27
#ltc: Lb5TUyhdUtqsExLmiyqCLAiBZUrs8mEYze
28
### Thanks.
29
30
### Nikki's addresses, if you're feeling extra generous:
31
#btc: 1J18oi6EdWALyFyk9mbNMmiZnbtyHSERPu
32
#ltc: LSt4C729DmykfRKAUi7ijjyryt75awBkC2
33
#
34
#
35
#  About this fork:
36
#  [mad]Berry wrote a cool script, but it was completely different from my understanding
37
#  of what Martingale is.  There was too much randomness for me.  So I rewrote most of it
38
#  such that it behaves more like the popular definition of Martingale.  It will follow the
39-
#  common last_bet^2 formula in an attempt to win back any losses (when the payout is 2.0x,
39+
#  common last_bet * 2 formula in an attempt to win back any losses (when the payout is 2.0x,
40
#  the formula is actually (((multiplier - 1) * initial_bet) + round_bet) / (multiplier - 1)))
41
#  where round_bet is the amount you've bet since you began losing).
42
#
43
#  I hope someone's able to make some use of it.  Please be aware though, after many simulations
44
#  of the different payouts and percents to win offered by coinroll.it, a Martingale strategy is 
45
#  nearly always beaten by a maximum bet set only a few percent lower than the highest bet the strategy
46
#  would commonly need to make.  This is likely very deliberate on coinroll.it's part.  I wouldn't
47
#  try to make money with this.
48
#
49
#  Also, there's a small C# simulation program I wrote up here: http://pastebin.com/yjv4V08f
50
#  I'd recommend changing it to use something other than doubles, as there are rounding errors.
51
#
52
### Good luck.
53
54
55
# Variables used to run the script
56
57
user=''											# userid from the site
58
password = '' 									# password from the site
59
initial_bet = 1000								# Your starting bet
60
less_than = 60000								# The number you're betting on
61
max_iter = 8 									# Setting this too low will cause the bot to write off a lot of losses
62
												# For example, if we're using 50% odds with a 2x payout and a 1000 Satoshi
63
												# bet, 8 iterations would equal a 128000 Satoshi bet, after which if the bot
64
												# doesn't win, it'll go back to a 1000 Satoshi bet and start the process over.
65
												# Set this > 15 to effectively ignore it with most current bets
66
max_loss = 0.75 								# balance <= initial_balance * max_loss, 0.75 means 25% loss
67
address = '' 									# Receive address
68
69
70
#-------Any changes below this line might break the script------
71
72
import urllib2,urllib,os,random,math,atexit,time
73
from sys import stdout
74
from datetime import datetime
75
76
__prog__ = "coinroll.it automated gambling script"
77
__scriptname__ = "run.py"
78
__author__ = "[mad]Berry"
79
__date__ = "$May 07, 2013 17:10:45 PM$"
80
__version__ = "1.0.04 - Nikki's fork 0.1.03"
81
82
start_time = datetime.now()
83
stdscr = 0
84
hasCurses = False
85
86
class Error(Exception):
87
    pass
88
89
def module_exists(module_name):
90
	try:
91
		__import__(module_name)
92
	except ImportError:
93
		return False
94
	else:
95
		return True
96
def cls():
97
	os.system(['clear','cls'][os.name == 'nt'])
98
	
99
def initCurses():
100
	global stdscr	
101
	stdscr = curses.initscr()
102
	curses.noecho()
103
	curses.cbreak()
104
	stdscr.keypad(1)
105
106
@atexit.register
107
def exitF():
108
	if(hasCurses):
109
		endCurses()
110
111
def endCurses():
112
	curses.nocbreak()
113
	curses.echo()
114
	stdscr.keypad(0)
115
	curses.endwin()
116
117
def perHour():
118
	dt = datetime.now() - start_time
119
	ms = (dt.days * 24 * 60 * 60 + dt.seconds) * 1000 + dt.microseconds / 1000.0
120
	return 3600000.0 / ms
121
122
def cout(out, y, x):
123
	if(hasCurses):		
124
		stdscr.addstr(y, x, out)
125
		stdscr.refresh()
126
	else:
127
		#sorry Windows...python really isn't my thing..
128
		cls()
129
		print out	
130
131
def call(api_url, **kwargs):
132
	try:
133
		baseurl = 'https://coinroll.it/'
134
		api_url = baseurl + api_url
135
		data = urllib.urlencode(kwargs) #({'user': user, 'password': password})
136
		header = {
137
					"Content-type": "application/x-www-form-urlencoded",
138
					"User-Agent" : "Coinroll Martingale by "+__author__+" Version "+ __version__
139
				}
140
		req = urllib2.Request(api_url, data, header)
141
		response = urllib2.urlopen(req)
142
		result = response.read()
143
		result = simplejson.loads(result)
144
		if 'error' in result:
145
		# An error occurred; raise an exception
146
			raise Error({'message': result['error']})
147
			time.sleep(2.5)
148
			exit(1)
149
		return result
150
	except Exception, e:
151
		out = data
152
		out += '\n' + e.args[0]['message']
153
		cout(out, 0, 0)
154
		time.sleep(2.5)
155
		exit(1)
156
157
def main():
158
	cout("Starting", 0, 0)
159
	resultgameinfo = call('getgameinfo', lessthan=less_than)
160
	multiplier = resultgameinfo['multiplier']
161
	resultbalance = call('getbalance', user=user, password=password)
162
	initial_balance = resultbalance['balance']
163
	profit = 0
164
	bet = initial_bet
165
	round_bet = 0
166
	withdrawn = 0
167
	iters = 0
168
	while True:
169
		result = call('bet',user=user, password=password, lessthan=less_than,amount=bet)
170
		balance = result['balance']
171
		profit += result['diff']
172
		if (result['win'] == True):
173
			bet = initial_bet
174
			round_bet = 0
175
			iters = 0
176
		else:
177
			round_bet += bet
178
			bet = int(math.ceil((((multiplier - 1) * initial_bet) + round_bet) / (multiplier - 1)))
179
			iters += 1
180
			if(iters >= max_iter):
181
				bet = initial_bet
182
				round_bet =  0
183
				iters = 0
184
		if(balance > initial_balance * 2):
185
			withdraw = balance - initial_balance
186
			resultwithdraw = call('withdraw', user=user, password=password, address=address, amount=withdraw)
187
			balance = resultwithdraw['balance']
188
			withdrawn += withdraw
189
		if((balance <= 0 or bet > balance) or balance <= initial_balance * max_loss):
190
			exit('Balance too low.')
191
		output = "Multiplier:\t\t\t{5:.3f}\nInitial Balance:\t\t{6:.8f}\nIn Play Balance:\t\t{0:.8f}\nCurrent Bet:\t\t\t{1:.8f}\nWithdraw:\t\t\t{2:.8f}\nTotal:\t\t\t\t{3:.8f}\nBTC/Hour:\t\t\t{4:.8f}\nIterations:\t\t\t{7}\n".format(float(balance) / 100000000, float(bet) / 100000000, float(withdrawn) / 100000000, float(balance + withdrawn) / 100000000, float(profit * perHour()) / 100000000, multiplier, float(initial_balance) / 100000000, iters)
192
		cout(output, 0, 0)
193
	return 0
194
195
if __name__ == '__main__':
196
	if(module_exists('curses')):
197
		import curses
198
		hasCurses = True
199
	else:
200
		hasCurses = False
201
	if(module_exists('simplejson')):
202
		import simplejson
203
	else:
204
		exit("Please download and install simplejson from: https://pypi.python.org/pypi/simplejson")
205
	if(hasCurses):
206
		initCurses()
207
	try:
208
		main()
209
	except KeyboardInterrupt:
210
		exit("Bye Bye")