-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
177 lines (155 loc) · 6.53 KB
/
tests.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import ccxt
import Exchange
import Pair
import botutils
abook = {
'bids':[
[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],
[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],
[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],
[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],],
'asks':[
[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],
[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],
[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],]
}
bbook = {
'bids':[
[3, 1],[3, 1],[3, 1],[3, 1],[3, 1],[3, 1],[3, 1],[3, 1],[3, 1],[3, 1],
[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],[2.5, 1],
[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],
[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],],
'asks':[
[3.5,2],[3.5,2],[3.5,2],[3.5,2],[3.5,2],[3.5,2],[3.5,2],[3.5,2],[3.5,2],[3.5,2],
[4.0,2],[4.0,2],[4.0,2],[4.0,2],[4.0,2],[4.0,2],[4.0,2],[4.0,2],[4.0,2],[4.0,2],
[4.5,2],[4.5,2],[4.5,2],[4.5,2],[4.5,2],[4.5,2],[4.5,2],[4.5,2],[4.5,2],[4.5,2],]
}
cbook = {
'bids':[],
'asks':[]}
dbook = {
'bids':[
[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],[2, 1],
[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],[1.5, 1],
[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],[1, 1],
[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],[0.5, 1],],
'asks':[
[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],[2.5,1],
[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],[3.0,1],
[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],[3.5,1],]
}
ebook = {
'bids':[
[7, 10],[7, 10],[7, 10],[7, 10],[7, 10],[7, 10],[7, 10],[7, 10],[7, 10],[7, 10],
[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],[6.5, 10],
[6, 10],[6, 10],[6, 10],[6, 10],[6, 10],[6, 10],[6, 10],[6, 10],[6, 10],[6, 10],
[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],[5.5, 10],],
'asks':[
[8.5,10],[8.5,10],[8.5,10],[8.5,10],[8.5,10],[8.5,10],[8.5,10],[8.5,10],[8.5,10],[8.5,10],
[9.0,10],[9.0,10],[9.0,10],[9.0,10],[9.0,10],[9.0,10],[9.0,10],[9.0,10],[9.0,10],[9.0,10],
[9.5,10],[9.5,10],[9.5,10],[9.5,10],[9.5,10],[9.5,10],[9.5,10],[9.5,10],[9.5,10],[9.5,10],]
}
fbook = {
'bids':[
[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],[7, 0.1],
[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],[6.5, 0.1],
[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],[6, 0.1],
[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],[5.5, 0.1],],
'asks':[
[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],[8.5,0.1],
[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],[9.0,0.1],
[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],[9.5,0.1],]
}
def test1():
bin = Exchange.Exchange(ccxt.binance())
bin.add_book(bin.Ex.fetch_order_book('BCD/BTC'), 'BCD/BTC')
hit = Exchange.Exchange(ccxt.bitz())
hit.add_book(hit.Ex.fetch_order_book('BCD/BTC'), 'BCD/BTC')
pair = Pair.Pair(hit, bin, 'BCD/BTC')
print(pair.max_trade())
print(pair.min_trade())
print(pair.margin())
def test2():
symbol = 'ETH/BTC'
t1 = Exchange.Exchange(ccxt.binance())
t1.add_book(abook, symbol)
t2 = Exchange.Exchange(ccxt.bitz())
t2.add_book(ebook, 'ETH/BTC')
pair = Pair.Pair(t1, t2, 'ETH/BTC')
print(pair.max_trade())
print(pair.min_trade())
print(pair.Margin)
print(pair.FlatFees)
print(pair.PercentFees)
def test3():
symbol = 'ETH/BTC'
t1 = Exchange.Exchange(ccxt.binance())
t1.add_book(abook, symbol)
t2 = Exchange.Exchange(ccxt.bitz())
t2.add_book(fbook, 'ETH/BTC')
pair = Pair.Pair(t1, t2, 'ETH/BTC')
print(pair.max_trade())
print(pair.min_trade())
print(pair.Margin)
print(pair.FlatFees)
print(pair.PercentFees)
def test4():
symbol = 'BCD/BTC'
t1 = Exchange.Exchange(ccxt.binance())
t1.add_book(abook, symbol)
t2 = Exchange.Exchange(ccxt.bitz())
t2.add_book(cbook, 'BCD/BTC')
pair = Pair.Pair(t1, t2, 'BCD/BTC')
print(pair.max_trade())
print(pair.min_trade())
print(pair.Margin)
print(pair.FlatFees)
print(pair.PercentFees)
def test5():
symbol = 'ETH/BTC'
t1 = Exchange.Exchange(ccxt.binance())
t1.add_book(abook, symbol)
t2 = Exchange.Exchange(ccxt.hitbtc())
t2.add_book(bbook, 'ETH/BTC')
pair = Pair.Pair(t1, t2, 'ETH/BTC')
print('~~~~~',pair.max_trade())
print('~~~~',pair.min_trade())
print('~~~',pair.Margin)
print('~~',pair.margin(pair.max_trade()))
print('~',pair.margin(pair.min_trade()))
print('$',"%.2f" % botutils.convert_to_USD(pair.max_trade(), 'ETH'),' -> $',"%.2f" % botutils.convert_to_USD(pair.max_trade()+pair.roi(pair.max_trade()), 'ETH'))
print('roilim:', (pair.roi(pair.max_trade())-pair.roi(pair.max_trade()*0.999))*1000)
def test6():
symbol = 'ETH/BTC'
t1 = Exchange.Exchange(ccxt.binance())
t1.add_book(abook, symbol)
t2 = Exchange.Exchange(ccxt.hitbtc())
t2.add_book(bbook, 'ETH/BTC')
pair = Pair.Pair(t1, t2, 'ETH/BTC')
for i in range(int(10*pair.min_trade()), int(10*pair.max_trade())):
print(pair.roi(i/10.0))
def test7():
symbol = 'ETH/BTC'
t1 = Exchange.Exchange(ccxt.binance())
t1.add_book(abook, symbol)
t2 = Exchange.Exchange(ccxt.hitbtc())
t2.add_book(abook, 'ETH/BTC')
pair = Pair.Pair(t1, t2, 'ETH/BTC')
print(pair.max_trade())
print(pair.min_trade())
print(pair.Margin)
print(pair.margin(pair.max_trade()))
print(pair.margin(pair.min_trade()))
print('$', "%.2f" % botutils.convert_to_USD(pair.max_trade(), 'ETH'), ' -> $',
"%.2f" % botutils.convert_to_USD(pair.max_trade() + pair.roi(pair.max_trade()), 'ETH'))
def test8():
symbol = 'ETH/USDT'
t1 = Exchange.Exchange(ccxt.exmo())
t1.add_book(t1.Ex.fetch_order_book(symbol), symbol)
t2 = Exchange.Exchange(ccxt.ethfinex())
t2.add_book(t2.Ex.fetch_order_book(symbol), symbol)
pair = Pair.Pair(t1, t2, 'ETH/USDT')
def main():
test8()
if __name__ == "__main__":
main()