-
Notifications
You must be signed in to change notification settings - Fork 2
/
btc_oracle_2.py
83 lines (62 loc) · 2.57 KB
/
btc_oracle_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import re
import socket
import requests
###
#Script takes an average of last x volumes on localbitcoins and a percentage of that (starting from today and going to the past) to get a growth factor, adjust percentage to make more precise
###
backwards = 365 #past and future days to base the prediction on
percent = 10 #history percentage to take into consideration as growth factor
# timeout in seconds
timeout = 6
socket.setdefaulttimeout(timeout)
# timeout in seconds
# set header
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
# set header
i = 0
while i < backwards:
request = requests.get("https://coin.dance/charts/ALL", headers=hdr)
geturl_readable = request.text
geturl_readable_matches = re.findall('value"\:"(\d+)"', geturl_readable)
term = geturl_readable_matches [-i:] #number sets age
print (term)
avg = 0
for x in term:
avg=avg+int(x)
avg=avg/len(term)
predict = (int(i)*int(percent))/100
print ("predict:"+str(predict))
last = (geturl_readable_matches[-int(predict):])
#x percent average
avg2 = 0
for y in last:
avg2=avg2+int(x)
avg2=avg2/len(last)
index = 100 * (int(avg2) - int(avg)) / int(avg)
#wrong calc
#x percent average
print (len(term))
print (len(last))
#price
request2 = requests.get("http://api.coindesk.com/v1/bpi/currentprice/btc.json", headers=hdr)
geturl_readable2 = request2.text
price = re.findall('rate":"([\d\.\,]+)', geturl_readable2)
real_price = price[0].replace(",","")
print ("Current price:" +str(real_price))
print (index)
#price
if index > 0:
print ("BTC will rise "+str(index)+"% in the following "+str(i)+" days ("+str(i/365)+" year(s)) to $" +str((float(real_price)+(float(real_price)*float(index))/100)) + " from current $" +real_price)
if index == 0:
print ("There will be no change")
if index < 0:
print ("Bitcoin price will fall "+str(index)+"% in the following "+str(i)+" days ("+str(i/365)+" year(s)) to $" +str((float(real_price)+(float(real_price)*float(index))/100)) + " from current $" +real_price)
logger = open("data.txt", 'a')
logger.write(str((float(real_price)+(float(real_price)*float(index))/100)) +"\n")
logger.close()
i = i+1