-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharb1.py
88 lines (74 loc) · 2.79 KB
/
arb1.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
84
85
86
87
88
import urllib.request, json
from pushbullet.pushbullet import PushBullet
import datetime
from api import API_KEY
#check every other hour
now = datetime.datetime.now()
if now.hour % 2 == 0:
with urllib.request.urlopen("https://www.bitmarket.pl/json/BTCEUR/orderbook.json") as url:
bitmarketdata = json.loads(url.read().decode())
#print(bitmarketdata['bids'])
with urllib.request.urlopen("https://api.gdax.com/products/btc-eur/book/?level=2") as url:
gdaxdata = json.loads(url.read().decode())
#print(gdaxdata['bids'])
value=12000
k=0
pricelist=[]
weightlist=[]
while True:
if value-bitmarketdata['asks'][k][0]*bitmarketdata['asks'][k][1]>0:
value=value-bitmarketdata['asks'][k][0]*bitmarketdata['asks'][k][1]
#print("remaining value", value)
pricelist.append(bitmarketdata['asks'][k][0]*bitmarketdata['asks'][k][1])
weightlist.append(bitmarketdata['asks'][k][1]*0.997) #0.997 zaklada 0,3% prowizje
#print(pricelist)
#print(weightlist)
k=k+1
continue
else:
remaining=value/bitmarketdata['asks'][k][0]
pricelist.append(remaining*bitmarketdata['asks'][k][0])
weightlist.append(remaining*0.997)
#print("remaining value", value-remaining*bitmarketdata['asks'][k][0])
#print(pricelist)
#print(weightlist)
break
bitmavg=sum(pricelist)/sum(weightlist)
print(sum(weightlist), 'of bitcoin will be bought for avg price of', bitmavg)
btcamount=sum(weightlist)-0.0009
value=btcamount
k=0
pricelist=[]
weightlist=[]
while True:
if value-float(gdaxdata['bids'][k][1])>0:
value=value-float(gdaxdata['bids'][k][1])
#print("remaining value", value)
pricelist.append(float(gdaxdata['bids'][k][0])*float(gdaxdata['bids'][k][1]))
weightlist.append(float(gdaxdata['bids'][k][1]))
#print(pricelist)
#print(weightlist)
k=k+1
continue
else:
remaining=value
pricelist.append(remaining*float(gdaxdata['bids'][k][0]))
weightlist.append(remaining)
#print("remaining value", value-remaining)
#print(pricelist)
#print(weightlist)
break
gdaxavg=sum(pricelist)/sum(weightlist)
print(sum(weightlist), 'of bitcoin will be sold for avg price of', gdaxavg)
arbitrage=gdaxavg-bitmavg
#print(arbitrage)
string1=str(arbitrage)
#get api key from env
apiKey = API_KEY
p = PushBullet(apiKey)
# Get a list of devices
devices = p.getDevices()
devices
p.pushNote(devices[0]["iden"], 'Buy at bitmarket/sell at gdax: ' + string1, "")
else:
pass