-
Notifications
You must be signed in to change notification settings - Fork 7
/
blockhedging.py
84 lines (68 loc) · 1.95 KB
/
blockhedging.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
import ccxt
from pprint import pprint
import time
from numpy import NaN
Exchanges = []
Names = []
counterPart = 'ETH'
baseCurrency = 'BTC'
pair = counterPart+'/'+baseCurrency
limit = 3
highLimit = 0.2
lowLimit = 0.001
#print (ccxt.exchanges)
lengthLimit = 10
length = 0
for i in ccxt.exchanges:
exchange = getattr(ccxt,i)()
try:
#print (exchange.fetch_order_book(pair,limit))
exchange.fetch_order_book(pair,limit)
Names.append(str(i))
Exchanges.append(exchange)
length = length + 1
if length > lengthLimit:
break
#break
except:
pass
gatewaysLength = len(Exchanges)
MES = [{} for i in Exchanges]
bids = [NaN for i in Exchanges]
bidsVolum = [NaN for i in Exchanges]
asks = [NaN for i in Exchanges]
asksVolum = [NaN for i in Exchanges]
for i in range(gatewaysLength):
try:
mes = Exchanges[i].fetch_order_book(pair,limit)
MES[i] = mes
#print (mes)
bidPrice = mes['bids'][0][0]
askPrice = mes['asks'][0][0]
if bidPrice < highLimit and bidPrice > lowLimit:
bids[i] = bidPrice
bidsVolum[i] = mes['bids'][0][1]
else:
bids[i] = NaN
bidsVolum[i] = NaN
if askPrice < highLimit and askPrice > lowLimit:
asks[i] = askPrice
asksVolum[i] = mes['asks'][0][1]
else:
asks[i] = NaN
asksVolum[i] = NaN
except:
MES[i] = {}
bids[i] = NaN
asks[i] = NaN
print (Names[i] + ' has error')
#print (bids)
#print (asks)
highestBid = max(bids)
lowestAsk = min(asks)
sellIndex = bids.index(highestBid)
buyIndex = asks.index(lowestAsk)
profit = highestBid/lowestAsk-1.
tradeVolum = min([ bidsVolum[sellIndex] , asksVolum[buyIndex] ])
print ('there are '+ str(gatewaysLength) + ' exchanges ')
print ('buy '+ str(tradeVolum)+ 'ETH at ' + Names[buyIndex] + ' and sell at '+ Names[sellIndex] + ' profit: ' + str(profit) )